“rm” command is used to remove/delete files.
this command can delete more than one file at a time.
“rm” command can also delete the specific file from the directory.
Syntax:
1 | $ rm filename [press enter] |
Example:
Suppose we want to delete a file Mybook01 then the command is as follows:
1 | $ rm Mybook01 [press enter] |
Note: File ones delete can’t be regained.
Delete more than one file at a time: “rm” command can also delete more then one file at a time.
Suppose we want to delete files Mybook01, Mybook02 and Mybook03 than the command is as follows:
1 | $ rm Mybook01 Mybook02 Mybook03 [press enter] |
Above command delete three files (Mybook01, Mybook02 and Mybook03 ) at a time.
Delete all file at a time: “rm” command can also delete all file at a time using *.
1 | $ rm * [press enter] |
Above command delete all files in a directory.
Delete a specific file from a directory:
Suppose we want to delete a file Mybook01 and Mybook02 from Book directory then the command as follows:
1 | $ rm Book/Mybook01 Book/ Mybook02 [press enter] |
Option of “rm” command
Interactive Deletion (i): option –i(interactive) ask and confirms from the user before deleting a file.
Suppose we want to delete two files Myook01 and Mybook02 than interactive deletion option “-i ” ask from the user before delete this files as shown in below command
1 2 3 | $ rm -i Mybook01 Mybook02 [press enter] rm remove Mybook01 (yes/no) ? ? y [ y enter by user] rm remove Mybook01 (yes/no) ? ? n [ n enter by user] |
If we press y then the file will be deleted and if press n then it will leave file undeleted.