Questions relating to the Linux remove command (rm)
Questions tagged [rm]
287 questions
                    
                    935
                    
            votes
                
                10 answers
            
        How can I recursively delete all files of a specific extension in the current directory?
How do I safely delete all files with a specific extension (e.g. .bak) from current directory and all subfolders using one command-line? Simply, I'm afraid to use rm since I used it wrong once and now I need advice.
         
    
    
        user216038
        
- 9,353
                    482
                    
            votes
                
                9 answers
            
        How to remove all files from a directory?
The closest I've gotten is 
# rm /path/to/directory/*.*
but that doesn't work for files that don't have an extension...
         
    
    
        user784637
        
- 11,465
                    133
                    
            votes
                
                2 answers
            
        Removing files older than 7 days
I write below command to delete all files that are older than 7 days, but it doesn't work:
find /media/bkfolder/ -mtime +7 -name'*.gz' -exec rm {} \;
How can I remove these files?
         
    
    
        Malihe Pakyari
        
- 1,331
                    113
                    
            votes
                
                6 answers
            
        How do I remove a folder?
I am a new user and I am trying to remove a specific folder.  I am using sudo rm /path/, but it is not working.  What is the correct command to use?
It is a file catolog I am attempting to remove but I am geting a message that it is empty. 
         
    
    
        Carl
        
- 1,131
                    96
                    
            votes
                
                8 answers
            
        Can files/directories deleted with rm be restored?
Is it possible to restore files/directories which are deleted from terminal using rm and rm -r?. If a file is deleted from graphical interface, it could be restored from trash, but how do you restore a file if it is removed using the rm utility?.
         
    
    
        user3215
        
- 5,475
                    93
                    
            votes
                
                6 answers
            
        How is 'rm -rf /' able to delete all files in the system?
I haven't tried this command on Ubuntu (for obvious reasons) so I am not sure if Ubuntu will allow its execution. But it's famous for deleting everything. Just out of curiosity, what happens when the kernel and /bin are deleted? How does rm maintain…
         
    
    
        Muye
        
- 1,033
                    82
                    
            votes
                
                12 answers
            
        How to remove all files and subdirectories in a directory WITHOUT deleting the directory in bash?
Is there a command to remove all files and subdirectories in a directory without deleting the directory?
For example if I have directory dontDeleteMe with subdirectories 1, 2, 3 and each subdirectory has a few pictures in it, how can I remove the…
         
    
    
        user784637
        
- 11,465
                    52
                    
            votes
                
                7 answers
            
        Is there any faster way to remove a directory than "rm -rf"?
I have a folder that has many files and "rm -rf" takes a lot of time to complete. Is there any faster way to remove a directory and it's contents (subdirs, etc)?
         
    
    
        Mohammad Moghimi
        
- 2,201
                    47
                    
            votes
                
                7 answers
            
        "No such file or directory" when trying to remove a file, but the file exists?
I am trying to remove a png image that was uploaded to my server via a PHP script. Whenever I try to delete it both through ftp and terminal, I get the error 
No such file or directory
However, when I ls in the dir, the file is listed and it is…
         
    
    
        DevinFrench
        
- 581
                    45
                    
            votes
                
                2 answers
            
        Does using -v (verbose) slow commands down?
In this question: How to remove all files and subdirectories in a directory WITHOUT deleting the directory in bash? it is asked how to delete all file in a folder, and not the folder itself. 
Matts exelent answer includes the use of the -v flag to…
         
    
    
        Eiriks
        
- 585
                    38
                    
            votes
                
                5 answers
            
        rm: cannot remove directory/: Permission denied
I made a directory called "shadi" and set this permission for it
sinoosh@ubuntu:/home$ ls -ld shadi
drwxr-xrwx 2 root root 4096 Jul  1 01:58 shadi
In this situation I have "others" permissions, but why can I not delete it?
sinoosh@ubuntu:/home$ rm…
         
    
    
        Sinoosh
        
- 2,101
                    35
                    
            votes
                
                3 answers
            
        Piping find -name to xargs results in filenames with spaces not being passed to the command
Normally to remove files with spaces in their filename you would have to run:
$ rm "file name"
but if I want to remove multiple files, e.g.:
$ find . -name "*.txt" | xargs rm
This will not delete files with spaces in them.
         
    
    
        Ash
        
- 497
                    35
                    
            votes
                
                10 answers
            
        Will ls always list the files that rm will remove?
Something I feel I ought to know for sure: if I ls , will rm  remove exactly the same files that ls displayed? Are there any circumstances where rm could remove files that ls did not show? (This is in the 18.04 bash)
Edit:…  
         
    
    
        B.Tanner
        
- 2,685
                    32
                    
            votes
                
                5 answers
            
        Removing folder named ~
This is the output of ls -l
ls -l
total 53484
drwxr-xr-x 3 root root     4096 2011-02-10 05:59 ~
-rw-r--r-- 1 root root 54313810 2011-02-13 05:09 jobs.jar
-rw-r--r-- 1 root root   384035 2011-02-15 05:33 jobsLog.out
I can't do rm -rf ~  because…
         
    
    
        theTuxRacer
        
- 16,533
                    30
                    
            votes
                
                3 answers
            
        What is the command to remove all files but not directories?
Let's say I have a directory tree like this:
FOLDER:
    file1
    file2
    file3
    Subfolder1:
        file1
        file2
    Subfolder2:
        file1
        file2
If I used rm -r FOLDER/*, everything in FOLDER would be deleted including…
         
    
    
        PKM
        
- 839