views:

136

answers:

3

I am using a mac. When I use the "rm" command it can only remove files. The "rmdir" command only removes empty folders. If you have a directory with files and folders with files and folders in them and so on. Is there anyway to delete all the files and folders without all the strenuous command typing? Remember, I am using the mac bash shell from terminal, not Microsoft DOS or linux.

+3  A: 
rm -rf some_dir

-r "recursive" -f "force" (suppress confirmation messages)

Be careful!

Jim Lewis
+1 and glad you added the "Be careful!" part... definitely a "Sawzall" command that can quickly turn a good day into a bad one.. if wielded carelessly.
itsmatt
like dont do "# rm -rf /"you ll regret that:
@itsmatt: You know what they say...give someone a Sawzall, and suddenly every problem looks like hours of fun!
Jim Lewis
A: 
rm -rf *

Would remove everything (folders & files) in the current directory.

Prine
+2  A: 

Yes, there is. The -r option tells rm to be recursive, and remove the entire file hierarchy rooted at its arguments; in other words, if given a directory, it will remove all of its contents and then perform what is effectively an rmdir.

The other two options you should know are -i and -f. -i stands for interactive; it makes rm prompt you before deleting each and every file. -f stands for force; it goes ahead and deletes everything without asking. -i is safer, but -f is faster; only use it if you're absolutely sure you're deleting the right thing. You can specify these with -r or not; it's an independent setting.

And as usual, you can combine switches: rm -r -i is just rm -ri, and rm -r -f is rm -rf.

Also note that what you're learning applies to bash on every Unix OS: OS X, Linux, FreeBSD, etc. In fact, rm's syntax is the same in pretty much every shell on every Unix OS. OS X, under the hood, is really a BSD Unix system.

Antal S-Z
Although all the options mentioned above are standard among all the Unix flavors listed, there are some differences too. For example, OS X (but not Linux) has `"rm -d"`, which removes either files or empty directories. Still, +1 for the point that OS X is BSD internally.
David Gelhar
True---the *POSIX subset* is (pretty much) guaranteed to work consistently across Unixen, but anything outside that may or may not.
Antal S-Z