SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810
Rep:
Quote:
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 will give you the listing for the directory entry rather that it's contents - to see the difference try running ls -d mydir and ls mydir where mydir is a directory.
Quote:
ls -d */
@Chuck56: I like that solution - nice bit of thinking there.
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.
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.