Linux Command Line (11) Delete Files and Directories



Linux Command Line (11) Delete Files and Directories

Linux Command Line (11)  Delete Files and Directories

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

Comments are closed.