Linux Commands

How do you Remove a File in Linux?

We all know about the GUI-based method of removing a file from a Linux system. However, if you are a CLI lover, you must know the methods through which you can remove a file from your Linux system through the Linux terminal. This article will teach you two different methods of removing a file in Linux through the terminal.

Methods of Removing a File in Linux

To quickly remove a file from your Linux system, you can use any one of the following two methods:

Method # 1: Using the Unlink Command

This method makes use of the unlink command in Linux for removing a file. You simply need to use this command as shown below:

$ unlink abc.txt

“abc.txt” is the name of the file that we wished to remove. You can conveniently replace it with the name of your particular file. Once the file will be removed successfully, no results will be produced on the terminal as shown in the following image:

Note that if you want to confirm the removal of the specified file, you can simply run the “ls” command inside the relevant directory to see if the specified file exists there or not.

Method # 2: Using the RM Command

This method uses the RM command in removing a file from your Linux system. You just need to execute this command as shown below:

$ rm abc.txt

Again, you can replace “abc.txt” with the name of the file that you intend to remove from your Linux system. This command will also not produce any results on the terminal as shown in the following image:

Note that if you want to confirm the removal of the specified file, then you can simply run the “ls” command inside the relevant directory to see if the specified file exists there or not.

Conclusion

This article was based on the two methods of removing a file in Linux. The first method is capable of removing only a single file at a time whereas the second method can also be used for removing multiple files at once from your Linux system.

Similar Posts