Weblog (or Blog)

Thursday, May 09, 2019

Zed Shaw's CLI Tutorial

In an earlier post, I recommended that beginners go through Zed Shaw's Crash Course to hone their basic skills in using the command line. If you use macOS and are doing Exercise 7, you may get a message that the directory you are trying to remove using rmdir is not empty. rmdir can only delete (remove) an empty directory. The reason the directory is not empty is that you may have used Finder to display the directory, resulting in Finder creating a hidden file holding its settings.

At the bottom of the list of commands to practice for Linux/macOS, Shaw provides a warning about and instructions if you get the "not empty" message. He recommends that you use rm -rf <dir_name> instead of rmdir. That works. But Shaw does not explain that the -rf switch requires care because you are telling macOS to remove (delete) without confirmation the directory and all of its subdirectories (i.e., the -r switch means to recurse through all subdirectories). If you mistakenly type rm -rf /, you will delete every directory on your hard drive. So be very careful with rm -rf <dir_name>.

posted at: 09:57 | path: /bash | permanent link