Questions tagged [rm]
Questions relating to the Linux remove command (rm)
284
questions
902
votes
9
answers
1.1m
views
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 ...
451
votes
9
answers
1.9m
views
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...
132
votes
2
answers
468k
views
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?
106
votes
6
answers
985k
views
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 ...
94
votes
8
answers
322k
views
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 ...
92
votes
6
answers
98k
views
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 ...
78
votes
12
answers
237k
views
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 ...
50
votes
7
answers
86k
views
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)?
46
votes
7
answers
249k
views
"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 ...
45
votes
2
answers
47k
views
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 ...
36
votes
5
answers
507k
views
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 ...
35
votes
10
answers
9k
views
Will ls always list the files that rm will remove?
Something I feel I ought to know for sure: if I ls <something>, will rm <something> remove exactly the same files that ls displayed? Are there any circumstances where rm could remove files ...
35
votes
3
answers
45k
views
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 ...
32
votes
5
answers
11k
views
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 ...
30
votes
3
answers
25k
views
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/*, ...
29
votes
10
answers
7k
views
How can I set up a password for the 'rm' command?
My friends keep deleting my files using the terminal. So please help me out by explaining how to make a password for rm command.
25
votes
7
answers
16k
views
Why is it possible to delete the entire file system?
After committing the infamous mistake of deleting my entire file system via sudo rm -rf /*, recovering from the horrendous damage that I had done and coping with the fact that I just lost 6 years off ...
21
votes
4
answers
24k
views
Unable to remove a file which has a name like a command argument [duplicate]
I inadvertently created a file called -r in my home directory. Now I cannot get rid of it:
rm -rf
rm: missing operand
Try 'rm --help' for more information.
Other attempts:
rm /-/r
rm: cannot remove ...
20
votes
8
answers
24k
views
remove file but exclude all files in a list
I need to cleanup a folder periodically.
I get a filelist which contains text, which files are allowed.
Now I have to delete all files which are not in this file.
Example:
dont-delete.txt:
...
20
votes
3
answers
9k
views
Exclude from * in command line
There are plenty of situations where the use of a * is virtually inevitable - e.g. rm -rf * in a folder that holds thousands of subfolders and files.
But what if you want to exclude just one or two ...
17
votes
3
answers
23k
views
How to find the pid of the process which has deleted a file?
I am working on a project related to VM migration. Sometimes the VM image will disappear and I just want to know who the culprit is. I tried strace on suspicious processes but to no avail.
16
votes
3
answers
12k
views
What does [co] mean in the "rm -rf filename[co]" command?
Let's say I have two files in /tmp:
root@ubuntu:~# touch /tmp/hello.{pyc,py}
root@ubuntu:~# ls /tmp/
hello.py hello.pyc
Now, lets run rm -rf command with [co] option
root@ubuntu:~# rm -rf /tmp/...
16
votes
4
answers
57k
views
How can I make rm stop asking me for permission?
On my server rm always asks me for permission (even though I'm root) when I run it, on my desktop it does not. Like so:
$ rm mod_wsgi-3.3.tar.gz
rm: remove regular file `mod_wsgi-3.3.tar.gz'?
How do ...
15
votes
6
answers
34k
views
how to remove files in a list of paths easily?
I have a list of lines like
/usr/lib/i386-linux-gnu/libavfilter.so
/usr/lib/i386-linux-gnu/libavfilter.so.3
/usr/lib/i386-linux-gnu/libavfilter.so.3.42.103
/usr/lib/i386-linux-gnu/i686/cmov/...
14
votes
2
answers
9k
views
How do I repair Ubuntu after running the command: sudo rm /*
While I was trying to remove files from a SD card from the same directory, I ran sudo rm /* and now Ubuntu isn't working.
When I restarted I get the error: kernel panic attempted to kill init.
I'm new ...
14
votes
6
answers
3k
views
Remove all but every 12th file
I have a few thousand files in the format filename.12345.end . I only want to keep every 12th file, so file.00012.end, file.00024.end ... file.99996.end and delete everything else.
The files may ...
14
votes
2
answers
24k
views
Does Ubuntu Server have a Trash?
I'm using the server version of Ubuntu. I was wondering if files still go into the "trash" etc. with this version.
I'm been deleting stuff and I just want to make sure the stuff is not being put into ...
13
votes
2
answers
2k
views
Are there any disadvantages of using rm $(ls) to delete files?
I was wondering if using rm $(ls) to delete files(or rm -r $(ls) to delete directories as well) was safe? Because in all the websites, people give other ways to do this even though this command seems ...
13
votes
3
answers
51k
views
Syntax error near unexpected token `('
When I use below code in Ubuntu terminal, it works fine:
rm !(*.sh) -rf
But if I place the same line code in a shell script (clean.sh) and run the shell script from terminal, it throws an error:
...
13
votes
3
answers
16k
views
rm works on command line but not in script
When I do rm *.old.* on the command line it removes correctly,
but when I do it in the following portion of my script, it does not rm all the *.old.* files.
What is wrong in my bash script:
for ...
12
votes
1
answer
21k
views
How to remove files modified between particular dates?
As in the topic: I would like to remove files in a directory that have been modified in a particular date range. How can I do this ?
12
votes
1
answer
12k
views
rm: cannot remove `/run/user/root/gvfs': Is a directory
Whenever I type a command which is similar to sudo apt-get install or anything like this I get this kind of error:
$ sudo su
# exit
exit
rm: cannot remove `/run/user/root/gvfs': Is a directory
How ...
11
votes
5
answers
13k
views
Pipe results of locate into rm
I tried running
locate *.orig | xargs rm
but it said No such file or directory
I've seen ways to do it with find but locate returns the full path to the object so it should be possible
11
votes
2
answers
2k
views
Excluding certain files and directories when deleting files
My top-level directory is data. data includes several directories and these directories have sub-directories. I need to remove all files and directories inside data/ except several files in some ...
10
votes
2
answers
1k
views
Is quoting filenames enough security for running `xargs sudo rm -rf`?
I wrote a script that deletes all except the last two files in a folder:
#!/bin/bash
ls -1 --quoting-style=shell-always /path/to/some/folder \
| head -n -2 \
| xargs printf -- "'/path/to/some/...
10
votes
1
answer
11k
views
Why is "rm" so much slower than deleting files via the File Manager?
I witnessed that deleting directories (with the size of a couple of gigabytes) which contain many files is very slow when using rm. It takes up to several minutes!
When deleting the same folder via ...
10
votes
3
answers
12k
views
How is rm command different from the delete button?
I read from a book where it says, the command rm deletes the inode and not the file. Which means if I delete with the rm command, then it cannot be restored.
I'm very new to Ubuntu environment. Now ...
9
votes
2
answers
6k
views
How to recover accidentally removed /bin/ls binary
I have mistakenly deleted the ls executable from the /bin folder.
Can I recover it or install it through the terminal?
9
votes
1
answer
2k
views
How to prevent a file under user folder to be deleted?
How can I make some file impossible to be deleted by user even if it is under his/her home folder?
9
votes
5
answers
31k
views
Can't delete/edit files on my pendrive
I'm trying to delete the .Trash-1000 from my pen drive, but with
sudo rm -rf .Trash-1000/
I got
rm: cannot remove `.Trash-1000/expunged/2660089871/apps.log': Read-only file system
(one line of ...
8
votes
2
answers
777
views
Is there a significant disadvantage to aliasing rm to do something else?
I've been bitten a few times recently with rming things I shouldn't have - for example, forgetting to ulink symlinks, not rm them.
I'm thinking of writing a small bash script to simply move the ...
8
votes
4
answers
2k
views
Repairing after running rm -rf /*
I accidentally ran rm -rf /* on my Ubuntu 10.10 and cancelled the command quickly. I was not root and didn't use sudo but a lot of my files were deleted. The system has become less responsive and I am ...
8
votes
1
answer
85k
views
How do I delete / remove a file
I am a beginner with Linux / Ubuntu, and I'm trying to remove / delete a file.
The specific is a wallet I created in Electrum to import a paper wallet; I can see the wallet in the file list but can't ...
8
votes
2
answers
32k
views
Difference between sudo rm -rf and rm -vf?
Recently I have seen one issue with a cache problem. The problem comes with broken hash and that could be fixed with
sudo rm -rf /var/lib/apt/lists/*
and
sudo rm /var/lib/apt/lists/* -vf
But I ...
8
votes
2
answers
16k
views
How to prevent directory from being deleted by user?
Suppose a directory dir1 is created by sudo on Desktop.
sudo mkdir dir1
Then I applied chown and chmod as following:
sudo chown root:root dir1
sudo chmod go-rwx dir1
Now dir1 is only accessible ...
8
votes
2
answers
63k
views
how to restore data after running rm? [duplicate]
I accidently ran sudo rm *
I thought I was in an unimportant subfolder.
The result is that I deleted some very important files.
Is there any way to get my data back?
7
votes
7
answers
10k
views
Is the command `sudo rm /Desktop/filename` safe?
Is this safe to use?
sudo rm /Desktop/FILENAME
The reason for wanting to use sudo is I can't see the file.
I accidentally typed in sudo rm /Desktop/index.html. It didn't find it but could ...
7
votes
4
answers
2k
views
How can I delete a file if it starts with <html> in bash?
I need a bash command to delete the entire file if the file itself begins with <html>.
I'm not sure the best way to go about this...
Context: I download a series of files via curl requests. ...
7
votes
2
answers
3k
views
I have a file named "-t". How to remove it? [duplicate]
Output of "ls -l":
-rw-r--r-- 1 root root 0 Mar 4 08:22 -t
When i try to do "rm '-t'":
rm: invalid option -- 't'
Try 'rm ./-t' to remove the file '-t'.
Try 'rm --help' for more information.
7
votes
2
answers
36k
views
How do I set Cron to send emails? [duplicate]
I have the following cron job command running once daily on my NAS device:
find /nfs/rpiggott/complete -mtime +45 -exec rm {} \;
I am wondering if there is a way to pipe a list that will result in ...