UNIX Primer

Home | Primer Home


Cleaning Up

We often find that we no longer have use for some of our files. In this case, we want to get rid of them to make room for others. The following commands allow us to do this.

Related Commands:

NameMeaningPurpose
rm ReMove To permanently delete files.
Syntax
rm <filename>
Notes
  • Use with caution. Files are not recoverable once they are deleted.
  • If you type 'rm -i' it will interactively prompt you before deleting each file that you specify. It is often useful to make an alias that automatically uses this option for you. See: advanced lesson 10 - other useful commands
  • To remove a directory without first deleting its contents, you can run 'rm -rf <dirname>' --- do so with GREAT CARE! The f option forces the delete, and the r option causes it to delete recursively. So, if you accidentally 'rm -rf ~', every file in your home directory will be permanently deleted.

NameMeaningPurpose
rmdir ReMove DIRectory Removes an empty directory from the filesystem.
Syntax
rmdir <dirname>
Notes
  • To run 'rmdir' on a directory, it must be empty. You can empty it using the 'rm' command.
  • To remove a directory without first deleting its contents, you can run 'rm -rf <dirname>' --- do so with GREAT CARE! The f option forces the delete, and the r option causes it to delete recursively. So, if you accidentally 'rm -rf ~', every file in your home directory will be permanently deleted.


Designed by D. Kaminsky
Edited by Diana Palsetia
© University of Pennsylvania, 2008