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

learn more… | top users | synonyms

171
votes
8answers
8k views

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 ...
77
votes
14answers
31k 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?
76
votes
12answers
39k views

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 ...
52
votes
7answers
33k views

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 ...
37
votes
12answers
86k 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?
28
votes
5answers
937 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 ...
20
votes
3answers
9k views

Does rm -f 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 ...
18
votes
4answers
663 views

Getting rid of a file called “-d” [duplicate]

Possible Duplicates: How do I delete a file named "-p" from bash? How to delete file with this name on linux: -]???????q Removing "-rf" file in Unix I've ...
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 ...
16
votes
4answers
69k views

undo Linux's rm? [duplicate]

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 ...
13
votes
5answers
13k 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?
11
votes
2answers
17k 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 ...
10
votes
4answers
3k views

`alias rm=“rm -i”` considered harmful?

I have read some time ago (can't find the reference) that using such an alias as alias rm="rm -i" was very bad. Is there historical evidence or common sense explanation for that fact? I would ...
10
votes
6answers
10k views

How to delete all but one file in Unix? [duplicate]

Possible Duplicate: How to delete all files in a directory except some? How to delete all but one(or some) file in Unix? Something like rm -rf -ignore myfile.txt *
9
votes
1answer
13k views

ls | grep | rm — How to format this command?

I'm trying to delete a bunch of files in a certain directory (on Mac OS X using Terminal) ls | grep \([1-9]\) | xargs rm should do the trick, but it doesn't. I'm trying to delete any file with a ...
8
votes
1answer
1k views

Remove all files but one with rm

Is there any way to remove all of the files in a directory except for one with a certain filename? For instance, if I had a directory containing the files file1, file2, and dontdelete. Would there be ...
8
votes
3answers
12k 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 ...
7
votes
6answers
3k 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 ...
7
votes
3answers
504 views

How to remove a file with unprintable charaters in Mac OS X Terminal [duplicate]

Possible Duplicate: Removing file with strange characters in filename in OS X I have a folder that has a file who's name is Icons and ends with an additiona unprintable character. I can see ...
6
votes
3answers
6k views

How to delete file with this name on linux: -]???????q

Somehow a file named -]???????q got created on my terminal. I tried rm -f "-]???????q" (in double quotes), but it did not get deleted. (Error:: rm: invalid option -- ]). How do I delete it?
6
votes
6answers
5k views

Saying 'yes to all' using rm -i

Say I wanted to make sure I'm removing the right files first, so I did something like: rm -i * just to make sure that I'm okay with the files that I am removing. So this will ask me for each file. ...
5
votes
3answers
984 views

Why is the dreadful 'rm -rf /' even allowed? [closed]

We all know the destructive power of the following command executed as root: rm -rf / Related questions: How far will you get with a 'rm -rf /' deleting everything: # rm -rf / I fail to ...
5
votes
1answer
452 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 ...
5
votes
1answer
130 views

Explaining the -W flag for rm

What does the -W flag for rm do? According to its man page, the flag attempts to "undelete the named files." And currently, "this option can only be used to recover files covered by whiteouts." What ...
5
votes
1answer
6k views

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 ...
4
votes
3answers
241 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 ...
4
votes
3answers
557 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 ...
4
votes
3answers
6k views

Mac — remove all files with a certain extension from a directory tree [duplicate]

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

Bash to delete a files older than X days

So I have a cron setup to make backups of a folder into a tarball every hour. I would like to add into the shell script that I'm using the ability to have files deleted automagically after about three ...
4
votes
2answers
436 views

Does rm work alphabetically?

I had many files in a folder in which I accidentally ran rm * before interrupting. It looks like files starting with a, b, and c are gone, but I am not sure, as I didn't know the name of all the ...
4
votes
2answers
2k views

Removing files matching a numeric range regular expression

I have a folder which has many files. Some of the data files are labelled 1, 2, 3, ..., 300 I want to remove these data files using the terminal. How do I do this? I want to do something like rm ...
4
votes
4answers
7k views

Command to remove all files and folders recursively including, hidden ones, on MAC OS Terminal?

rm -rf * will remove all files and folders but not hidden ones. rm -rf .* will remove all hidden files and folders, but not those that are not hidden, correct? What command should one type, in order ...
4
votes
1answer
187 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 ...
4
votes
2answers
557 views

Safe substitute for OS X `rm`?

I am used to having rm to alias something safer. I have been using osx-trash, but once I upgrade to Ruby 1.9.2, this stops working. I know about trash-cli from Python, but I would much prefer ...
4
votes
3answers
1k views

Removing file with strange characters in filename in OS X

After a memory error in my program, I am stuck with a file with a strange filename. It's proving quite resistant to all normal methods to remove files with strange names. The filename is: ...
4
votes
1answer
5k views

Deleting files doesn't free space

I've got a disk formatted as ext3, which was filled completely. I'm attempting to free up some space on it by deleting files, but it's not working. I can rm the files, and they don't show up in the ...
4
votes
3answers
616 views

rm on MINGW32, cannot unlink not owner

Similar to rm on cygwin, cannot unlink not owner, but for MINGW32. I tried chmod u+w path but this did not help. user@computer /d $ rm dir -d rm: cannot unlink `dir': Not owner user@computer /d $ ...
3
votes
3answers
6k views

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?
3
votes
4answers
236 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 ...
3
votes
1answer
232 views

rm -r only files?

Is there an way to remove all the files from the current dir (recursively), keeping the directory structure?
3
votes
2answers
168 views

What is the point of UNIX's rmdir?

I'm new to UNIX (MAC OS X bourne shell POSIX), I understand rmdir will only remove an empty directory but under what circumstances would you actually want to use rmdir <directory name> and not ...
3
votes
1answer
757 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 ...
3
votes
2answers
261 views

How to limit CPU and disk usage of rm to allow other programs to remain functional

When deleting a large file, rm seems to be hogging all the available CPU and disk resources so that other program are hanging. Is there a way to limit a programs - specifically a CPU or disk ...
3
votes
2answers
3k views

Remove everything except? [duplicate]

Possible Duplicate: Remove all files but one with rm In unix, to remove zip files in a directory one can simply type rm *.zip How can one remove everything except zip files?
3
votes
1answer
287 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 ...
3
votes
2answers
98 views

Deleting Certain Extension with Bash (quickly)

I have seen other threads about deleting a certain extension in a directory. However, when I try it, it seems to work but takes a long time to go through directories and say "Permission denied" on ...
3
votes
1answer
527 views

When does rm remove open files?

Particularly, I want to know what happens when I rm an open file and don't explicitly kill the process holding the file descriptor to that file. Will the file be removed when the system is shut down?
3
votes
1answer
208 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 ...
3
votes
1answer
932 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 ...
3
votes
1answer
40 views

OS X - DEAAD300 File Can't be seen via Terminal or Deleted

OS X - 10.7.5 I have a file DEAAD300 on a users desktop that I can not delete. EDIT - The file can not be opened either. The icon that shows up looks like an Excel file (The user has Office 2011 ...