The rm
command in Linux comes with the GNU Core-utilities package and deletes one or multiple files and folders.
The GNU Core-utilities is available for all Unix-like operating systems.
The rm
command supports many functionalities. Users can select a functionality of their choice by setting the right flags or arguments. In this shot, we go through the most frequently used arguments for rm
.
The rm
command is used without any additional flags to remove one or multiple files. To remove multiple files, the file names are sent as arguments together.
The rm
command can recursively delete an entire folder, provided that the -r
flag has been set. To remove multiple folders, folder names are sent as arguments together. The -r
flag can also remove files.
The -i
flag makes sure that rm
asks the user for confirmation before deleting a file or folder.
The -v
flag stands for verbose and ensures that rm
generates a detailed report of the deleted file.
The -f
flag is used to delete a file for which the user does not write permissions.
To delete all files whose names contain the word file, the special character *
may be used.
In the example below, we create two files using the touch
command and one folder using the mkdir
command.
Subsequently, we use the -r
flag to permanently delete the folder and the rm
command without any flags to delete one of the files.
To delete the second file, we use the rm
with the -i
flag, which ensures that the user is asked for confirmation before deletion occurs.
The user will have to enter
Y
, which stands for yes, for deletion to occur. Alternately, the user can inputN
, which stands for no, to interrupt the operation.
Free Resources