rm command to delete files in linux
The rm command (short for remove) is a Unix / Linux command which is used to delete files from a file system.
Here is few example of rm command
1) To remove a file named test.txt, use the following command.
$ rm test.txt
Here rm test would delete the file named “test” in the current directory. You could also specify a full path to the file: rm /path/to/test would delete the file at /path/to/test on your file system.
2) You can also use the rm command to delete multiple files at one time like the following command.
$ rm file1 file2 file3
If you want to be careful when deleting files, you can use the -i option with the rm command. The ‘-I’ stands for “inquire”, so when you use this option the rm command prompts you with a yes/no prompt before actually deleting your files. For example:
$ rm -i files file2 file3
3) To remove all files & subdirectories from a directory, use the below given command.
$ rm -rf directoryname
4) To delete all TXT files in the current directory, use the following command.
$ rm *.txt
5) To delete all files in the current directory that begin with the string “index”, you can use the command given below.
$ rm index*
This command deletes files named index.php, index.html and in general, any filename that begins with the character string “index”.