rm is used to remove files or directories. It can be used interactively to ask user input while removing multiple files or the contents of a directory.
A great care has to be taken before running rm command. There is no way to recover the files which are removed unless they were backed up on tape.
Use rm <filename> to remove these files.
To remove multiple files with a common keyword.
To remove all these files except City_DETAIL-ALL enter
If the file does not belong to the current user, or if the file does not have write permissions, the
rm command asks you before removing ,i:e
rm: remove City_DETAIL_KOL.lst??.lst
If you do not want to answer to this question to all the files, use –f option to remove forcefully.
rm -f City_DETAIL_???.lst
To remove directories and files use –rf option
/home/jenny$rm -rf FILMS
This will remove all the sub directories of and the directory itself. This command is also same as
cd /; rm –rf home/jenny/FILMS
remember that you cannot remove a directory if it is the path of your working directory or a parent when you are inside its subdirectories.
eg: both of these don’t work.
/home/jenny /FILMS$ rm -rf /home/jenny /FILMS #Does not work
/home/jenny /FILMS/K3g$rm -rf /home/jenny /FILMS #Does not work
To view the files which are being removed when files are removed in bulk.
Suppose you have a file containing the list of files to be removed. then
/home/jenny$ head file_to_remove_list
home/jenny$sed ‘s/^/rm -ef /g’ file_to_remove_list > file_to_remove_list.sh
home/jenny$chmod +x file_to_remove_list.sh
To remove files interactively use -i option.
/home/jenny$ rm -ir FILMS
rm: remove FILMS/ Schindler's List ?y
rm: remove FILMS/ Chinatown? y
rm: remove FILMS/ Taxi Driver?y
rm: remove FILMS/ The Sixth Sense?n
y and n are inputs given by you to remove or not to remove resp.