Jump to content

A very dangerous gotcha


Guest Adriano1
 Share

Recommended Posts

Guest Adriano1

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest Adriano1

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.

Link to comment
Share on other sites

Guest Adriano1

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.

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

Guest Adriano1

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".

Link to comment
Share on other sites

Guest Adriano1

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...