Guest Adriano1 Posted April 1, 2005 Report Share Posted April 1, 2005 As I was reading some weeks ago, the result of the command rm -rf ./.* is not what one would expect. To see why, feel free to echo ./.* Especially as root, the consequences could be a bit devastating. Just felt it needed to be said. Please, do feel free to remove this if it's redundant. Quote Link to comment Share on other sites More sharing options...
DragonMage Posted April 1, 2005 Report Share Posted April 1, 2005 The command rm -rf can be devastating period. Especially when done as root. There are many horror stories of a sleepy / drunk / stupid administrator accidentally wiped out his hard disk / important files / directories just because of typing this command. Quote Link to comment Share on other sites More sharing options...
Guest Adriano1 Posted April 1, 2005 Report Share Posted April 1, 2005 yes, but this is especially insidious. What if you want to delete all hidden files on a folder (let's say you wanted to upgrade a system cleanly, for example)? This is the command that comes immediately to mind, yet it would erase all your folders. Quote Link to comment Share on other sites More sharing options...
Dyslexic Posted April 1, 2005 Report Share Posted April 1, 2005 I don't get it. I just tried the echo command on my system, and it does exactly what one would think. It returns everything in the current dir that starts with a dot. Quote Link to comment Share on other sites More sharing options...
Guest Adriano1 Posted April 1, 2005 Report Share Posted April 1, 2005 Hint: look at the first two items in that list. What do you think happens when you do rm -rf ./.. ? Quote Link to comment Share on other sites More sharing options...
Dyslexic Posted April 1, 2005 Report Share Posted April 1, 2005 I'd expect to get an error message since bash protects . and .. Quote Link to comment Share on other sites More sharing options...
Guest Adriano1 Posted April 1, 2005 Report Share Posted April 1, 2005 well, bash is not the only shell out there, as we know. FTR, I saw this gotcha reading through some alt.sysadmin.recovery related pages. Perhaps it doesn't work in some shells. I'll create a new user and test it. Quote Link to comment Share on other sites More sharing options...
Havin_it Posted April 1, 2005 Report Share Posted April 1, 2005 Just a small tangential thought, but does rm stop once it has deleted itself? Quote Link to comment Share on other sites More sharing options...
Guest Adriano1 Posted April 1, 2005 Report Share Posted April 1, 2005 Not necessarily, if it is stored in memory... Quote Link to comment Share on other sites More sharing options...
paul Posted April 1, 2005 Report Share Posted April 1, 2005 for i in `find . -type f -name '.*'` do rm $i done or find . -type f -name '.*' > filelist while read filename; do rm "$filename"; done < filelist either of those suggestions should do what you're wanting to do ;) Quote Link to comment Share on other sites More sharing options...
Guest Adriano1 Posted April 1, 2005 Report Share Posted April 1, 2005 Sure, but they don't immediately come to mind as the quickest option, do they? And also, '.*' doesn't mean "all files that begin with an asterisk or not"? I thougth * here meant "0 or more of the previous". Quote Link to comment Share on other sites More sharing options...
Guest Adriano1 Posted April 1, 2005 Report Share Posted April 1, 2005 Ok, after a bit of testing I can vouch that at least my bash (FC3) doesn't do evil with my command (outputs "can't delete ." and "can't delete ".."), and also that Paul's first command works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.