[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.
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.
Quote:
Originally Posted by andrew.comly
Your right when only counting the amount of lines(how many directories).
Unfortunately, when making a "list", the spaces for this purpose, the spaces end up breaking the list up.
Quote:
Originally Posted by andrew.comly
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).
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place.
What you're not indicating here is the exact reason why this list was broken.
It is clear to me that I can create an example directory structure where directories contain spaces in the file names and that find command works perfectly.
You have been unclear about the exact requirements for this list.
I am not asking to see a link to some other question.
I also do not feel it will be helpful to repeat something like your first post where you show code and command attempts only.
What I am asking for is input/output examples and more exact requirements for this desired list.
If you feel that you have covered that topic sufficiently in your other thread in Programming, then I will close this thread to avoid frustrating fellow members and let you continue with that question to resolve your problem.
I did some testing on my computer, at it didn't appear that space mattered, it was like the {} substitution was automatically escaped to ignore the spaces, the entire directory, including the spaces, were passed and processed as one directory or file name.
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.
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place.
What you're not indicating here is the exact reason why this list was broken.
It is clear to me that I can create an example directory structure where directories contain spaces in the file names and that find command works perfectly.
You have been unclear about the exact requirements for this list.
I am not asking to see a link to some other question.
I also do not feel it will be helpful to repeat something like your first post where you show code and command attempts only.
What I am asking for is input/output examples and more exact requirements for this desired list.
If you feel that you have covered that topic sufficiently in your other thread in Programming, then I will close this thread to avoid frustrating fellow members and let you continue with that question to resolve your problem.
This is actually a bit different from the specific application thread.
However, concerning closed threads, I have another thread I merely put up by accident.
The specific story is as follows: I had originally put up the a first thread. Then a minute later I went to edit it, but it wasn't on "my threads". So I thought it got erased or something. Naturally I then copied the tread again from my text file (on my HDD) into your forum again. Then I saved it, logged out and then came back the next day to discover that the first attempt to post hadn't been erased, but it had come back from ghostland and had caused the corrected second attempt post to be marked as a duplicate. Being that there was some valuable replies to the non-corrected first response, is there any way we can erase the corrected second attempt to post and just keep the first? Is that why I have a disabled reputation? Do I have a disabled reputation because my linux ability is a beginner?
It is too bad there is no technical support email that we can email and tell you about things like this.
Last edited by andrew.comly; 07-01-2017 at 01:25 AM.
Reason: grammar
You can use either the Report button to contact the moderator of the forum where the thread is to ask to move, close, or merge threads. You can also use the Contract Us link to send a message to Jeremy.
Reputation is a setting you can change in your profile to enable or disable.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.