Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'BAD advice' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
BAD advice
Authored by: vipw on May 02, '01 04:23:00AM

this is a good way to learn why you gotta be careful with rm -rf.

particularly, doing a find and piping through xargs rm is dangerous.

the find search will list all directories named .Trash, removing all of them is fine, however using xargs is not the safe way to do it.

say you have "/Users/Bozo/.Trash" and "/Users/Bozo The Clown/.Trash"
both of those will match and will be passed to xargs. however, when xargs runs
"rm -rf /Users/Bozo The Clown/.Trash" it will first remove all of /Users/Bozo, then try removing The, and then try removing Clown/.Trash. this will entirely remove Bozo's home directory and the removal of The and Clown/.Trash will fail.

luckily, find has ways to do this whole procedure correctly.
find / -name ".Trash" -type d -exec rm -rf {} ';'

that will only delete directories named .Trash

better yet is to change -exec to -ok, and then it will prompt you before each trash directory.
find . -name ".Trash" -type d -ok rm -rf {} ';'

even so, using find to clean up .Trash directories is pretty sloppy. you would probably be better off querying the lookupd/netinfo for the users' home dirs and deleting .Trash from there, but hey, i have no idea how to do that, os x doesn't seem to use the password files.



[ Reply to This | # ]