Delete a File Using Linux Command Line

This is the directory containing the file 'test1.txt' which we want to delete.

ls After mkdir Command

We will use the Linux command rm (remove) to erase the file. Enter the following.

rm test1.txt

Replace 'test1.txt' with the name of the file you want to delete.

rm Command

To erase multiple files place them in a line with a space between each filename. e.g. rm test1.txt test2.txt

You can also use the * wildcard. The command rm *.txt will delete all files in the current directory that end with .txt

Use rm -i filename(s) to individually confirm each file to delete.

Other options include: -

-v Verbose mode

-f Force a deletion even if a file is write protected.