This command is used to take away information. It can be used to take away directories when it’s invoked with the
-r possibility. Alternatively, verify the
Common syntax for
$ rm [OPTION...] [FILE...]
Delete a file
rm command removes a single file. To do that, kind
rm adopted by the identify of the file you wish to delete.
Instance: Deleting the instance.txt file positioned within the /ExampleDir listing.
Take away information with out affirmation
rm -f [file]
This selection permits customers to take away write-protected information with out affirmation.
Instance: Let’s delete the write-protected newfile.txt file.
Delete a number of information
rm [file1] [file2] [file3]
rm command with filenames as arguments to take away a number of information without delay.
Instance: Eradicating a number of information new1, new2, new3 positioned within the /NameDir listing.
Show output message
rm -v [filename]
-v (verbose) possibility lets you get details about what’s being eliminated.
Instance: Deleting the instance.txt file and getting details about it.
Immediate for affirmation earlier than deleting a file
rm -i [filename]
This selection is used to request affirmation earlier than deleting a file. Typing
y (sure) confirms, typing
n (no) stops.
Instance: When deleting the identify.txt file, a affirmation message comes up. Enter
y to substantiate deletion.
This command removes listing in addition to information inside the listing. There isn’t vital distinction with the
rm -r command besides that it cannot be used to take away a file.
Common syntax for
$ rmdir [OPTION...] [DIRECTORY...]
Take away a listing
Use this command to take away a listing, however it can solely be eliminated whether it is empty.
Instance: Getting into the
rmdir command adopted by the listing identify ExampleDir to take away it.
Delete a number of directories
rmdir [file1] [file2] [file3]
This command lets you delete a number of directories without delay, however all of them should be empty.
Instance: Deleting all directories new1, new2, and new3 on the similar time.
Take away mother or father directories
rmdir -p [directory-path]
-p possibility removes the required listing and its mother or father directories.
Instance: Eradicating the listing path newdir/dir1. The command removes the newdir listing after deleting the dir1 listing.