+3 votes
2 views
RM Linux Command | Examples Parameters

ago in Linux/Unix by (515k points)
reopened ago | 2 views

1 Answer

+4 votes
Best answer

How to use the RM command in Linux

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:

 

  • rm -- -name
  • rm ./-name

 

 

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":

 

 

image

 

Step 2

You can delete an element by running the syntax:
 rm (name) 
Step 3

Check that it has been deleted with “ls”:

 

 

image

 

Step 4

Access the desired directory if this is the case and there we list the content with "ls":

 

 

image

 

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.

 

 

image

 

step 7

List the content with "ls":

 

image

 

step 8

We delete elements with the same name regardless of their extension:
 rm name* 
step 9

Check that they have been deleted correctly:

 

 

image

 

step 10

Validate that it has been deleted:

 

image

 

step 11

It is possible to list all content without specifying extensions:
 ls*.?? 
image

 

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.

 

 

image

 

step 14

List the content with "ls":

 

image

 

step 15

To force the deletion we execute:
 rm -f (object) 
step 16

Validate that it has been deleted.

 

 

image

 

step 17

We list the current directories with “ls”:

 

image

 

step 18

To delete a directory we execute the syntax:
 rm -d (directory) 
image

 

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

 

 


ago by (3.2m points)
edited ago

Related questions

+5 votes
1 answer
asked Nov 2, 2022 in Linux/Unix by backtothefuture (515k points) | 10 views
+4 votes
1 answer
asked Sep 22, 2020 in Linux / Unix by backtothefuture (515k points) | 250 views
+5 votes
1 answer
asked Feb 22, 2020 in Linux / Unix by backtothefuture (515k points) | 268 views
+5 votes
1 answer
asked Feb 21, 2020 in Linux / Unix by backtothefuture (515k points) | 231 views
+4 votes
1 answer
asked Feb 18, 2020 in Linux / Unix by backtothefuture (515k points) | 227 views
Sponsored articles cost $40 per post. You can contact us via Feedback
9,914 questions
10,035 answers
498 comments
3 users