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

learn more… | top users | synonyms

5
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 ...
1
vote
1answer
20 views

What does rm --preserve-root prevent exactly?

Modern rm by default has the --preserve-root option enabled, but what exactly does this prevent? I understand it will prevent rm -r / (right?) but does it prevent cd / rm * or rm /* for ...
2
votes
1answer
48 views

Is there any difference in power between sudo rm and sudo rm -f?

Simple question, but I'm not sure I got a complete understanding from man rm. To the best of my knowledge the only difference is that adding the -f will plow through files without prompting and ...
1
vote
1answer
1k views

How do I remove someone else's subdirectory from under my directory?

I was sharing files with a coworker on a Linux server, and he added some new files. Now we've moved the files somewhere else, so I'd like to remove the old files. However, when my coworker added his ...
-4
votes
2answers
388 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?
28
votes
10answers
3k views

Prevent user typing accidental space between rm and wildcard

Intention: rm -rf string* Problem: rm -rf string * The first case is a legitimate and common use of rm, a small typo can cause a lot of problems in the second case. Is there a simple way to ...
0
votes
2answers
215 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
2answers
425 views

Deleting a file with question marks in the name (another encoding) in Debian

I have a file with the name like ?????????????????????? ???????????????????????? ??????????.png in my directory. It seems to me that file was created under windows with russian name. I pulled it with ...
0
votes
2answers
706 views

rm a corrupt file

I am trying to remove a file using rm. However, if I do ls, all the information about the file is ?????? ?? ?? example.txt... And calling rm returns that no such file exists. How can I force a remove ...
8
votes
6answers
4k 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 ...
5
votes
2answers
9k 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 ...
84
votes
16answers
50k 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?
1
vote
1answer
31 views

Deleting unpacked tar.gz files after unpacking incorrectly

I recently unpacked a set of backup files in RHEL3 - 2.4kernel with tar via: tar -xvf backupfile It started to error out a bunch and I aborted thinking that maybe it was a gzip instead. Unpacking ...
0
votes
1answer
100 views

Filesystem device on a VPS

I did some bullcrap on my VPS and accidentaly deleted wrong files. Now I want to recover them with extundelete but I can't seem to find the filesystem device on my VPS. I tried ls -la /dev | grep ^b ...
2
votes
4answers
1k views

Mac keyboard shortcut to rm file [duplicate]

Possible Duplicate: Permanently deleting files on Mac OS What's the Mac keyboard shortcut to rm a file? I know command + delete sends it to trash, but I want to permanently delete it, say ...
1
vote
1answer
90 views

rm'd dirs in Users/home/ reappear in OSX [duplicate]

Possible Duplicate: Stop Mac OS from re-creating ~/Pictures, ~/Music, or ~/Public Hi, I su'd to root and deleted some stock directories in my home folder such as Documents, Music, Pictures ...
42
votes
12answers
101k 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?
1
vote
0answers
469 views

Ubuntu: How to get my data back after sudo rm -r *? [duplicate]

Given an user made a clean and successfull: sudo rm -r * #erase all folders and files recursively starting from root How to get all the hard drive's data back ?
3
votes
2answers
594 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?
0
votes
0answers
89 views

Bypass the $Recycle Bin in CygWin?

I'm using a CygWin session to find a large number of directories at a certain level in the file system tree in a loop, compress each directory into 1 archive, then delete the directory This ...
0
votes
2answers
2k views

How can I remove a directory with rm - rf?

I try to remove a folder with rm -rf foldername … but it says rm: cannot remove folder :is a directory. What's wrong?
0
votes
1answer
108 views

How to remove files that start with 2011XXXX

I have a bunch of files i need to delete, they all start with 2011XXXX. How would i delete them. So far i have this command: ls | grep 2011 | xargs rm And it works, but is there a better way to ...
0
votes
0answers
49 views

rm -rf * results in “Killed”

I used PHP to generate about 4,000,000 files in a directory (f/) because I was bored. When I cd .. and use rm -rf f, it simply returns "Killed" about half a second later and does not delete the ...
0
votes
2answers
91 views

Why does `rm -rf`` silently fail?

[EDIT] Please don't waste your time reading my question below. It turns out my colleague is an idiot.. :) On my server I'm trying to remove a folder and all its subfolders with the usual rm -rf ...
0
votes
0answers
389 views

How to delete *.vmdk files?

I can't seem to delete *.vmdk files and related on Mac OS X 10.6.8 with sudo rm: $ sudo rm -rf /Volumes/Temp/vm/ rm: /Volumes/Temp/vm//MarukoVM/nvram: Read-only file system rm: ...
2
votes
1answer
209 views

What command sequence can I use to delete directories but not their files?

How do I delete directories but not the files inside them? I have tried the following: rm -di /Users/arthur/Desktop/MyFolder remove /Users/arthur/Desktop/MyFolder? y rm: ...
0
votes
1answer
44 views

How much dangerous rm -rf is?

Does rm -rf dir/ erase filesystems mounted below dir/ (say in dir/a)?
2
votes
1answer
1k 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 ...
1
vote
2answers
2k 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: ...
0
votes
2answers
508 views

Removing Hidden Files in folder

I am having some trouble removing a particular folder on my harddrive. I have tried the conventional approach of rm -rf req (where req is the filename) however this failed. running ls ...
3
votes
2answers
195 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
3answers
7k 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 ...
4
votes
1answer
515 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
44 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 ...
10
votes
6answers
11k 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 *
1
vote
1answer
289 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 ...
1
vote
2answers
135 views

unable to remove file and directory

i'm trying to remove directory from my external hard drive that i mounted to the file system i'm using the rm -r command but i got the the strange error : rm: cannot remove `Lundu ...
1
vote
1answer
217 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 ...
17
votes
3answers
84k 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 ...
0
votes
1answer
165 views

Permission denied on sudo remove

I have two users userA and userB. userA has permission over a file named cache. I want to give permission to userB to remove the file. I have made following entry in /etc/sudoers file : userB ...
4
votes
2answers
609 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 ...
1
vote
1answer
131 views

Unable to delete a file using bash script

I'm having problems removing a file in a bash script. I saw the other post with the same problem but none of those solutions solved my problem. The bash script is an OP5 surveillance check and it ...
0
votes
2answers
230 views

Is it better to check if file exists before deleting it

Sometimes when I want to delete a file (from within a script), I will just delete it rather than checking if it exists first. So I do this: $ rm "temp.txt" 2>/dev/null Instead of this: [ -f ...
1
vote
1answer
60 views

Using Bash, how can i delete all the dektop.ini in my external drive folder tree?

I am using my external HDD to store my music, and now I've installed linux on my pc. I would like to erase all the desktop.ini files in the thousand nested folders on the HDD, how can I accomplish ...
0
votes
1answer
41 views

Recovering a file in Linux

I securely deleted a file in Linux by: 1) First encrypting it with AES (cipher block chaining) 2) Then using srm which does 38 passes (as explained in man srm) Any pointers on how to recover it?
0
votes
2answers
71 views

How to `rm` files in current directory and directories inside current directory

I would like to rm all files that end in ~ in both my current directory and all directories inside my current directory. I was under the impression that the flag -r or -R would do this; however, the ...
1
vote
1answer
161 views

Removing multiple files from directory, as specified by variable in Makefile

I have a Makefile with the following configured for installing man pages MANDIR = /usr/share/man/man1 MANPAGES = exec1.1 exec2.1 make install triggers the following: install: $(MANPAGES) ...
3
votes
1answer
679 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
1k 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
44 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 ...