[SOLVED] rm files only - retain directory structure
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.
hi, i am trying to recurse into directories and delete only files.
Code:
cat set-share.bash
#!/bin/bash
for line in "`find nov`"
do
# echo "$line"
rm "$line"
done
set-share.bash
...
nov/stuff/folder - two/link to file.lnk
nov/Projects/name - of - directory
nov/Projects/RE access.msg
nov/Security: A file or path name is too long.
find nov | wc -l
235
# to find the longest fine-name find nov | cut -b 50- | more
nov/Projects/very long project name/very long project name - very long project requirements description_11-21-05.xls
longname="nov/Projects/very long project name/very long project name - very long project requirements description_11-21-05.xls"
rm "$longname" #works
can someone explain why this is failing or have a better idea,
thanks,
because of the quotes around "`find nov`" it considers all 235 lines one long file-name. but without the quotes file-names with spaces will get truncated. is there another way to 'wrap' file-names that contain spaces?
Not only is this thread over 7 years old, the suggestion isn't even a good one. `pwd` is unnecessary, just use ".", and directory names can have .'s in them as well...such as hidden directories, "d.name" naming schemes, etc. And to top it all off, piping the output to xargs will break if any of the matches have a space or other "bad" character in the name.
Hko already provided the correct solution in 2005.
Last edited by suicidaleggroll; 05-30-2013 at 12:16 PM.
Not only is this thread over 7 years old, the suggestion isn't even a good one. `pwd` is unnecessary, just use ".", and directory names can have .'s in them as well...such as hidden directories, "d.name" naming schemes, etc. And to top it all off, piping the output to xargs will break if any of the matches have a space or other "bad" character in the name.
Hko already provided the correct solution in 2005.
Why is pwd unnecessary?
if you try to rm a directory you will get an error message and the directory won't be deleted. Who uses file names with spaces or bad characters?
I posted a reply because there was no "one liner" and this was the first thing that came up when i googled the same question. I wonder why I went out of my way to post a reply.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.