How to Remove Files Using Linux Commands

Remove Files Using Linux Commands

If you are new to Linux, you must know Linux commands. We can do everything in Linux using the command line including the deletion of files or folders. In this tutorial, I will show you to remove files in Linux using the command line.

How to Remove Files

In Linux, we use either the rm or unlink command.

Here is the syntax

$ unlink filename
$ rm filename

While using these commands, be careful. It is because it will not ask for your confirmation when deleting files. Files once deleted using rm command are gone. So, be careful.

If you try to remove a file that is write-protected, it will ask you to confirm. In such cases, type Y and hit Enter to confirm the deletion. Otherwise, it will delete the file with our prompting.

If you are using the unlink command you can only remove one file at a time, but the rm command lets you remove multiple files at the same time.

To delete multiple files using the rm command, here is the syntax you need to follow.

$ rm filename1 filename2 filename3

The rm command also supports wildcard (*) and regular expansions. So, you can use these to delete multiple files. For example, if you want to remove all .jpg images in the current directory, use the following command.

$ rm *.jpg

If you want the system to confirm each file before deleting it, use -i option

$ rm -i filename(s)

If you do not want the prompt and force delete all files including write-protected. Use -f option to the rm command.

$ rm -f filename(s)

If you want to see the report of each file removed, use -v option.

$ rm -v filename(s)

You can also combine these options. Like if you want the system to prompt before each deletion and show the details. Combine -i and -v options. 

$ rm -iv filename(s)

Wrap Up

Now you know how to use rm command to delete files one by one or in bulk. I have also listed options you can use with rm commands. So, you can now start using the rm command.


author

Deepanker Verma is the founder of Nerdy Guides. He is a tech blogger, software developer, and gadget freak. He also runs TheWPGuides, and Techlomedia


Similar Articles

0 Comments

Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2022 Nerdy Guides | Developed By Deepanker