Deleting a File or Directory with rm

To delete a file named filename, use this command:

matthew@seymour:~$ rm filename

You can remove a directory in a different location by changing what is after rm. To remove a directory in /home/matthew/randomdirectory, if I am already in my /home directory, I can use the following:

matthew@seymour:~$ rm randomdirectory/filename

Or from anywhere using an absolute path, I can use this:

matthew@seymour:~$ rm /home/matthew/randomdirectory/filename

Or from anywhere using a path shortcut, I can use the following command:

matthew@seymour:~$ rm ~/randomdirectory/filename

If you try to use rm to remove an empty directory, you will receive an error message: rm: cannot remove `random/': Is a directory. In this case, ...

Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.