rm is the Linux Posix command to remove and delete files or directories.

learn more… | top users | synonyms

3
votes
0answers
15 views

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 ...
2
votes
2answers
32 views

UNIX command for deleting / removing files on today's date

I want to remove all the files in the directory I am in currently in that were created today. So if today is April 3rd then the UNIX commond I am asking for would remove someFile2, someFile3, ...
0
votes
1answer
19 views

command to delete all files with numbers

How can I delete nay file that has a number in its name from directory /www/ and up? Like, it would delete a1.php a2.php 123213.php asdasd5.php Would this work? ls | grep \([1-9]\) -f | xargs rm ...
1
vote
2answers
43 views

How can I delete this non-existant directory in Linux?

A few weeks ago I mapped/browsed (can't remember) to a network share on my local network. It worked fine at that point. I haven't used the machine since then, until today. As you can see below, ...
9
votes
2answers
14k views

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 ...
0
votes
1answer
34 views

Stop deletion of files in Linux

I'm looking for a way to stop accidental deletion of some important files in Linux, but with a couple of criteria. The file has to remain writable (so it can of course still be replaced with rubbish ...
67
votes
14answers
20k views

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?
3
votes
1answer
614 views

restore /dev after `rm`ing it

during a gentoo install from the livedvd, there's one step to create a dev dir to be used later in the chroot of the target for the instalation it's done like that mount --rbind /dev /mnt/gentoo/dev ...
0
votes
1answer
129 views

I accidentally deleted the home directory on my Amazon Linux EC2. My whole site disappeared. What now?

I was using sudo rm -rf to delete some folders, and accidentally deleted the /Users/ec2-user home directory. I had my EC2 and AWS Route 53 running my site. Now, it just disappeared. I have all the ...
1
vote
1answer
94 views

Use rmdir to delete lots of empty folders within a folder

I have a folder which should at any time have less than 500k folders. These folders are created dynamically, and when the files (images) inside them are deleted by some script, the folder itself ...
4
votes
3answers
193 views

How to remove a file with name starting with “-r” using cli [duplicate]

I have been creating odd-named files every once in a while, e.g. $ls -rthl $-rw-r--r-- 1 shamil hep 290 Aug 13 11:58 -rf And interestingly it is impossible to remove this file with rm -f -rf I ...
3
votes
4answers
218 views

Remove all *.foo in directory tree

How do I remove all *.foo in a directory tree? rm -r *.foo does not work. I could try a loop, but that needs recursive expansion: for x in */*/.../*.foo do rm $x done Which is not possible ...
35
votes
10answers
68k views

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?
0
votes
0answers
24 views

Fast removal of millions of files on a remote compute cluster [duplicate]

I would like to know what's the fastest way to remove massive number of files on a remote compute cluster (linux). I have 1000 folders to delete permanently - each containing about 200k files with ...
1
vote
1answer
117 views

Why is `rm` seemingly ignoring escapes?

I'm trying to rm a directory and its contents, however for whatever reason rm is ignoring escape characters. In this example, I'm trying to remove the folder Team Fortress 2 from ...
7
votes
6answers
2k views

Best practices to alias the rm command and make it safer

Some time ago I erroneously deleted my home folder because I ran a rm -rf * on the wrong terminal, whose working directory was the home folder! I wish I had an alias for the rm command, but it was ...
28
votes
5answers
629 views

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 ...
3
votes
1answer
193 views

What if “rm -rf” does not work, but “ls -a” shows no files?

I have a folder foo in an encfs container (source: /local/home/me/Documents mountpoint: /u/me/Documents) which I cannot delete. > pwd /u/me/Documents > mount [..] encfs on ...
0
votes
1answer
33 views

How can I know what subfolders rm -rf attempted to delete first?

I mistakenly run rm -rf on a wrong folder and than cancel the operation after two seconds. The folder is quite big with many subfolders and maybe 1% was deleted. How can I know what subfolders rm ...
1
vote
1answer
279 views

Fastest way to delete a non empty directory in Linux

I use the command rm -rf directory but i came across the following article : Article That suggests that rsynch to an empty folder is the fastest way? rsync -a –delete empty/ a Why is this the case ? ...
-4
votes
2answers
808 views

“rm -rf /” VS. “mv -r / /dev/null”

Might be a stupid question, but what would be the worst for your system ? (I think both) But to my opinion mv would be the fastest to "delete" it all. Am I wrong ? (don't wana test aniway ^^ )
2
votes
2answers
554 views

rm command: remove files with file names containing brackets

I am trying to remove all files in a Windows 7 directory with filenames containing brackets; ( and ): Using MinGW: rm *(*)* I get an error: sh: syntax error near unexpected token '(' I assume ...
2
votes
1answer
42 views

How can rm -rf be slower than delete in nautilus?

I had this very surprising situation recently, while trying to delete folders containing many files (think code repo checkout with some 10 thousands files): When I tried to do this via command line ...
2
votes
1answer
126 views

Delete all file except some in bash, without cd to the directory?

I need to make a daily cleanup in a download directory. I have saw this question and tested the answer rm !("test 1"|"test 4") It work great, but require to have cd to the directory before. Since ...
0
votes
2answers
81 views

Need to delete a file I accidentally labeled in quotes in Linux [duplicate]

I have a file which I wrote and not thinking put the actual filename in single quotes like this: 'filename' When I try to remove it using rm -f 'filename' it does not recognize that it is there I ...
1
vote
0answers
91 views

Slow directory removal (rm -rf) on Max OS X

Can anyone help me diagnose why removing a directory would be so slow on my Mac? $ du -hs mydir/ 606M mydir/ $ find mydir/ -type f -print | wc -l 12720 $ date Tue Sep 10 10:59:27 PDT 2013 $ rm ...
5
votes
1answer
309 views

How to delete the contents of a USB Stick in Linux

I'm not looking to format the stick at all, but rather to iterate through the files deleting them all (though after typing 'iterate through' I can sense a Python script coming along. So far I've ...
4
votes
1answer
140 views

How can I remove all files from a directory that have a certain filename length?

I have a tmp directory full of various files that a program has created and not cleaned up properly. Each of these files has a filename that's simply 6 random characters. In addition to these, there ...
0
votes
2answers
90 views

`sudo rm -rf /` got interrupted leaving the data partially deleted

I ran sudo rm -rf / to wipe out all data, for some reason the execution got interrupted. Now I am left with a shell that only has cd command!!! (ls, sudo, rm, etc got deleted!) What should I do to ...
16
votes
3answers
1k views

How can I remove a file or directory called “\”?

I'm using terminal on a Ubuntu machine and there is a file that I would like to delete. The file's name is \ (just a backslash). Now usually I would just do rm filename However if I do rm \ then ...
0
votes
1answer
322 views

rm -rf does not delete folder contents but instead creates another empty one

I'm currently writing a start script for a minecraft game server. In this script I included a backup script. This backup script works almost perfect but instead of deleting a folders contents it just ...
-1
votes
1answer
172 views

Preventing execution of sudo rm -rf /*

Do any Linux distros prevent the execution of sudo rm -rf /* so that people do not accidentally delete their hard drives if they did not know what they are doing?
1
vote
1answer
77 views

Use 'find' to find and delete large files of a certain type

I am trying to find and rm -rf large files in RHEL, but what I would expect from this command that would give me purely the file directories, feeding them into rm -rf, it is not removing them. My FU ...
1
vote
2answers
759 views

How can delete all files except one from a directory?

I need to delete all files, except one (its name is defined), from a given directory. How can I do this from the terminal in OS X? Can I do this with one single command?
-1
votes
2answers
82 views

Behaviour of “rm -r”

Up until now I was using Ubuntu, and the behaviour of rm for directories was the following: rm -r dir would remove dir if it was empty, and give an error otherwise rm -rf dir would remove dir and ...
3
votes
1answer
552 views

How do I remove a possible hard-link directory to root?

I know hard links to directories aren't supposed to be possible but it I have something odd on my NAS that looks very much like one. This folder originally came from a linux machine and appears to ...
0
votes
4answers
367 views

Is there any rm log with removed files?

Is there any way to check what was recently removed with rm command?
0
votes
1answer
123 views

Does interrupting rm command with keyboard delete any file?

I'm running Fedora 13 (Goddard) and when I was recursively removing a directory I noticed I had some files there I couldn't lose, so I interrupted the process with ctrl+c. Now I don't know if I lost ...
1
vote
1answer
123 views

Avoiding accidental 'rm' disasters

Today, using sudo -s, I wanted to rm -R ./lib/, but I actually rm -R /lib/. I had to reinstall my OS (Mint 15) and re-download and re-configure all my packages. Not fun. How can I avoid similar ...
10
votes
5answers
12k views

use rm to remove files and directories recursively

is it possible to use rm to remove files and directories matching a pattern recursively without using other commands?
1
vote
4answers
1k views

Where do files and directories go when I run 'rm -rf folder_or_file_name' in Ubuntu 10.04?

When I delete folders or files in the Nautilus GUI, those folders/files go to Trash but where do folders/files go when I run rm -rf folder_or_file_name in terminal in Ubuntu 10.04?
0
votes
2answers
181 views

Accidentally “rm -rf /” in OS X [closed]

Some background to maybe help others from making this mistake. I was reading jokes from this Stack Overflow page to my friend ...
1
vote
2answers
4k views

OS X Lion: Emptying the trash takes “forever”: is using rm -r safe?

Emptying my Trash in OS X Lion (non securely) is taking about three hours (about 1.5 million files, from a Time Machine backup). I had to stop the process a few times already, because I could not move ...
3
votes
1answer
177 views

rm -r only files?

Is there an way to remove all the files from the current dir (recursively), keeping the directory structure?
2
votes
1answer
213 views

Removing a directory containing a file using find

I'm searching a list of directories for certain files and I want to delete the directory that the file is in. This is what I'm trying: find /converter/storage/unmatched/ -size -4b -name '*.mp3' ...
7
votes
3answers
9k views

Can files deleted with rm -rf be recovered?

When I delete folders or files in through osx terminal using the rm -rf, where do they go? I heard that some say they are deleted directly, but some also say it only "remove the link to the file ...
1
vote
2answers
567 views

Delete directory and subdirectory - Operation not permitted

There is a folder called Trash-1000 and i want to delete it. There are some folders in it which cannot be deleted (do not even know how they were created). Looks like: ...
4
votes
3answers
544 views

I just ran rm /* accidentally, any fix?

I fell so stupid... I just ran rm /* accidentally, but I meant rm ./* on a cloud server with root access. Now, no one command works. ls, ssh, sftp... none. Is there a way to fix that? (Note: params ...
0
votes
2answers
159 views

How can I recover from mistaken 'rm *'?

I just typed rm * in the wrong directory by mistake. I had the wrong terminal window highlighted. What are my options?
0
votes
1answer
127 views

How can I prevent bash from executing 'rm' when ' * ' is one of the arguments?

I wish to insure myself from accidentally using rm [argument_i] * [argument_j] i.e. it should always refuse to execute the command, when the asterisk character is separated by white space on both ...