Welcome guest


rm - Remove

Sometimes you will need to get rid of files and directories, so that your account does not become too cluttered. You only have a finite amount of disk quota, and it can be easy to fill up. It is a good idea to remove unwanted files on a regular basis.

The command that will let you remove a file is the rm (remove) command. You should be aware that when you remove a file in Linux it is gone forever so you should make sure that you are careful when using this command.

Syntax

eos% rm filename

The rm command will ask you if you are sure that you want to remove the file. Type 'y' if you wish to remove it, or 'n' if you change your mind. rm also accepts the following dash options:

-r recursively (go into every subdirectory)
-f forced (stops computer from asking your permission for every single file or directory that is removed)
-rf does not ask permission for all files and directories and works recursively

Example 1

How would you get rid of the file INLAB2 from your MyE115 directory (in your home directory) if you were in your home directory?

Ask yourself:

Q: What am I doing? A: Removing a file.
Q: How do I do that? A: Using the rm command.
Q: What are the path names? A: I am in my home directory, the file is in my MyE115 directory and will be totally removed.

rm File Tree

As with all Linux commands, you could have issued the entire path name:

eos% rm /afs/unity.ncsu.edu/users/y/yourhome/MyE115/INLAB2

BEWARE: There is a command in Linux called delete. The delete command does not actually erase or get rid of a file. Instead, it marks it for deletion, and makes the file invisible to you. You then have to use the expunge command to actually delete it. Use the rm command. It is easier to deal with.

Example 2

How would you get rid of the file INLAB2 from your MyE115 directory (in your home directory) if you were in your home directory.

Ask yourself:

Q: What am I doing? A: Removing a file.
Q: How do I do that? A: Using the rm command.
Q: What are the path names? A: I am in my home directory, the file is in my MyE115 directory and will be totally removed.

rm File Tree 2

With any Linux command you can first change directory (cd) to the place where the file you want to work with is located and then issue a command to work with the file. You should get used to the idea that all Linux commands may be used together. For example, you could have also changed directory cd) to the MyE115 directory, used pwd to see if you were there, used ls to determine if the file INLAB2 was located there, and then used the rm command to get rid of the file.

Example 3

How would you remove MyE115 and everything in it if you were in your home directory?

Ask yourself:

Q: What am I doing? A: Removing an un-empty directory.
Q: How do I do that? A: Use the rm with the -rf options.
Q: What are the path names? A: I am in my home directory. It is in my home directory and I am going to remove it completely.

rm File Tree 3

rm is a very useful command. However, if you are not careful you can delete all of your files. Be careful when using it