1

I'm trying to print a list of the directories within a directory path i'm passing to a bash script. I know that

    ls -dn */ 

will print the list of only dirs within the current path, but i want to print the ones within the path i provided to the script.

1
  • i am guessing that you want to print only the path of the dir which you provide with your script . Commented Sep 6, 2013 at 14:23

1 Answer 1

1

You can use ls with the variable also to list directories:

p="somepath"
ls -dn "$p"/*/

Or using find:

find "$p" -type d -maxdepth 1
Sign up to request clarification or add additional context in comments.

3 Comments

-maxdepth 1 is not necessary
I added -maxdepth 1 to make sure to get directories from 1st level only, otherwise it will find directories from any level below given path.
mmm that useful, thank. by the way, i noticed that -maxdepth 1 should appear after "$p" and before -type..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.