Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 917
Yen Avatar asked May 04 '09 16:05

Yen


People also ask

How will you remove all files in current directory including the files that are two levels down in a sub directory?

Just typing rm <directory name> just leads to number of sub questions in which each of the sub directory must be removed manually. But, rm -rf helps in removing the whole directory along with its sub directories at once.


1 Answers

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.

like image 128
tvanfosson Avatar answered Sep 19 '22 18:09

tvanfosson