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

837 questions
293
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,820
101
votes
8 answers

Have rm not report when a file is missing?

I have a bash script that I want to remove files from various directories. Frequently, they won't be there because they weren't generated and that's fine. Is there a way to get the script not to report that error, but if rm has some other output to…
flickerfly
  • 1,651
44
votes
6 answers

Is it possible to determine the progress of an rm command?

Using rm -rf LargeDirectory to delete a large directory can take a large amount of time to complete depending on the size of the directory. Is it possible to get a status update or somehow monitor the progress of this deletion to give a rough…
John
  • 1,081
28
votes
5 answers

delete subfolders without deleting parent folder

For this type of dir structure : /config/filegroups/filegroupA/files/fileA1.txt /config/filegroups/filegroupA/files/fileA2.txt /config/filegroups/filegroupB/files/fileB1.txt /config/filegroups/filegroupB/files/fileB2.txt ... I know that I can use…
BaltoStar
  • 2,371
27
votes
5 answers

Is there a simple way to preview the files that rm will remove?

Is there a simple way to evaluate what a given rm command will do when you do not understand it (such as not recognizing how the flags, variables, etc. interact)? While ls helps catch problems in your rm parameters, ls -abc XYZ does not list the…
Dane
  • 385
23
votes
9 answers

Is `yes | rm -r` safer than `rm -rf`?

I have heard many times that issuing rm -rf is dangerous since users can accidentally remove the entire system. But sometimes I want to remove a directory recursively without being asked every time. I am thinking about using yes | rm -r instead. The…
user169459
11
votes
1 answer

Is `rm -rf` not atomic?

I've just caught a confusing error: rm: cannot remove `xxx/app/cache/prod': Directory not empty which was caused by the following command: rm -rf $cache_dir/* where $cache_dir is defined as xxx/app/cache So I see it like: rm removed everything in…
zerkms
  • 775
11
votes
1 answer

How to delete a file named --help?

By mistake I created a file named --help trying to get help about the command > > --help If i try to delete the file like this: rm --help the help about the command rm is shown.
Rodrick
  • 213
10
votes
4 answers

How to cancel a rm command?

There are a lot of questions about how to undo a finished rm command. In my case, my rm started asking: "Are you sure you want to delete this file?" And I need to confirm for each one of them. Instead of manually confirming "y/n": Can I set "yes"…
Andrejs
  • 315
  • 2
  • 4
  • 10
9
votes
3 answers

What's the reason that "rm -rf a/b" says "a/b is not empty"?

The following script sometimes gives me things like can't remove a/b as it's not empty ssh -T user@host <
Cheng
  • 6,641
8
votes
2 answers

rm -f files starting with a digit

I've accidentally redirected the output of a CSV file to my directory. How can I rm only the files that start with a number, and leave the files that start with a letter intact? mymachine$ ls 71.24 README.md 30 4.29 8 …
spuder
  • 18,053
7
votes
2 answers

as root cannot remove file under /tmp operation not permitted

working on a server, operating system is SLES 11.4 x86-64. There are many files, and folders, under the /tmp directory. As root, I cannot remove anything under /tmp. Such as rm -f sort5BtEdh or rm /tmp/sort5BtEdh it returns rm: cannot remove…
ron
  • 6,575
5
votes
3 answers

How does Linux format itself while running?

When you run sudo rm -rf --no-preserve-root / Your system will delete every file, one by one. However, this also includes running processes and the operating system itself, eventually deleting rm. How is Linux able to continue to run if program…
Jon
  • 153
4
votes
2 answers

Accidentally made a directory "~" in a subdirectory

I accidentally made a directory "~/" under a subdirectory in my home directory. How to safely remove this directory without affecting my home directory. rm -r ~ obviously won't work... Thanks!
3
votes
1 answer

What exactly does rmdir -p do?

-p, --parents remove DIRECTORY and its ancestors; e.g., rmdir -p a/b/c' is similar tormdir a/b/c a/b a' Yeah - I'm definitely not going to risk testing that out myself. ;)
InquilineKea
  • 6,262
1
2 3