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
43
votes
4 answers

osx find exec rm find: exec: unknown primary or operator

I've got a bunch of files that end in "-e" that I want to remove. $ find . -name "*-e" exec rm {} \; find: exec: unknown primary or operator Is the regex expanding in some way that messes everything up?
freedrull
  • 2,194
  • 4
  • 21
  • 33
38
votes
4 answers

Unable to remove files recursively from Git

I want to remove all files from Git at ~/bin/. I run git rm -r --cached ~/.vim/* # Thanks to Pate in finding --cached! I get fatal: pathspec '.vim/colors' did not match any files This error messsage suggests me to use the…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
36
votes
8 answers

Can't remove a directory in Unix

I've got a seemingly un-deletable directory in Unix that contains some hidden files with names that start with .panfs. I'm unable to delete it using either of these commands: rm -R rm -Rf Does anyone have any suggestions?
fugu
  • 6,417
  • 5
  • 40
  • 75
35
votes
3 answers

How to enable confirmation alert when using 'rm' command to delete files / folders?

I have found that we cannot recover files/folders when deleted using rm command from here But, is it possible to add a confirmation alert when using rm command in the terminal?
webster
  • 3,902
  • 6
  • 37
  • 59
30
votes
3 answers

How to recover the deleted files using "rm -R" command in linux server?

I have unfortunately deleted some important files and folders using 'rm -R ' command in Linux server. Is there any way to recover?
Srini
  • 309
  • 1
  • 3
  • 3
27
votes
3 answers

Removing files with rm using find and xargs

When I do rm file.txt or rm *.txt I'm prompted for each file, since I didn't specify the -f option to rm. But when I do this: find . -type f -name '*.txt' | xargs rm the files are removed without the confirmation. What is the logics behind this?…
Martin G
  • 17,357
  • 9
  • 82
  • 98
26
votes
3 answers

Error 'rm: missing operand' when using along with 'find' command

I see that this question is getting popular. I answered my own question below. What says Inian is correct and it helped me to analyze my source code better. My problem was in the FIND and not in the RM. My answer gives a block of code, which I am…
aPugLife
  • 989
  • 2
  • 14
  • 25
23
votes
3 answers

Calling rm from subprocess using wildcards does not remove the files

I'm trying to build a function that will remove all the files that start with 'prepend' from the root of my project. Here's what I have so far def cleanup(prepend): prepend = str(prepend) PROJECT_ROOT =…
mythander889
  • 915
  • 5
  • 16
  • 23
22
votes
3 answers

Does git rm remove all history of a file?

My project has a file foo that I've been using and checking in with git. I just did some refactoring so that I no longer need the file at all. If I do git rm foo, will the file still exist in older commits? Will I be able to check out an older…
Jeffrey
  • 1,681
  • 3
  • 13
  • 23
22
votes
5 answers

How to avoid "No such file or directory" Error for `make clean` Makefile target

I have a Makefile that defines a .PHONY clean target for cleaning up .o files and executables, that target looks like: ... .PHONY : clean clean: rm $(addprefix $(vq_DIR),$(vq_OBJS)) \ $(addprefix $(vq_DIR),vq) \ $(addprefix…
jameh
  • 1,149
  • 3
  • 12
  • 20
19
votes
3 answers

Remove all files that does not have the following extensions in Linux

I have a list of extensions: avi,mkv,wmv,mp4,mp5,flv,M4V,mpeg,mov,m1v,m2v,3gp,avchd I want to remove all files without the following extensions aswell as files without extension in a directory in linux. How can I do this using the rm linux command?
Tike
  • 387
  • 1
  • 2
  • 10
18
votes
3 answers

rm -f equivalent for PowerShell that ignore nonexistent files

Background I have a PowerShell script that writes some results into a file. I want to remove the result file automatically at the start of the script with Remove-Item. You can remove the result file manually, so I don't want to show error messages…
SATO Yusuke
  • 1,600
  • 15
  • 39
18
votes
3 answers

Using find to delete all subdirectories (and their files)

I'm sure this is straight forward and answered somewhere, but I didn't manage to find what I was looking for. Basically, I'm trying to run a cron script to clear the contents of a given directory every 7 days. So far I have tried the…
infmz
  • 347
  • 2
  • 3
  • 10
17
votes
6 answers

Restore deleted file not staged in git

I accidentally removed the entire directory of my source code...with a nice rm -r. I know, really bad; but fortunately, I had a git repo in the containing directory. Thus, git has a huge list of unstaged changes of deleted files. For example:…
Vance T
  • 513
  • 2
  • 5
  • 15
14
votes
8 answers

How to undo git rm -rf dirname without a first commit?

I did: git init git add . git rm -rf dirname Looking at other answsers, git reset --hard HEAD, git checkout -f and git reflog did not work, apparently because there is no HEAD to go back to, nor a commit to get the files back from. Is there a way…
B Seven
  • 44,484
  • 66
  • 240
  • 385
1
2
3
35 36