In this tutorial, we will learn rm Linux command with examples. This command is used to remove directories or files.
- Ubuntu Linux
- JBoss Application Server directories and files.
rm Linux Command
rm Linux command is used to remove files and directories on the system. The general syntax for the command is:
$ rm <filename>
$ rm <directory name>
$ rm <path to filename/directory to be removed>
The man page for the command can be launched using the following command:
$ man rm
Alice is a DevOps Engineer. She does manual application deployments on the QA server. She wants to clean the Wildfly/JBoss application server files and directories to deploy the next QA build on the server. Look at the examples, of how she uses the rm command for this purpose.
To remove a single file we can use the following command. For example, to remove a server log archive file, we can use the rm command.
$ rm server.log.2016-09-3
The above would remove the server log file. We can notice the output of the ls command before and after the rm command.
rm command is also used to remove the directory and all its contents recursively.
For example, to delete server tmp directory, its subdirectories, and file contents, we can use the following command:
$ rm -rf tmp
The -r or –recursive command-line switch is to denote recursive. This flag removes directories and their contents in a recursive manner. By default, rm doesn’t remove directories. We can use this switch to override this behavior.
The -f or –force command-line switch is to force the remove operation without any prompts to the user.
The rm -rf option is generally used in shell scripts to remove files and directories. Issue this command with caution, as it would delete the entire directory and subdirectories with their contents as well.
Linux Basic Commands Tutorial page:
More Information on Ubuntu Linux: