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

learn more… | top users | synonyms

3
votes
1answer
41 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
38 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
20 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
45 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, ...
0
votes
1answer
38 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 ...
0
votes
1answer
138 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
97 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 ...
3
votes
4answers
219 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 ...
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 ...
4
votes
3answers
196 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 ...
1
vote
1answer
119 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 ...
28
votes
5answers
644 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
198 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
34 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
281 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 ? ...
2
votes
2answers
575 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
43 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
130 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
82 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
92 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 ...
4
votes
1answer
142 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 ...
5
votes
1answer
313 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 ...
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 ...
0
votes
1answer
324 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
82 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
votes
2answers
83 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 ...
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 ...
3
votes
1answer
568 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
1answer
125 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 ...
-4
votes
2answers
827 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 ^^ )
1
vote
1answer
125 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 ...
0
votes
2answers
184 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 ...
3
votes
1answer
179 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
214 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' ...
1
vote
2answers
579 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
1answer
128 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 ...
1
vote
1answer
60 views

Removing all directories in a given path with unix

I have a directory containing lots of files and lots of empty directories. I want to keep the files but remove the directories. How can I achieve this using rm and other standard unix tools?
2
votes
1answer
534 views

Is it possible to remove the root directory?

I noticed in the documentation for rm as obtained by rm --help the following flag: --no-preserve-root do not treat `/' specially What does this mean? Is it actually possible to delete the root ...
0
votes
4answers
376 views

Is there any rm log with removed files?

Is there any way to check what was recently removed with rm command?
1
vote
2answers
77 views

Does RM corrupt when interrupted?

So I may have kind of accidentally rm -r'd ~. Not to worry, I have backups! I did a quick file listing diff to copy across files that were removed, all is good. But... Does GNU rm corrupt files if I ...
2
votes
1answer
513 views

Undeletable file in RedHat Linux

There is a file under my home area that I cannot delete. When I do an ls -al on the directory, the permissions are ?--------- and there is a ? for user, group, size and date columns. When I attempt to ...
3
votes
1answer
38 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 ...
0
votes
2answers
160 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?
-2
votes
3answers
364 views

A file which is not a dir nor a file

This may look like a weird question, but I just got this output for a file (directory?) in my system. This may be a trivial or well-known error, but for me, this file (directory?) called ...
1
vote
1answer
111 views

rm !(myfile) does not work on OS X?

The command works fine on Linux but on OS X Mountain Lion when I'm doing: rm !(myfile) bash complains: bash: !: event not found Is there any way to do it the same on OS X?
67
votes
14answers
21k 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?
0
votes
2answers
265 views

How to delete all files & directories in a directory including hidden ones except .htaccess?

As the question suggests, I have a situation where I have a folder that users can upload weird stuff there. Have a cron job set up to clean this folder every a few hours. It has a .htaccess for ...
7
votes
3answers
384 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 ...