Display directories only
Solved
artagon7
Posted messages
423
Status
Member
-
dennys -
dennys -
Hello,
I want to display only the directories contained in a given directory. I read the man page for ls and what I found is the -d option, but it doesn't work. How do we display only the directories (recursively)?
Thank you
I want to display only the directories contained in a given directory. I read the man page for ls and what I found is the -d option, but it doesn't work. How do we display only the directories (recursively)?
Thank you
Configuration: Linux Konqueror 3.5
9 answers
-
Hello!
You can also use "ls -d */"
ls -d: to tell it not to descend into subdirectories
*/: to tell it to display all those that end with "/" which are only the directories
+ -
Personally, I prefer tree for that.
tree -d directory/
--
Archlinux ... A lightweight, fast, and KISS distribution on archlinux.fr -
Salut,
ls -lR | grep ^d
orfind . -type d -exec ls -ld {} \;--
106485010510997108 -
I tried your three commands and only the command from perlien at lami20j worked, which is ls -lR | grep ^d.
In the case of the command proposed by jipicy (ls -R | grep '/$'), it doesn't display anything, while the command from marc[i1] doesn't work because there is no tree command in my shell!!! (I checked with man). As for the last two commands, it probably depends on the distribution we have.
Thank you all three, :-) -
The command "tree" is not installed by default, that's why I didn't suggest it. However, I always install it on my systems... and the Martian does apparently too ;-)
As for the command "ls -R | grep '/$'", indeed it depends on the distributions and the configuration of "ls" (alias to be precise in the form "alias ls='ls -F --color=auto'" for Mandriva for example), so you just need to write it with a patriotic flair for it to have the desired effect:ls -FR | grep '/$'
;-))
--
JP - Penguin breeder -
Do a favor for the environment, close your windows and adopt a penguin. -
Hello,
Yes, indeed the command ls -FR | grep '/$' works. But ultimately it doesn’t give a very practical result, unlike the other command. For example, I have the directory /Informatique:
/Informatique
../Linux
...../Fichiers_systemes
...../Pages_man
../Programmation
...../Langage_C
...../Scripts_bash
../Test
...../Test_1
...../Test_2
...../Test_3
...../Test_4
If I run the command ls -FR | grep '/$', it gives me:
$ ls -FR | grep '/$'
Linux/
Programmation/
Test/
Fichiers_systemes/
Pages_man/
Langage_C/
Scripts_bash/
Test_1/
Test_2/
Test_3/
Test_4/
In this case, I can still find my way. But in the case where I take a larger directory, I might get lost. In this case, is it possible to get something that looks like:
/Informatique
../Linux
...../Fichiers_systemes
...../Pages_man
../Programmation
...../Langage_C ... etc ...
I believe that the command from marc[i1] would be more appropriate, at least that’s what the name of the command suggests. If the command tree gives the result I want, I would like to install it. How do I install tree?
Thank you, -
-
Hello,
At least you tried?!
The -d option does not serve to display only directories but
-d, --directory
displays directory names instead of their contents and does not dereference symbolic links
lami20j@debian-acer:~/div$ ls -l total 4 drwxr-xr-x 2 lami20j lami20j 4096 Nov 30 17:09 aaa -rw-r--r-- 1 lami20j lami20j 0 Nov 30 17:09 toto.txt lami20j@debian-acer:~/div$ ls -d * aaa toto.txt lami20j@debian-acer:~/div$ ls -d */ aaa/
The -d option does not serve to display only directories but (man ls)
-d, --directory
displays directory names instead of their contents and does not dereference symbolic links
Here’s what happens when I use -d with -Rlami20j@debian-acer:~/div$ ls -lRd * drwxr-xr-x 2 lami20j lami20j 4096 Nov 30 17:11 aaa -rw-r--r-- 1 lami20j lami20j 0 Nov 30 17:09 toto.txt lami20j@debian-acer:~/div$ ls -lR * -rw-r--r-- 1 lami20j lami20j 0 Nov 30 17:09 toto.txt aaa: total 0 -rw-r--r-- 1 lami20j lami20j 0 Nov 30 17:11 zzz.png lami20j@debian-acer:~/div$
orlami20j@debian-acer:~/div$ ls -l aaa total 0 -rw-r--r-- 1 lami20j lami20j 0 Nov 30 17:11 zzz.png lami20j@debian-acer:~/div$ ls -ld aaa drwxr-xr-x 2 lami20j lami20j 4096 Nov 30 17:11 aaa lami20j@debian-acer:~/div$
-
-
-
Yes indeed.
The --directory option is more subtle than I thought.
Thank you for this clarification. -
Hello,
as such, from the beginning you should tell us what display you want to get ;-)
in this case, indeed the command given by marc[i1] is the solution
if I'm not mistaken you are on ubuntusudo aptitude install tree
--
106485010510997108