Questions tagged [rm]

rm is a basic UNIX command used to remove files, directories, and other items from the filesystem.

rm is a basic UNIX command used to remove files, directories, and other items from the filesystem.

Options:

-f force
-r, -R or --recursive

Examples

rm -rf /some/dir #removes all files and dirs recursively from this point

References

534 questions
427
votes
4 answers

How to remove files and directories quickly via terminal (bash shell)

From a terminal window: When I use the rm command it can only remove files. When I use the rmdir command it only removes empty folders. If I have a directory nested with files and folders within folders with files and so on, is there a way to…
None
249
votes
12 answers

How to remove folders with a certain name

In Linux, how do I remove folders with a certain name which are nested deep in a folder hierarchy? The following paths are under a folder and I would like to remove all folders named a. …
Joe
  • 14,513
  • 28
  • 82
  • 144
230
votes
20 answers

Remove all files except some from a directory

When using sudo rm -r, how can I delete all files, with the exception of the following: textfile.txt backup.tar.gz script.php database.sql info.txt
masjoko
  • 2,311
  • 2
  • 14
  • 4
216
votes
6 answers

How to prevent rm from reporting that a file was not found?

I am using rm within a BASH script to delete many files. Sometimes the files are not present, so it reports many errors. I do not need this message. I have searched the man page for a command to make rm quiet, but the only option I found is -f,…
Village
  • 22,513
  • 46
  • 122
  • 163
215
votes
8 answers

Linux delete file with size 0

How do I delete a certain file in linux if its size is 0. I want to execute this in an crontab without any extra script. l filename.file | grep 5th-tab | not eq 0 | rm Something like this?
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
179
votes
5 answers

Command line: piping find results to rm

I'm trying to work out a command which deletes sql files older than 15 days. The find part is working but not the rm. rm -f | find -L /usr/www2/bar/htdocs/foo/rsync/httpdocs/db_backups -type f \( -name '*.sql' \) -mtime +15 It kicks out a list of…
jerrygarciuh
  • 21,158
  • 26
  • 82
  • 139
129
votes
7 answers

How to delete multiple files at once in Bash on Linux?

I have this list of files on a Linux server: abc.log.2012-03-14 abc.log.2012-03-27 abc.log.2012-03-28 abc.log.2012-03-29 abc.log.2012-03-30 abc.log.2012-04-02 abc.log.2012-04-04 abc.log.2012-04-05 abc.log.2012-04-09 abc.log.2012-04-10 I've been…
user1253847
  • 5,241
  • 10
  • 29
  • 28
103
votes
4 answers

How do I remove an empty folder and push that change?

How can I remove an empty folder locally and also have that happen for other collaborators that share the remote via pull-push? I know that folders aren't 'tracked' in that sense by git but the question remains. e.g. I moved a file to another…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
101
votes
10 answers

Remove only files in directory on linux NOT directories

What delete command can be run to remove only files in given directory NOT directories NOT sub-directories NOT files in these sub-directories. Some files don't have extensions so rm *.* wont work... There are thousands of files in this…
AndrewC
  • 1,282
  • 2
  • 11
  • 10
90
votes
5 answers

Linux why can't I pipe find result to rm?

sorry if this is a noobie question but I can't find a good answer. To find then remove something I can use find . -name ".txt" -exec rm "{}" \; But why can't I just pipe the results to rm like find . -name ".txt" | rm like I would pipe it to…
user1297061
  • 1,531
  • 2
  • 13
  • 15
86
votes
8 answers

How to delete only directories and leave files untouched

I have hundreds of directories and files in one directory. What is the best way deleting only directories (no matter if the directories have anything in it or not, just delete them all) Currently I use ls -1 -d */, and record them in a file, and do…
kopelkan
  • 1,135
  • 2
  • 9
  • 8
81
votes
12 answers

Delete a list of files with find and grep

I want to delete all files which have names containing a specific word, e.g. "car". So far, I came up with this: find|grep car How do I pass the output to rm?
Magnus
  • 1,550
  • 4
  • 14
  • 33
78
votes
3 answers

Powershell Command: rm -rf

rm is to remove item, but what is the parameter -rf do or signify? Whenever I typed help -rf it printed the entire list of available commands in powershell. What happens if you type rm -rf in powershell? From reading around I've gathered that it…
BK_
  • 783
  • 1
  • 5
  • 5
66
votes
1 answer

Unable to use yes -command to all questions when removing

I get a long list of read-only protected files when I run rm -r trunk | yes I am trying to answer yes to all by one command. How can you answer yes to all questions?
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
60
votes
8 answers

Delete files with string found in file - Linux cli

I am trying to delete erroneous emails based on finding the email address in the file via Linux CLI. I can get the files with find . | xargs grep -l email@example.com But I cannot figure out how to delete them from there as the following code…
Spechal
  • 2,634
  • 6
  • 32
  • 48
1
2 3
35 36