Linux Command Line (11) Delete Files and Directories

Rate this post

To delete a file, we use the remove command which is rm and then we type the filename we want to remove
rm errorfile.txt

We can also use the -v for verbose and the -i for interactive(Ask before deleting the file) options when removing a file
rm -vi errorfile-copy.txt

There is no trash file, so once a file is deleted, it is gone

An empty directory can be removed with the command rmdir
rmdir Emptydirectory

We add some files into a directory with the command:
Touch Newdirecotry2/file{1..5}.txt

This will create empty files file1.txt, file2.txt. file3.txt, file4.txt, and file5.txt

The rm command will remove a directory that is not empty but we need to add the -r (for remove recursively)
rm -r Newdirectory2

Adding the lower case -i option will require you to confirm deleting every file in that directory
Adding the upper case -I option will only require you to confirm once for the entire directory and everything in it

Tag: xóa thư mục linux, Linux, tutorial, remove, rm, delete, file, directory, Bash, ubuntu, command line

Xem thêm:



  1. Even though it's basic stuff, you present it very well and usually show me something I still didn't know. You have a great style of delivery making things very clear. Thank you for your videos. They are very well presented.


Leave a Reply

Your email address will not be published. Required fields are marked *