1,170 reputation
421
bio website localhost
location San Francisco, CA
age 38
visits member for 2 years, 7 months
seen Mar 27 at 21:39

Manager of computing infrastructure for the Department of Electrical Engineering and Computer Sciences (EECS) at the University of California, Berkeley


Feb
28
revised Sort a list of domain names (FQDNs) starting from tld and working left
added 153 characters in body
Feb
28
awarded  Promoter
Feb
28
comment Sort a list of domain names (FQDNs) starting from tld and working left
Do you have timing information for this sort? I'm curious to see how this compares to @Mark-Henderson's PowerShell implementation, as well as my Python implementation. I used /usr/bin/time -v for the elapsed time and max memory stats.
Feb
28
comment Sort a list of domain names (FQDNs) starting from tld and working left
5 seconds seems like a long time for only 1,500 lines. My python implementation does 1,500 in a fraction of a second, and 150,000 in just over 3 seconds. What do you suppose makes it so slow in PowerShell?
Feb
28
revised Sort a list of domain names (FQDNs) starting from tld and working left
added 886 characters in body
Feb
28
answered Sort a list of domain names (FQDNs) starting from tld and working left
Feb
28
accepted Resetting SP password using jumper P20 doesn't work on Sun Fire x4600 M2
Feb
26
comment How do I prevent accidental rm -rf /*?
My intent is to provide a safe, general, effective, extensible answer to the original question: "How do I prevent accidental rm -rf /*?" Using find . -delete is safe(r) because it avoids this very common accidental mistake. It is also safer because makes it easy to preview the file list before deleting. It is a general method that works on any unix system and is not shell-dependent. It is effective because it accomplishes the same thing as rm -rf ./* but is more extensible, for example adding `-iname '*~' makes it easy to delete all *~ files in all subdirectories. How would rm do that?
Feb
26
comment How do I prevent accidental rm -rf /*?
Sure, so BSD find doesn't allow you to omit the directory, so you have find . -delete instead of find -delete. Also, the '*' glob may or may not expand dot files... it depends on a setting, which by default matches the behavior you describe, but if the system or someone has set shopt -s dotglob then it will expand dot files, too. If you are actually dealing with thousands of files you may also run up against the "Argument list too long" error, but that's another one you can avoid by using find.
Feb
26
comment How do I prevent accidental rm -rf /*?
It's clear you don't preview a list of files in your solution... that is exactly the point I'm making with find that you can do that easily simply by leaving off the -delete.
Feb
26
comment How do I prevent accidental rm -rf /*?
How is find -delete or find dir -delete a significant change in workflow? It accomplishes exactly the same thing as rm -rf ./* and 'rm -rf dir/*` without being prone to globbing errors or needing rubegoldberg-esque functions defined in .profile, plus if you want to preview the list of files before you delete them, just remove the -delete from the find command.
Feb
26
comment How do I prevent accidental rm -rf /*?
I understand what you are trying to do with set -f which is equivalently set -o noglob in Bash, but that still doesn't explain your statement that "The good thing about it is that it's only Bash". Instead you can eliminate the problem entirely and in a generic way for any shell by not using rm at all, but rather using the find command. Have you actually tried that suggestion to see how it compares with what you suggest here?
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.