Questions tagged [rm]
75 questions
182
votes
31 answers
How do I prevent accidental rm -rf /*?
I just ran rm -rf /* accidentally, but I meant rm -rf ./* (notice the star after the slash).
alias rm='rm -i' and --preserve-root by default didn't save me, so are there any automatic safeguards for this?
I wasn't root and cancelled the command…

Valentin Nemcev
- 2,015
- 2
- 14
- 12
123
votes
24 answers
rm on a directory with millions of files
Background: physical server, about two years old, 7200-RPM SATA drives connected to a 3Ware RAID card, ext3 FS mounted noatime and data=ordered, not under crazy load, kernel 2.6.18-92.1.22.el5, uptime 545 days. Directory doesn't contain any…

BMDan
- 7,249
- 2
- 23
- 34
37
votes
5 answers
Could `rm -rf / --no-preserve-root` mess up the bios?
In order to see approximate speeds for tarballing an entire system, and then restoring that system when if it was foobar'd, I partially cloned one of our primary systems onto a workstation that, while not integral to our company systems, would be…

MirroredFate
- 459
- 5
- 9
32
votes
11 answers
How to make `rm` faster on ext3/linux?
I have ext3 filesystem mounted with default options. On it I have some ~ 100GB files.
Removal of any of such files takes long time (8 minutes) and causes a lot of io traffic, which increases load on server.
Is there any way to make the rm not as…
user13185
29
votes
3 answers
Cannot delete folder with rm -rf. Error: device or resource busy
I'm trying to delete /var/www/html but I'm getting this error:
rm: cannot remove `html': Device or resource busy

Hugo
- 291
- 1
- 3
- 3
23
votes
2 answers
Will Ansible prevent the execution of 'rm -rf /' in a shell script
This is based upon this hoax question here. The problem described is having a bash script which contains something to the effect of:
rm -rf {pattern1}/{pattern2}
...which if both patterns include one or more empty elements will expand to at least…

aroth
- 393
- 3
- 9
11
votes
3 answers
Unix magic, delete all .pyc files from a tree of directories?
Is there a quick way of deleting all the .pyc files from a tree of directories?

interstar
- 1,281
- 4
- 18
- 23
10
votes
2 answers
cannot remove file, Device or resource busy
I tried removing a file. The most relevant answer can be found here, but I found no luck. Here is the original problem:
maxgitt@mgpc:~$ sudo rm -rf /var/lib/docker/
rm: cannot remove '/var/lib/docker/aufs': Device or resource busy
To locate the…

Max
- 237
- 2
- 4
- 8
10
votes
3 answers
Is there a way to delete 100GB file on Linux without thrashing IO / load?
I have a huge log file I need to delete on a production web server. I'm worried it'll bring the system to a crawl if I rm it on Linux. Any brilliant ideas?
Update:
Filesystem: ext3
Partition: /var (mostly logs and MySQL data)
Log file is no longer…

objectoriented
- 143
- 1
- 1
- 6
9
votes
10 answers
Best practices to prevent 'rm -rf /' in bash scripts
It's well known fact that extra space in env.variable can lead to deletion of / directory in bash script.
#!/bin/bash
...
rm -rf /$MYPATH
if $MYPATH contains values like " dir" or "dir /" it will lead to "rm -rf / dir" or "rm -rf dir /". And will…

igorp1024
- 228
- 3
- 8
8
votes
3 answers
How to keep subtree removal (`rm -rf`) from starving other processes for Disk I/O?
We have a very large (multi-GB) Nginx cache directory for a busy site, which we occasionally need to clear all at once. I've solved this in the past by moving the cache folder to a new path, making a new cache folder at the old path, and then rm…

David Eyk
- 667
- 1
- 7
- 17
6
votes
3 answers
How to Fix Directory with all Question Marks as Permissions
I'm using CentOS 7 and trying to list a directory's contents but can't. When I try to list the contents, I get the following output:
[entpnerd@myhost ~]$ ls -ali /data/sharedlogs/otherhost/
ls: cannot access /data/sharedlogs/otherhost/vcs: Not a…

entpnerd
- 165
- 1
- 6
6
votes
3 answers
Difficult to Delete Files in Linux
There's a lot of stuff about this on the Internet, but most of the examples there are contrived. How does one delete files that are really stubborn? e.g.,
$ find ./ -inum 167794
./àKÈÿÿÿÿ@
$ find ./ -inum 167794 -exec rm \"{}\" \;
rm: cannot…

mgjk
- 874
- 3
- 9
- 20
6
votes
3 answers
Remove directories in Solaris
I am using Solaris. I have several directories with the following names:
saa_first.data
saa_second.data
saa_third.data
I want to remove these directories along with its content, so I use:
rm -fr saa*
What I get is the following questions:
rm:…

Rosdi
- 239
- 2
- 3
- 11
5
votes
5 answers
How to remove a file where the file name has utf-8 character issues
I want to remove a file from a server via bash rm command.
This is a sample file Test_ Mürz.jgp.
How would one go about removeing files with such chars issues in the filename on a grand scale ... especially when you don't know the position of the…

mahatmanich
- 2,954
- 3
- 22
- 23