Questions tagged [rm]

rm is the command to remove files

rm is the command to remove files. Use this tag for questions about the rm command, or more generally about removing files.

Further information

834 questions
483
votes
10 answers

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 staff 1352 Aug 18 14:33 --help ... How in the…
Astra
  • 4,933
  • 2
  • 16
  • 6
287
votes
2 answers

Recursively delete all files with a given extension

I want to delete all *.o files in a directory and its sub-directories. However, I get an error: sashoalm@aspire:~/.Workspace.OLD$ rm -r *.o rm: cannot remove `*.o': No such file or directory On the other hand, rm *.o works, but it's not recursive.
sashoalm
  • 5,760
  • 11
  • 32
  • 47
281
votes
24 answers

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 like: find /path/to/folder -name "filenamestart*"…
Toby
  • 3,973
  • 4
  • 20
  • 16
276
votes
2 answers

how can I recursively delete empty directories in my home directory?

Possible Duplicate: How to remove all empty directories in a subtree? I create directories very often, scattered over my home directory, and I find it very hard to locate and delete them. I want any alias/function/script to find/locate and delete…
Santosh Kumar
  • 3,753
  • 6
  • 28
  • 36
239
votes
9 answers

How to delete directories based on `find` output?

I issue the following command to find the .svn directories: find . -name ".svn" That gives me the following results: ./toto/.svn ./toto/titi/.svn ./toto/tata/.svn How could I process all these lines with rm -fr in order to delete the directories…
Arnaud
  • 2,501
  • 2
  • 12
  • 8
224
votes
3 answers

How do I remove a directory and all its contents?

In bash all I know is that rmdir directoryname will remove the directory but only if it's empty. Is there a way to force remove subdirectories?
Piper
  • 2,535
  • 2
  • 19
  • 15
220
votes
4 answers

Delete files older than X days +

I have found the command to delete files older than 5 days in a folder find /path/to/files* -mtime +5 -exec rm {} \; But how do I also do this for subdirectories in that folder?
Teddy77
  • 2,883
  • 7
  • 23
  • 34
213
votes
8 answers

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 containing empty directories only. Moreover, it's quite…
maaartinus
  • 4,979
  • 7
  • 30
  • 29
175
votes
5 answers

I deleted /bin/rm. How do I recover it?

Just for fun, I thought I would use this command on my Raspberry Pi running Raspbian: sudo rm -f /bin/rm I thought I could just reinstall coreutils: I was wrong! apt-get install --reinstall coreutils gives an error from dpkg, saying it couldn't…
user60684
  • 1,753
  • 2
  • 12
  • 18
152
votes
14 answers

rm -rf all files and all hidden files without . & .. error

rm -rf /some/path/* deletes all non-hidden files in that dir (and subdirs). rm -rf /some/path/.* deletes all hidden files in that dir (but not subdirs) and also gives the following error/warning: rm: cannot remove directory: `/some/dir/.' rm: cannot…
Jake Wilson
  • 1,623
  • 2
  • 11
  • 6
141
votes
6 answers

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 for rm and is there a way of undoing an rm…
boehj
  • 2,580
  • 4
  • 23
  • 22
133
votes
4 answers

How do you do a dry run of rm to see what files will be deleted?

I want to see what files will be deleted when performing an rm in linux. Most commands seem to have a dry run option to show just such information, but I can't seem to find such an option for rm. Is this even possible?
Cory Klein
  • 18,391
  • 26
  • 81
  • 93
113
votes
5 answers

How to avoid the need to issue "y" several times when removing protected file

I'm looking for a solution to be used as a response to "rm: remove write-protected regular file [x] ?" I was thinking of issuing a character followed by carriage return for several amount of times, in bashrc. How do we do that?
Iancovici
  • 1,252
  • 2
  • 8
  • 11
107
votes
3 answers

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 remove the write-protected file test.txt. I would have…
Magnus
  • 1,403
  • 3
  • 14
  • 14
104
votes
4 answers

What is the difference between 'rm' and 'unlink'?

Assuming you know the target is a symbolic link and not a file, is there any difference between using rm and unlink to remove the link?
IQAndreas
  • 10,145
  • 21
  • 59
  • 79
1
2 3
55 56