WriteBash - The
rm command is used to delete files or folders in Linux. Using the rm command is quite simple, this article will talk about it. It can be very simple but when used be careful. Why is that? I will say in the next part of the article.
Use the rm command
The rm command structure is as simple as:
rm [OPTION] item ...
This item, you can understand it is a file or a directory, can also be many files or folders.
Normally, when you type rm to delete a file or folder, there will be a confirmation prompt before the deletion. You can use the
-f option to skip asking for confirmation before deleting.
Options are supported
The rm command supports a number of options as image below.
You can type below command to show all the options of rm command:
Usually the two most commonly used options are
-f to ignore the deletion before deleting and use
-r if you want to delete a directory containing content (not an empty directory).
You can see the difference in the example image above. When using the
-f option, the rm command will skip asking you if you are sure to delete the file. And when you want to delete a non-empty directory, you must use the
-r option otherwise it will not be deleted.
Be careful when using the rm command
You know, in Linux, you can use wildcards. With rm as well, you can delete multiple files at the same time through the wildcard. For example when you type the command below:
rm -f *.log
That means you will delete all the files that end in .log in the current directory.
Read more: Move and rename in Linux with mv command.
But if you type wrong, just a space in front of .log then you will have big trouble. As follows:
rm -f [space] *.log
This will delete all the files in the current directory and notify you that there is no .log file at all.
The most dangerous joke. The following command is widely used to make jokes with newcomers to Linux. This command will completely destroy your operating system. Never run that command.
rm -f /*
This tutorial shows you how to use the
rm command, which is quite simple. Besides, you have to be extremely careful when using the rm command because once you delete the data, it will be very difficult to restore as it was before.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.