How to Delete Files in Unix
The 'rm' command in Unix is a very powerful tool for deleting files. Unlike Windows, it performs its operation silently and assumes that you actually do want to permanently delete the file. It is actually possible to remove every file in your filesystem (including required system files). However, when used correctly, it is a quick way to remove any file and clean up disk space.
Instructions
-
Instructions
-
1
Open a terminal window. The terminal window is usually found under Start -> Utilities
-
2
Change to the directory where the files are located.
Our example will be 'doc.txt' and 'doc2.txt' found in /home/Mary/Documents directorycd /home/Mary/Documents
or
cd ~/Documents -
-
3
List the contents of the directory.
ls -la
The -l option shows the time the file was last modified (among other things), -a option tells the ls command to show all files, including hidden files.
This allows you to be sure that your are removing the correct files. -
4
Remove the file with the command:
rm doc.txt doc2.txt
You can specify any number of files after the command.
-
5
Exit the terminal with the command:
exit
-
1
Tips & Warnings
You can perform the same procedure with only one command if you specify the exact path of the file: "rm /home/Mary/Documents/doc.txt /home/Mary/Documents/doc2.txt".
You can use wildcards with the rm command. If you want to remove all the text files in a directory the command would be "rm *.txt"
There is no undelete command in Linux. If you are not sure that you really want to delete the files, use the Graphical User Interface (GUI) and place the file in the Trash folder. This folder acts the same as Windows Recycle Bin.