In Unix, how do you remove everything in the current directory and below it?

Yen picture Yen · May 4, 2009 · Viewed 206.7k times · Source

I know this will delete everything in a subdirectory and below it:

rm -rf <subdir-name>

But how do you delete everything in the current directory as well as every subdirectory below it and the contents of all of those subdirectories?

Answer

tvanfosson picture tvanfosson · May 4, 2009

Practice safe computing. Simply go up one level in the hierarchy and don't use a wildcard expression:

cd ..; rm -rf -- <dir-to-remove>

The two dashes -- tell rm that <dir-to-remove> is not a command-line option, even when it begins with a dash.