Linux

Linux Commands To Remove Files And Directories

Linux Commands To Remove Files And Directories
Written by itsubuntu

Insight: Linux Commands To Remove Files And Directories

Let’s go through this tutorial to remove files and directories in Linux using command line. During this tutorial, we will use the rm command to remove files and directories. We will guide you with the rm examples.

Linux Commands To Remove Files And Directories

Let’s start this Linux tutorial. You need to have sudo privilege to excute this command:

1. Remove single file.

Run the following command to remove a single file in Linux from command terminal.

rm filename

Meanwhile, If your file is write protected, System will ask you to confirm before executing the remove operation.

2. Remove multiple files at once.

Run the following rm command to remove multiple files at once.

rm file_name1 file_name2 file_name3

Or you can also use a wildcard (*). For example to remove all .mp3 files in the current directory, use the following rm command.

rm *.mp3

3. Remove files even if the files are write-protected.

Run the the following command to remove files even if the files are write protected.  For example, you can remove it with the -f (force) option.

rm -f filename(s)

4. Remove file after confirming.

Run the following command to confirm each file before deleting.

rm -i filename(s)

5. Remove empty directory.

Run the following command in your terminal to remove empty  directory.

rm -d dirname

6. Remove non-empty directories and all the files inside it.

Open your terminal and run the following command.

rm -r dirname

7. To remove multiple directories at once.

Run the following command to remove multiple directories at once.

rm -r dirname1 dirname2 dirname3

 

 

All right, This much for now. You can bookmark this post for your future use as we will regularly update this post with more rm examples.  Meanwhile, Let us know if there is any mistakes or errors in this article.

Summarry: Linux Commands To Remove Files And Directories.



About the author

itsubuntu

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Dear lovely people, Welcome to itsubuntu.com

Join our mailing list to receive the freebies, tutorials, latest news and updates from our team.

You have Successfully Subscribed!