How to Delete Files and Folers in Linux – Hongkiat

Read Time:1 Minute, 59 Second

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 rmdir command.

Common syntax for rm command:

$ rm [OPTION...] [FILE...]
Delete a file
rm [file]

The 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.

delete file
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 file without confirmation
Delete a number of information
rm [file1] [file2] [file3]

Use the 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.

delete multiple files
Show output message
rm -v [filename]

The -v (verbose) possibility lets you get details about what’s being eliminated.

Instance: Deleting the instance.txt file and getting details about it.

display output message
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.

confirmation before delete


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

$ rmdir [OPTION...] [DIRECTORY...]
Take away a listing
rmdir [file]

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 dir
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.

delete multiple dir
Take away mother or father directories
rmdir -p [directory-path]

The -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.

delete parent directory

Source link

0 %
0 %
0 %
0 %
0 %
0 %

Average Rating

5 Star
4 Star
3 Star
2 Star
1 Star

Leave a Reply

Your email address will not be published.