Unix Commands: rm
Posted 01/23/2011 at 3:29pm
| by Cory Bohon

Deleting files and folders in Unix can be a little scary, so use caution. Unix doesn’t have a trash bin that your files go to when deleted. Once you invoke the delete command, the files or folders will be gone. Forever. We cannot stress this enough.
To delete a file, you will use the rm command. This stands for “remove.” So, if you had the file “test.txt” in your current working directory, you would type the following command to remove it:
rm test.txt
The file would then be removed from the directory that you’re currently working in.
Alternatively, you could use rm -i test.txt, which asks for a confirmation before removing the file.
Deleting directories (folders) can be a bit trickier. The standard rm will not work on removing directories. To remove a directory called “Test,” use the following command:
rmdir Test
However, this command will only work on directories that don’t have additional files and subdirectories contained in them. To remove a directory that has files in it, you’ll need to use the following command:
rm -r Test
This will use what’s known as recursion to delete all of the files and folders contained in the directory before finally deleting the directory itself.