0

I have some folders specified in my PATH environment variable. How do I list all the files in these folders?

  • Try a loop ... result might be lengthy. – RudiC Dec 9 '18 at 21:33
  • 4
    find ${PATH//:/ } – Ipor Sircer Dec 9 '18 at 21:33
  • 5
    What's do you need this for? – Tomasz Dec 9 '18 at 21:35
  • 1
    @IporSircer This should have been posted as the most KISS answer.... – George Vasiliou Dec 9 '18 at 22:05
  • I agree. @IporSircer if you post this as an answer, I can mark your answer as the accepted answer :-) – Eloy Dec 9 '18 at 23:27
3

You can use this pipeline with any necessary modifications applied:

<<<"$PATH" sed 's/:/\n/g' | xargs -I@ find "@" -name '*a*'

Replace -name '*a*' with any filters you need. If you don't need to apply filters, etc, you can use the short version for the xarg part of the pipeline: xargs find, ie.:

<<<"$PATH" sed 's/:/\n/g' | xargs find

The sed part can in fact be reduced to a here string and delimiter definition as in:

<<<"$PATH" xargs -d: find

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.