This brief tutorial shows students and new users how to use the rm command on Ubuntu to delete or remove files and folders, including directories.
We previously showed you how to use the rmdir command on Ubuntu. rmdir command is used to delete folders or directories and not files.
The rm command does both.
If you’re a student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners.
Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…
During your introduction, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.…
Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses.
However, when you’re learning to use and understand Ubuntu Linux, you should also learn how to use the command line to terminal. Most Linux users should be able to do some basic command line tasks. This tutorial is going to show you how….
When you’re ready to learn how to use the rm commands, follow the guide below:
About rm command:
The rm command is a command utility use to remove to remove or delete files and directories on Linux systems, including Ubuntu. It’s one of the most common commands that Linux users get to use on a daily basis.
The syntax is the rule and format of how the rm command can be used. These syntax options can be reordered, but a straight format must be followed.,.
Below is an example syntax of how to use the rm command.
rm [OPTION]. [FILE].
The command line options are switches or flags that determined how the commands are executed or controlled. they modify the behavior of the commands. they are separated by spaces and followed after the commands.
Below are some options of the rm command:
|FILE.||Replace FILE.. with the file(s) you want to remove or delete|
|-f, –force||Use the -f or –force to ignore nonexistent files and arguments and never prompt before deletion|
|-i||Use the -i option to prompt before every removal or a file|
|-r, -R, –recursive||Use the -r or -R or –recursive to remove directories and their contents recursively|
|-d, –dir||Use the -d or –dir to remove empty directories|
|–no-preserve-root||Use the –no-preserve-root to not treat ‘/’ specially. By default, the / directory is not removed|
|–help||Display a help message and exit.|
Below are some examples of how to run and use the rm on Ubuntu Linux.
Simply run the rm to invoke it.
If you want to use the rm command to remove a file named Private.txt, you simply run the commands below:
When you run the above command and you have rights to delete from that directory, the command will delete the file defined above. (Private.txt)
If you don’t have permission to delete content from the parent directory (directory the file lives), you won’t be able to. You’ll will get “Operating not permitted” error. This simply means you don’t have rights there to carry out the operation you executed.
Each time you run the rm command to delete an item, you’ll get prompted to confirm that you want to delete the specified file. If you prefer not to be bother or prompted, you use the -f or –force option.
rm -f Private.txt
The -f option tells rm never to prompt the user and to ignore nonexistent files and arguments when running.
To use the rm command to delete one or more empty directories, you use the -d option.
rm -d PrivateDirectory
rm -d behaves exactly as rmdir command wrote about previously.
However, the rm -d command only delete empty directories. If the directories contain files and other directories, the command will fail.
To remove all non-empty directories and all files within them recursively, you run the rm command with the -r option against the directories.
rm -r PrivateDirectories
To force-ably remove non-empty directories and all content in them without being prompted, use the -r and -f option:
rm -rf PrivateDirectories
If you don’t have rights, you may have to use the rm command with sudo.
sudo rm -rf PrivateDirectories
Congratulations! You have learned how to delete or remove content using the rm command on Ubuntu
You may also like the post below: