How can I list directories only in linux?
How can I list directories only in linux?
What would the command be? |
'ls'? You need to be more specific with your question.
|
Here's one way:
ls -p | grep "/" The -p option to ls appends a / character to all directories (this character can never appear in a file name). Grep then filters the resulting information, to only show entries that contain a / character. The only slight downside of this is that the list you get will have the slash on the end of each line. If this is a problem, you should be able to get rid of it using cut. |
You could try 'tree -d -L 1'
|
Here's another one
Code:
find . -type d -exec ls -d {} \; |
The shortest and simplest way
ls -d */
I just found this out after nearly 3 years of using Linux. |
If you want to include the hidden directories, you may want to try one of these....
Code:
find . -type d -exec ls -d {} \; |
What about listing only directories recursively? Can it be done with just ls? ls -dR doesn't seem to work as I'd like it. It seems that "list recursively" and "list dirs but not contents" clash...
|
Try "du":
Quote:
If the left column (directory size) annoys you, you can easily eliminate it with: du|awk '{print $2}' |
Quote:
|
Code:
ls -l |grep ^d |
Quote:
|
ls -d */
Check this out:
http://www.amjith.blogspot.com/2005/...-in-linux.html |
'ls -ld */' rocks !
Code:
ls -ld */ Code:
ls -p | grep "/" Code:
lsd='ls -ld */ .*/' |
Here is inline bash scripts
listing only directories: Code:
for f in *;do if [[ -d $f ]]; then echo $f;fi; done; Code:
for f in *;do if [[ -d $f ]]; then echo "" > /dev/null ;else echo $f ;fi; done; Code:
for f in *;do if [[ -d $f ]]; then echo $f; done; |
All times are GMT -5. The time now is 07:12 PM. |