Untitled Document
rm Command

rm - command deletes one or more files . It operates silently and should be used with caution . By default rm commands removes files , but ued with some special options and operators it removes directories as well .

Example 1 - Basic Example

Run the following rm command ,which will remove user.txt file .

   rm usr.txt      

Example 2 Removing multiple files

Run below rm command to remove three files in single stroke

   rm user.txt sample.txt logs.txt    

Example 3 - Remove all files from directories .

Sometimes during directory clean up operations we need to remove all the files from directory to empty a directory . The * when used by itself , represents all files and we can ten use rm like this .

   rm *   

Example 4 - adding double space to file ( -d ) option

-d option adds double space to a file .

  pr -d emp.csv 

Example 5 - interactive deletion ( -i ) option

The ( -i ) interactive option makes the command ask the user for confirmation before removing each file . A y removes the file , any other response leaves the file undeleted .

  rm -i user.txt logs.txt sample.txt

Example 6 - recursive deletion ( -r or -R ) option , Removing Directory

The -r or -R option , rm won't normally removes directories , but when used with this option , it will . With -r or -R option , rm does the tree walk and removes everything it finds from all directories and its sub-directories .

  rm -r *  

Example 7 - Forcing Removal ( -f ) option

rm prompts for removal if a file is write-protected . The -f option overrides this minor protection and forces removal . When you combine it with the -r option , it could be the most risky thing to do .

  rm -rf * 
Untitled Document