There are certain commands in Linux with which it is possible to manage all the parameters and elements of both the system and the user, one of these is related to the removal of elements in Linux and is the RM command..
rm command parameters
The rm (remove) command is responsible for deleting files and objects in a safe way, let's take into account that by default the rm command does not delete directories, but it is possible to do so using some criteria, these are:
- -f, --force: its task is to discard non-existent files and arguments without prompting for removal.
- -i: prompts us before deleting a file-I: or element.
- -I: raise the question once before deleting more than three files or when deleting recursively.
- --one-file-system: when deleting recursively, it will omit the directories that are in a different file system than the one indicated on the command line.
- -r, -R, --recursive: delete directories and their contents recursively.
- -d, --dir: delete empty directories.
- --h: display the help of the command.
rm command extra options
To take into account, if we want to delete a file whose name starts with a '-', it is possible to use one of the following options:
Now TechnoWikis will explain how to use this command in Linux and in this case we will use Ubuntu.
To stay up to date, remember to subscribe to our YouTube channel!
SUBSCRIBE ON YOUTUBE
How to use the RM command in Linux
Step 1
We open the terminal and list the content with "ls":
Step 2
You can delete an element by running the syntax:
rm (name)
Step 3
Check that it has been deleted with “ls”:
Step 4
Access the desired directory if this is the case and there we list the content with "ls":
step 5
We delete all elements of the same type using the syntax:
rm *.extension
step 6
Check that these elements have indeed been deleted.
step 7
List the content with "ls":
step 8
We delete elements with the same name regardless of their extension:
rm name*
step 9
Check that they have been deleted correctly:
step 10
Validate that it has been deleted:
step 11
It is possible to list all content without specifying extensions:
ls*.??
step 12
To delete an element requesting confirmation we execute the following:
rm -i *
step 13
We confirm whether or not that element is deleted using son as the case may be.
step 14
List the content with "ls":
step 15
To force the deletion we execute:
rm -f (object)
step 16
Validate that it has been deleted.
step 17
We list the current directories with “ls”:
step 18
To delete a directory we execute the syntax:
rm -d (directory)
This will have deleted that directory. We see how the rm command becomes an ally when it comes to deleting files or directories, but the advantage is that it will do it safely according to the criteria that we have established in the execution of the command, but being careful that elements are deleted so as not to remove something important