[SOLVED] Subject: Can't make a list of Directories since some names contain spaces.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
As you can see by the "8", same problem as attempt01
Attempt04:
Code:
ls -l ee/ | grep ^d
drwxrwxr-x 2 a a 4096 6月 26 22:19 unit 1
drwxrwxr-x 2 a a 4096 6月 26 22:19 unit 2
drwxrwxr-x 2 a a 4096 6月 26 22:19 unit 3
drwxrwxr-x 2 a a 4096 6月 26 22:19 unit 4
$ ls -l ee/ | grep ^d | awk '{for(i=9;i<NF;i++)printf$i}'
unitunitunitunit
Even awk cuts the parts of the DIR name off after the space.
Is there anyway of making a list of all DIR, including ones whose DIR names include spaces?
1) Don't store the output of ls in an intermediate variable, just pipe it straight to wc
2) Use the "-1" flag in ls
3) Use the print0 flag in find to print out the names with null terminators, then use the files0-from flag in wc to read it properly
If you want an answer in Perl, I'll write one. But I'm not going to waste time to make one if you're just going to say you don't like Perl or something (like so many have to me in the past).
I would like to make a list of all directories in a parent directory.
...
Is there anyway of making a list of all DIR, including ones whose DIR names include spaces?
Yes, find . -type d was previously attempted. Also List=$(find . -type d) was previously attempted, and due to some dir/file names containing spaces, the list is broken (application).
If you want an answer in Perl, I'll write one. But I'm not going to waste time to make one if you're just going to say you don't like Perl or something (like so many have to me in the past).
I really do appreciate your team spirit, and hope to be able to help you sometime in the future. The only problem is that I am just an independent bash programming student, and haven't even learned how a shellscript can call a perl script yet. This doesn't mean that I don't regard perl as an outstanding language to learn, it's just that it might distract me in my current stage of development. This specific question is no emergency.
It's a lot easier just to let the find command do the work an not have to worry about how the shell will parse the resulting list.
Code:
find AC -type d -exec chmod 700 {} \;
find AC -type f -exec chmod 600 {} +
The first command tells find to execute the chmod command immediately on each directory it discovers since it can't descend into a directory until the appropriate permission has been set. The second command, ending with "+" instead of "\;" allows find to pass as many file names as it can to each invocation of chmod.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.