Remove Files and Directories That Aren't Emptyrm -RfThere is an easier way to remove directories with files. Use the combination of the -R (or --recursive) and -f (or --force) options. The -r tells rm to go down into every subdirectory it finds and delete everything, while the -f tells rm to just do it without bothering you with the niceties, such as folders that aren't empty. $ pwd /home/scott/libby/by_pool $ ls pool_02.jpg lieberman_pool lieberman_pool_bak $ ls lieberman_pool_bak pool_01.jpg pool_03.jpg pool_01.jpg_bak pool_03.jpg_bak $ rm -Rf lieberman_pool_bak $ ls pool_02.jpg lieberman_pool Pow! That's a sure-fire way to get rid of a directory and all the files and subdirectories inside it. Caution The rm -Rf command can destroy your important files and your system. The classic Linux warning is not to type rm -Rf /* as root. Yes, you will erase your system. No, it will not be pretty. Yes, you will feel stupid. In general, be careful when using wildcards with rm -Rf. There's a huge difference between rm -Rf libby* and rm -Rf libby *. The former deletes everything in the working directory that begins with libby; the latter deletes any file or folder named exactly libby, and then deletes everything else in the directory. You can also inadvertently create a disaster if you mean to enter rm -Rf ~/libby/* and instead fat finger your command and tell the shell rm -Rf ~/libby /*. First the ~/libby directory leaves, and then your file system begins its rapid journey toward nonexistence. Here's one that's bitten a few folks trying to be clever: Never type rm -Rf .*/* to delete a directory that begins with . because you'll also match .. and end up deleting everything above your current working folder as well. Oops! Once again: Be careful using rm -Rf when you're a normal user. Be hyper vigilant and paranoid when using rm -Rf as root! |