rm is the POSIX command to remove and delete files or directories.
Questions tagged [rm]
262 questions
                    
                    568
                    
            votes
                
                14 answers
            
        How do I make rm not give an error if a file doesn't exist?
I'm writing a makefile that will clean up some useless files at the end of the compilation.  If a target has already been made, it will of course skip that target and the useless file may not be there.  So if I do this:
rm lexer.ml interpparse.ml…
        
        Jason Baker
        
- 8,932
 
                    203
                    
            votes
                
                9 answers
            
        How far will you get with an 'rm -rf /' command?
I've often wondered how far the system will actually get if you run rm -rf /. I doubt the OS would be able to erase itself (?)
Bonus Question: After the command has been executed, will rm have removed itself?
Update:
I've tested this in a couple of…
        
        nopcorn
        
- 16,982
 
                    132
                    
            votes
                
                17 answers
            
        How to delete all files in a directory except some?
I need to delete all files in a directory, but exclude some of them. For example, in a directory with the files a b c ... z, I need to delete all except for u and p. Is there an easy way to do this?
        
        Ashot
        
- 1,469
 
                    120
                    
            votes
                
                11 answers
            
        Undo an "rm -rf ~" command?
I had a folder I didn't want named '~', so from the command line I typed
rm -rf ~
and accidentally deleted my home folder (since ~ resolved to /home/username). Is there any way back or do I basically need to recreate the account from scratch?
        
        Chris
        
- 1,869
 
                    101
                    
            votes
                
                3 answers
            
        Does rm -rf follow symbolic links?
I have a directory like this:
$ ls -l
total 899166
drwxr-xr-x 12 me scicomp       324 Jan 24 13:47 data
-rw-r--r--  1 me scicomp     84188 Jan 24 13:47 lod-thin-1.000000-0.010000-0.030000.rda
drwxr-xr-x  2 me scicomp       808 Jan 24 13:47…
        
        Greg
        
- 1,199
 
                    98
                    
            votes
                
                6 answers
            
        Delete files with regular expression
I Tried to delete files that starts with A and ends with 2 numbers but It doesn't do a thing.
What I tried:  
rm ^A*[0..9]2$
Where am I wrong?
        
        gdoron
        
- 1,100
 
                    72
                    
            votes
                
                15 answers
            
        How to recover a removed file under Linux?
By accident, I used rm on a file I didn't want to delete. Is there a way that I can get it back under Linux?
        
        HaiYuan Zhang
        
- 4,197
 
                    68
                    
            votes
                
                12 answers
            
        What command do I need to use to remove a file called `-rf`?
I did something crazy at some point that created a file called -rf on my filesystem.
Now I can't figure out how to delete it...
I've tried: 
rm "-rf"
rm \-rf
These just exit immediately, arrgh!
Anyone know how to remove this file? Preferably…
        
        Pierre-Antoine LaFayette
        
- 1,127
 
                    67
                    
            votes
                
                14 answers
            
        Trying to delete directory with "rm -rf", but get message that it's not empty
I've tried deleting a directory using "rm -rf" and I'm getting the message "Directory not empty":
Bens-MacBook-Pro:please benjaminhocking$ ls -lart empty_directory/
total 16
drwxr-xr-x  5 benjaminhocking  staff  170 Aug 27 14:46 .
drwxr-xr-x  3…
        
        Ben Hocking
        
- 816
 
                    46
                    
            votes
                
                3 answers
            
        Is there a scenario where rm -rf --no-preserve-root is needed?
I've seen some questions on here where people accidentally do rm -rf --no-preserve-root or rm -rf *, wiping out most or all of their file system before they can react.
Is there ever a reason to use --no-preserve-root, whether in normal use, as a…
        
        Nzall
        
- 3,056
 - 7
 - 39
 - 50
 
                    42
                    
            votes
                
                5 answers
            
        Linux – cannot remove owned file with 777 permissions
I've couple of files that I cannot remove using rf -Rf command. I'm the owner of those file and the group assigned to those files is also a group my user is in. What's even weirder is that I can edit their content and I can change the permissions…
        
        RaYell
        
- 1,164
 
                    38
                    
            votes
                
                5 answers
            
        Deleting millions of files
I had a dir fill up with millions of gif images. Too many for rm command.
I have been trying the find command like this: 
find . -name "*.gif" -print0 | xargs -0 rm
Problem is, it bogs down my machine really bad, and causes time outs for customers…
        
        Corepuncher
        
- 481
 
                    37
                    
            votes
                
                3 answers
            
        Mac -- remove all files with a certain extension from a directory tree
Possible Duplicate:
Delete files recursively matching a name on the command line (OS X) 
I want to remove all files with extension .orig from my tree.  The tree is deep.  Is there an easy way to do that?
I will probably have to do this many times…
        
        William Jockusch
        
- 5,123
 
                    35
                    
            votes
                
                3 answers
            
        undo Linux's rm?
Possible Duplicate:
UNDO  LINUX  Trash Command 
Hi,
Is there any simple way to undo an rm command?
The question is purely theoretical; I have NEVER deleted the log of a benchmark queue who took a whole lunchtime to run.
        
        Adam Matan
        
- 8,740
 
                    28
                    
            votes
                
                11 answers
            
        Prevent user typing accidental space between rm and wildcard
Intention:
rm -rf string*
Problem:
rm -rf string *
The first case is a legitimate and common use of rm, a small typo can cause a lot of problems in the second case. Is there a simple way to smartly protect against an accidental trailing or leading…
        
        bobdole
        
- 291