ls to view directories only
Hi. I realise that the answer to this question is probably in the man page, but I seem to be incapable of finding it!
I would like to use the 'ls' command to display directories only. (Equivalent of MSDOS 'dir /ad') I've tried: ls -d * ls --directory * ls -ldR * together with various combinations of the above. Nothing I have tried seems to give me what I want, and I am starting to get a little frustrated. Please put me out of my misery!... |
What is your current working directory? Are there any subdirectories in the current working directory?
Have you tried the command without the * |
|
Thanks for replying. I'm in my home directory, and I do have sub-directories. I've tried with and without the '*'.
The only results I seem to be able to get are either a complete listing including subdirectories and files, or just the current directory, '.' ls -d ls -dR ls -dr ls --directory -R ls --directory -r ls --directory all just return '.' |
Thanks, LinuxLaLa. I appear to have been mixing up directories with directory entries...
For anybody else who may be interested, tree -d gives the same results. A bit simpler than all that 'grep' malarky! |
Cool. Thanks for sharing with us all.
Cheers. |
is this what you want?
Code:
ls -d */ |
Code:
|
you can put loads of "*/" together like so to go deeper:
Code:
> ls -1d ileaf/*/*/ billy |
Spot on. Thanks, bigearsbilly.
|
The problem is that is gives the full path of the folder with ls -d1
:( Quote:
:( |
confused
Quote:
[norm@localhost ~]$ ls -d */ bin// Dropbox// Movies// playground// tmp// Desktop// FAH6.02-Linux// MP3// pyNeighborhood// Videos// Documents// Linux Cookbook - allfreeebook.tk// Music// smb4k// work// Downloads// lmms// Pictures// Templates// then cd MP3 [norm@localhost MP3]$ ls -d */ ls: invalid option -- '=' Try `ls --help' for more information. [norm@localhost MP3]$ |
Keep in mind that it's really your shell that is expanding that "*/" to a list of directories that is then seen by ls. What is probably happening is that your MP3 directory has a subdirectory with a name beginning with '-', and ls tries to process that entire name as a set of flag arguments. Try this:
Code:
ls -d -- */ |
Quote:
The offending directory is appropriate -----> -=A3-Sopranos Soundtrack=-// You're absolutely right! Do I understand you to mean [norm@linux-2 ~]$ ls -l -a # aaaah! I see how the -=A3Sopranos would get expanded by bash total 10492 drwx------ 79 norm norm 4096 Jul 17 14:06 ./ ls -d */ shell expands */ to all lines ending in / then passes it all to ls -d -=A3Sopranos BUT -=A3Sopranos is not the first entry so ls must be checking to see if it can list EVERYTHING without errors before ANYTHING is sent to stdout ie display. Is that right? HOWTO Train Brain to expand like Bash! |
As rknichols said, when you type that cmd, bash is expanding the wildcard, then passing to ls.
The only way to think like bash is practice... ;) Try these for ref http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
That's right, the directory list isn't being generated by ls, but by shell globbing. ls is only reading the list to give you detailed info.
http://mywiki.wooledge.org/glob For a simple list, you can even do this: Code:
echo */ |
Quote:
It appears that the ls command is in the second category. |
It seems everyone is doing it the hard way. The simplest way to list a directory and only the folders, without the full path is:
ls -F <whatever path you want> | grep / For example ls -F ./ | grep / will list the local directories ls -F Documents/ | grep / will list all of the directories in the folder Documents Hope this helps! |
the simplest way is:
Code:
ls -d */ |
To also show hidden directories, I prefer:
Code:
ls -al | grep ^d |
If you're not stuck on using ls, the command find . -maxdepth 3 -type d would list all directories under ./, for no more than three levels. Here's an example:
Code:
$ cd Scripts/ Or you could use this: Code:
$ tree -dL 2 |
command to list directories only
Hi,
Please try below command. it should be listed the directories only. ls -l|grep "^d" |
ls -dl `find /location/of/your/dir -type d`
Thanks to Marius Ducea http://www.ducea.com/2009/06/05/linu...nd-full-paths/ |
Quote:
($(..) is highly recommended over `..`, BTW.) Code:
$ mkdir 'aa bb' Code:
$ find . -type d -exec ls -dl '{}' \+ Code:
$ find . -type d -ls |
for ZSH ;)
alias lsd="ls -d \.#*(/)"
with setopt extendedglob |
Just the DIRs please.
Code:
ls -lF |
'Nother necro...
|
All times are GMT -5. The time now is 01:38 PM. |