Listing only subdirectories.
Hi:
Being at a certain directory I want to list the names of all subdirs under this dir. I have found this can be done with 'find . -type d -maxdepth 1'. Question: can this be done with the ls command? Regards. |
I might misunderstand your question but have you looked at the man page?
man ls Try: ls -d * |
Hi:
I have read ls man page throughout. But 'ls -d *' does exactly the same as 'ls'. At least in my system (slackware 12.0). Thanks for your reply. |
ls -d */
or ls | grep / |
Quote:
Quote:
|
Well, thank you very much. I can see how bash expands * or */ by issuing 'ls */'. Adding the -d option prevents ls from entering the child directories. But given that in 'ls *' * expands in the same way, I can't see where is the difference. Anyways, the command works, and that's fine with me.
|
Yes. Many times, when I wanted to see the file mode bits of a directory, I was forced to use the -d option. For example, with 'ls -l samples/' I only could see the contents of ./samples. But if I did 'ls -ld samples' then I could see the file mode bits of directory ./samples. The grep trick I also had used it, but I did not like to depend on the graphical output of the listings. The 'find' solution seemed good to me but if I could do it with 'ls' I would have more control over the listing format and information.
In M$-DOS it is very simple: DIR/AD. That's all. Of course, it isn't as powerful as ls is. Well, this is commentary, nothing else. Thanks to you both and regards. |
Yes - to be honest I have often used "find -d" to show directories somewhere not knowing of Chuck56's clever solution - either using find or just paging through a ls directory listing looking for directories - Chuck56's method is really cool. One for me to store in my "linux tricks" book I think. Thanks again Chuck56.
|
Alternative solution
ls -l | grep ^d include hidden dirs ls -la | grep ^d |
All times are GMT -5. The time now is 04:46 PM. |