rm is the command to remove files

learn more… | top users | synonyms

26
votes
6answers
9k views

Recovering accidentally deleted files

I accidentally deleted a file from my laptop. I'm using Fedora. Is it possible to recover the file?
48
votes
8answers
11k views

How do I delete a file whose name begins with “-” (hyphen a.k.a. dash or minus)?

How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory: tohru:~ $ ls -l total 8 -rw-r--r-- 1 me ...
38
votes
2answers
16k views

Why can rm remove read-only files?

If I create a file and then change its permissions to 444 (read-only), how come rm can remove it? If I do this: echo test > test.txt chmod 444 test.txt rm test.txt ...rm will ask if I want to ...
14
votes
4answers
4k views

Make `rm` move to trash

Is there a Linux script / application which, instead of deleting files, moves them to a special “trash” location? I’d like this as a replacement for rm (maybe even aliasing the latter; there are pros ...
10
votes
1answer
2k views

What does *~ mean?

At the end of a makefile I saw rm -f *~ *.class I understand the *.class, but what's *~?
28
votes
1answer
2k views

Does 'rm .*' ever delete the parent directory?

The expression .* is expanded by bash to include the current and parent directories: $ ls -la total 2600 drwxrwxrwx 2 terdon terdon 2162688 Sep 10 16:22 . drwxr-xr-x 142 terdon terdon 491520 Sep ...
25
votes
6answers
30k views

Where do files go when the rm command is issued?

Recently I accidentally did rm on a set of files and it got me thinking where exactly these files end up? That is to say, when working with a GUI, deleted files go to the Trash. What's the equivalent ...
4
votes
1answer
2k views

Deleting files by age

Is there a command to delete all the files in a directory that haven't been modified in N days? I need to clean up some old logs.
21
votes
3answers
5k views

How to remove all empty directories in a subtree?

How can I remove all empty directories in a subtree? I used something like find . -type d -exec rmdir {} 2>/dev/null \; but I needs to be run multiple times in order to remove directories ...
17
votes
7answers
14k views

How do I recursively shred an entire directory tree?

I have a directory tree that I would like to shred with the Linux 'shred' utility. Unfortunately, shred has no -R option for recursive shredding. How can I shred an entire directory tree ...
6
votes
1answer
6k views

Cannot delete a file - permission denied - why?

[db2inst1][testing ~/sqllib/db2dump] rm db2diag.log rm: cannot remove `db2diag.log': Permission denied [db2inst1][testing ~/sqllib/db2dump] id uid=1002(db2inst1) gid=107(db2iadm1) ...
25
votes
12answers
34k views

Efficiently delete large directory containing thousands of files

We have an issue with a folder becoming unwieldy with hundreds of thousands of tiny files. There are so many files that performing rm -rf returns an error and instead what we need to do is something ...
17
votes
3answers
8k views

Is there any way to prevent deletion of certain files from user owned directory?

Let's say user has Directory1 and it contains File1 File2 CantBeDeletedFile How to make so the user would never be allowed to delete the CantBeDeletedFile? If I change the ownership of Directory1 and ...
11
votes
6answers
10k views

Deleting all files in a folder except files X, Y, and Z

I have a lot of files and folders in a specific folder and I want to delete all of them; however, I wanted to keep files X, Y, and Z. Is there a way I can do something like: rm * | but NOT grep | X ...
12
votes
7answers
6k views

What's the best way to format a HDD in Linux in order to leave no trace?

I'm running Debian and need a way to format the entire hdd in order to not leave any trace on it because I want to donate it to a friend. So what will be the best way in order to format it? If I ...
10
votes
4answers
16k views

How do I recursively delete directories with wildcard?

I am working through SSH on a WD My Book World Edition. Basically I would like to start at a particular directory level, and recursively remove all sub-directories matching .Apple* - how would I go ...
22
votes
9answers
5k views

How can I delete a file with no name

I somehow managed to create a file that doesn't seem to have a filename. I found some information regarding how to get more details of the file in the following thread. However, I tried some of the ...
5
votes
2answers
29k views

How to recover files I deleted now by running rm *? [duplicate]

By mistake I ran rm * on the current directory where I created many c program files. I had been working on these since morning. Now I can't take out again the time that I spent since morning on ...
6
votes
5answers
891 views

Making a directory protected from 'rm -rf'

I just lost some data in folder A which was inside folder B after doing rm -rf B. Before I could realize what have I done, it was all over. Now a lesson is learnt, I wish to make some of my folder ...
13
votes
2answers
376 views

Can I make `rm` interactive only when using globbing? (in either bash or zsh or both)

Whenever I rm multiple items at once with shell globbing and there's even the slightest possibility that the pattern expands to more than I expect it to, I always try to remember to add -i, but (of ...
7
votes
3answers
4k views

No space on device when removing a file under OpenSolaris

While trying to mount a NFS share (exported from an OpenIndiana server) on a client box, the OI server crashed. I got the black screen of death, what looked like a log dump, then the system restated. ...
5
votes
4answers
623 views

How to forbid the execution of /bin/rm -f *?

I cannot remember how many times I've listed a subdirectory and executed /bin/rm -f * in the current directory. Can anyone give suggestions to help me avoid this? What should I do if I want the system ...
1
vote
2answers
6k views

Delete files in a directory that match a regexp, using a Mac terminal

How do I delete files in a directory that match a given regexp, or a similar solution, using a Mac terminal?
12
votes
1answer
9k views

Unable to delete file, even when running as root

I am in the process of migrating a machine from RHEL 4 to 5. Rather than actually do an upgrade we have created a new VM (both machines are in a cloud) and I am in the process of copying across data ...
5
votes
1answer
3k views

mv file without write permission to the source file

I just realised that I can move a file that I do not own and don't have write permissions on. I have write permissions to the directory, so I am guessing that is why I could move it, but in this ...
5
votes
5answers
505 views

How do I remove a file I accidentally created named $file?

I was working on a shell script and I accidentally created a file with the variable as its name. Now I have $file in my ls output, and cannot remove it. What can I do?
4
votes
2answers
1k views

Why is rm slow?

I have been trying to use rsnapshot for making backups, but I'm finding it unusable. While it is able to diff a directory (50gb) and duplicate it (hardlinking every file) in a few minutes, and I can ...
4
votes
1answer
2k views

deleting a 'file' under /proc or /dev

I am using a cowdancer/debootstrap setup to generate a chroot. Of course, as I iterate, I generate some chroot configurations that are bad. I have found myself in an awkward situation where I have ...
3
votes
3answers
2k views

How to delete 2 months back files in unix

Say I have below log files, AA_XX_20130719185428.log exec_xxx_cpb_20130712182453.log 13122013121327_AR_INC_DOBC_1.dprf.log 24122013_masterscript.LOG Date part contains both date and time. I want ...
3
votes
2answers
3k views

Scripting `rm` and `rm -i`

I want to create a script that whenever there are more than three files being removed, it invokes rm -i by default. I know it will go in initialization files but can't seem to get it working. So far: ...
3
votes
2answers
419 views

Capturing new output after deleting the output file

I'm runnig a java server on Debian with this command: java -jar myapp.jar [args] >> log.txt Once I gzipped the log file to send it and then I realized the original file was gone, leaving me ...
1
vote
2answers
354 views

Free disk space from a JBoss log file which is still being written to

Is there any locking on the content, imposed by the process if at all the process is using the file. We host a JBoss app server on a RHEL 6.4 OS and due to the disk space constraints we have decided ...
1
vote
1answer
408 views

Speeding a find rm command with test through parallelization

I want to recursively delete all files in directories and subdirectories with number of lines less than 10, and am currently using the following command find . -type f -name "*.txt" | while read; do ...
0
votes
4answers
862 views

Configure rm command

I want to configure rm command. When one types rm to delete a file, then instead of deleting it right away, the file has to be transferred to the .trash of home folder. Can someone help me ?