Reputation
1,750
Top tag
Next privilege 2,000 Rep.
Edit questions and answers
Badges
8 24
Newest
 Revival
Impact
~139k people reached

Feb
26
comment How do I prevent accidental rm -rf /*?
@ValentinNemcev Doing an accidental rm -rf /* is an age-old Unix rite of passage! Now it's time for you to learn the find command to save yourself from this kind of grief in the future. Certainly you should avoid some of the bad advice that is found in the answers to this question. Suggestions such as using specially-named -i file are akin to telling a kid learning to ride a bike to never pedal, just push on the ground with your feet, oh and also make sure to hold in the brake lever all the time. If you want to ride with the big boys, use find.
Feb
26
comment How do I prevent accidental rm -rf /*?
@SachinDivekar how did this answer get voted so high? safe-rm and ---preserve-root are okay suggestions, but prepending # doesn't really seem to be all that effective. My real gripe, though, is with this special -i file business which is, quite simply, bad advice! Littering your filesystem with odd-named files really is not helpful, especially when there is a simple, effective, general solution using the find command to preview and then delete: find | less and then find -delete.
Feb
26
comment How do I prevent accidental rm -rf /*?
And if you need the directory to remain you can do that quite simply by using find somedir -type f -delete which will delete all files in somedir but will leave the directory and all subdirectories.
Feb
26
comment How do I prevent accidental rm -rf /*?
Yes, I think that scoping out files using find is a good suggestion, however the nuances of xargs are important if you suggest using it, otherwise it leads to confusion and frustration when encountering files with spaces (which is avoided by using the -delete option).
Feb
26
comment How do I prevent accidental rm -rf /*?
It's good you're trying to preview your files before deleting them, however this solution is overly-complicated. You can instead accomplish this very simply in a more generic way using the find command. Also, I don't understand why you say "the good thing about it is that it's only Bash"? It is recommended to avoid bash-isms in scripts.
Feb
26
comment How do I prevent accidental rm -rf /*?
+1 for using some method of previewing your files before you delete them, however there are simpler and safer ways to do that using the find command.
Feb
26
comment How do I prevent accidental rm -rf /*?
@MadHatter Also, globbing, though visually somewhat similar, is very different semantically from regular expressions. In a regex the meaning of * has a very precise definition called the Kleene Star which is a unary operator that matches zero or more elements of the set to which it is applied (in the case of regular expressesions, the character or set of characters preceding the Kleene Star), whereas in globbing the * matches anything in the pattern that follows. They are semantically very different even if they seem to have a similar syntax.
Feb
26
comment How do I prevent accidental rm -rf /*?
@MadHatter Checking to see what files match before you delete them is good advice, but there is a safer and more expressive way to do it with the find command.
Feb
26
comment How do I prevent accidental rm -rf /*?
@Giles Not using rm directly is good advice! An even better alternative is to use the find command.
Feb
26
comment How do I prevent accidental rm -rf /*?
@eventi I agree that there is some terrible advice and ugly hacks in this thread. And it's definitely a good idea to look at something before destroying it, but there is an even better way to do that using the find command.
Feb
26
comment How do I prevent accidental rm -rf /*?
Previewing the files first before deleting them is a good idea, and there is an even safer and more expressive way to do it using the find as I explain in my answer.
Feb
26
comment How do I prevent accidental rm -rf /*?
It is good you suggest using find, but I recommend a safer way of using it in my answer. There is no need to use xargs rm since all modern versions of find have the -delete option. Also, to safely use xargs rm you also need to use find -print0 and xargs -0 rm otherwise you'll have problems when you encounter things like filenames with spaces.
Feb
26
answered How do I prevent accidental rm -rf /*?
Feb
20
comment Resetting SP password using jumper P20 doesn't work on Sun Fire x4600 M2
@WesleyDavid I figured a photo of the screen would help head off people asking questions about whether I had installed the jumper properly or not.
Feb
20
revised Resetting SP password using jumper P20 doesn't work on Sun Fire x4600 M2
added 85 characters in body
Feb
20
asked Resetting SP password using jumper P20 doesn't work on Sun Fire x4600 M2
Feb
19
revised How can I prevent a test virtual host on Apache from consuming too many resources relative to the main host?
added tag plesk
Feb
19
suggested approved edit on How can I prevent a test virtual host on Apache from consuming too many resources relative to the main host?
Feb
18
comment What's the best way of handling permissions for apache2's user www-data in /var/www?
@Tom Great to see that you recommend using the findcommand for this. One small performance tip I would give if you have lots of files/directories and you are using GNU find is to use + instead of \; so that the command will operate on multiple files because "it is faster to run a command on as many files as possible at a time, rather than once per file. Doing this saves on the time it takes to start up the command each time." Also, it is easier to type since it doesn't need backslash.
Feb
16
revised At what point is EBS usage the bottleneck?
added tags performance disk-performance