Questions relating to the Linux remove command (rm)

learn more… | top users | synonyms

184
votes
6answers
222k views

How can I recursively delete all files of a specific extension in the current directory?

How do I safely delete all files with a specific extension (e.g. .bak) from current directory and all subfolders using one command-line? Simply, I'm afraid to use rm since I used it wrong once and now ...
69
votes
9answers
315k views

How to remove all files from a directory?

The closest I've gotten is # rm /path/to/directory/*.* but that doesn't work for files that don't have an extension...
66
votes
6answers
22k views

How is 'rm -rf /' able to delete all files in the system?

I haven't tried this command on Ubuntu (for obvious reasons) so I am not sure if Ubuntu will allow its execution. But it's famous for deleting everything. Just out of curiosity, what happens when the ...
35
votes
5answers
69k views

Can files/directories deleted with rm be restored?

Is it possible to restore files/directories which are deleted from terminal using rm and rm -r?. If a file is deleted from graphical interface, it could be restored from trash, but how do you restore ...
35
votes
5answers
283k views

How do I remove a folder?

I'm a new user and Im trying to remove a specific folder. I am using sudo rm /path/ but its not working. What is the correct command to use? It is a file catolog I am attempting to remove but im ...
27
votes
5answers
5k views

Removing folder named ~

This is the output of ls -l ls -l total 53484 drwxr-xr-x 3 root root 4096 2011-02-10 05:59 ~ -rw-r--r-- 1 root root 54313810 2011-02-13 05:09 jobs.jar -rw-r--r-- 1 root root 384035 2011-02-15 ...
23
votes
2answers
6k views

Does using -v (verbose) slow commands down?

In this question: How to remove all files and subdirectories in a directory WITHOUT deleting the directory in bash? it is asked how to delete all file in a folder, and not the folder itself. Matts ...
21
votes
5answers
5k views

Unable to remove a file which has a name like a command argument [duplicate]

I inadvertently created a file called -r in my home directory. Now I cannot get rid of it: rm -rf rm: missing operand Try 'rm --help' for more information. Other attempts: rm /-/r rm: cannot ...
16
votes
6answers
11k views

Is there any faster way to remove a directory than “rm -rf”?

I have a folder that has many files and "rm -rf" takes a lot of time to complete. Is there any faster way to remove a directory and it's contents (subdirs, etc)?
14
votes
3answers
2k views

Exclude from * in command line

There are plenty of situations where the use of a * is virtually inevitable - e.g. rm -rf * in a folder that holds thousands of subfolders and files. But what if you want to exclude just one or two ...
10
votes
2answers
2k views

What does [co] mean in the “rm -rf filename[co]” command?

Let's say I have two files in /tmp: root@ubuntu:~# touch /tmp/hello.{pyc,py} root@ubuntu:~# ls /tmp/ hello.py hello.pyc Now, lets run rm -rf command with [co] option root@ubuntu:~# rm -rf /tmp/...
10
votes
2answers
5k views

Does Ubuntu Server have a Trash?

I'm using the server version of Ubuntu. I was wondering if files still go into the "trash" etc. with this version. I'm been deleting stuff and I just want to make sure the stuff is not being put into ...
9
votes
4answers
14k views

How can I make rm stop asking me for permission?

On my server rm always asks me for permission (even though I'm root) when I run it, on my desktop it does not. Like so: $ rm mod_wsgi-3.3.tar.gz rm: remove regular file `mod_wsgi-3.3.tar.gz'? How ...
9
votes
1answer
8k views

rm: cannot remove `/run/user/root/gvfs': Is a directory

Whenever I type a command which is similar to sudo apt-get install or anything like this I get this kind of error: $ sudo su # exit exit rm: cannot remove `/run/user/root/gvfs': Is a directory How ...
9
votes
3answers
5k views

How to find the pid of the process which has deleted a file?

I am working on a project related to VM migration. Sometimes the VM image will disappear and I just want to know who the culprit is. I tried strace on suspicious processes but to no avail.
8
votes
2answers
2k views

I have a file named “-t”. How to remove it? [duplicate]

Output of "ls -l": -rw-r--r-- 1 root root 0 Mar 4 08:22 -t When i try to do "rm '-t'": rm: invalid option -- 't' Try 'rm ./-t' to remove the file '-t'. Try 'rm --help' for more information.
8
votes
4answers
15k views

“No such file or directory” when trying to remove a file, but the file exists?

I am trying to remove a png image that was uploaded to my server via a PHP script. Whenever I try to delete it both through ftp and terminal, I get the error No such file or directory However, ...
8
votes
1answer
2k views

How to prevent a file under user folder to be deleted?

How can I make some file impossible to be deleted by user even if it is under his/her home folder?
8
votes
2answers
3k views

How is rm command different from the delete button?

I read from a book where it says, the command rm deletes the inode and not the file. Which means if I delete with the rm command, then it cannot be restored. I'm very new to Ubuntu environment. Now ...
7
votes
4answers
2k views

How can I delete a file if it starts with <html> in bash?

I need a bash command to delete the entire file if the file itself begins with <html>. I'm not sure the best way to go about this... Context: I download a series of files via curl requests. ...
7
votes
2answers
568 views

Is there a significant disadvantage to aliasing rm to do something else?

I've been bitten a few times recently with rming things I shouldn't have - for example, forgetting to ulink symlinks, not rm them. I'm thinking of writing a small bash script to simply move the ...
7
votes
1answer
7k views

How to remove files modified between particular dates?

As in the topic: I would like to remove files in a directory that have been modified in a particular date range. How can I do this ?
6
votes
7answers
4k views

Is the command `sudo rm /Desktop/filename` safe?

Is this safe to use? sudo rm /Desktop/FILENAME The reason for wanting to use sudo is I can't see the file. I accidentally typed in sudo rm /Desktop/index.html. It didn't find it but could ...
6
votes
3answers
27k views

Syntax error near unexpected token `('

When I use below code in Ubuntu terminal, it works fine: rm !(*.sh) -rf But if I place the same line code in a shell script (clean.sh) and run the shell script from terminal, it throws an error: ...
6
votes
1answer
799 views

How to recover accidentally removed /bin/ls binary

I have mistakenly deleted the ls executable from the /bin folder. Can I recover it or install it through the terminal?
6
votes
2answers
8k views

Is there a way to do a ' ls -R | grep “aname”* | rm; to remove multiple files in multiple directory

I have installed (compiled) emerald. The command make uninstall didn't work (there is no makefile as it is just a script). So I decided to remove the file manually. But there were a lot of files. I'...
5
votes
4answers
521 views

Repairing after a rm -rf /*

I accidentally ran rm -rf /* on my Ubuntu 10.10 and canceled the command quickly then. Although I was not sudo but a lot of my files were deleted. The system has become less responsive and I am not ...
5
votes
1answer
3k views

Piping find -name to xargs results in filenames with spaces not being passed to the command

Normally to remove files with spaces in their filename you would have to run: $ rm "file name" but if I wanted to remove multiple files, i.e: $ find . -name "*.txt" | xargs rm This will not ...
5
votes
2answers
422 views

rm -I to prevent accidental rm

I just created alias rm="rm -I" to prevent from accidental rm command. -I prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while ...
5
votes
1answer
2k views

Cannot delete file from /home by rm command

I cannot delete a file in my /home folder. Terminal output give me the message: ~$ rm /home/goldap/Загрузки/Put Don Kihota (1934) bash: ошибка синтаксиса около неожиданной лексемы '(' Roughly ...
5
votes
4answers
1k views

How can I prevent accidental execution of the rm -r *command?

Occasionally I use command to delete some files. For example, the name might start with 'a', so I'll delete with the command rm -r a*, but I don't want to remove some other directory by accident. How ...
5
votes
3answers
8k views

I cannot delete files from root's Trash

I deleted some large files from nautilus launched as sudo. They still show in /home/.Trash-0/files/<foldername> when I type sudo sh -c "du -h /home | grep -P '[0-9]G\t'" but when I type sudo rm ...
4
votes
2answers
10k views

Difference between sudo rm -rf and rm -vf?

Recently I have seen one issue with a cache problem. The problem comes with broken hash and that could be fixed with sudo rm -rf /var/lib/apt/lists/* and sudo rm /var/lib/apt/lists/* -vf But I ...
4
votes
2answers
930 views

Converting .rm to .flv using terminal?

Is there anyway to convert .rm to .flv using terminal? Because .rm file is not running in Mplayer in my Ubuntu 12.04. OS Detail: Linux HP-CQ40 3.8.0-39-generic #58~precise1-Ubuntu SMP Fri May 2 ...
4
votes
1answer
129 views

what happens if i delete a file while tar is processing it?

I am attempting to backup my filesystem with the following command: tar -cvjf /fs.bz2 --exclude=/fs.bz2 --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys / This command has been ...
4
votes
1answer
841 views

Difference between commands for removing empty directories

What is the difference between rm --dir <directory> and rmdir <directory> with respect to removing empty directories? Also, if they are similar, is there any advantage of having an rmdir ...
4
votes
0answers
131 views

Not allowed to delete a encfs-encrypted empty folder

I have an encfs-encrypted folder and just cut the content of a subfolder of it and pasted it into another folder outside the encfs-encrypted one. While doing that, I got an error message, saying that ...
4
votes
2answers
293 views

How to prevent users from deleting files that are already in use?

Consider this scenario: User is executing a command on a file. This file becomes 'in-use' now. $ tail -f somefile.log In another shell, user deletes the file. $ rm somefile.log Now, this file ...
3
votes
4answers
457 views

“rm” doesn't accept internal command as a paramter

Why doesn't this work? rm $(gsettings get org.gnome.desktop.background picture-uri | awk '{gsub("file://","");print $0}') rm: cannot remove `\'/home/foggy/obrazky/wallpapers/24/...
3
votes
5answers
366 views

rm: cannot remove directory/: Permission denied

I made a directory , the name is "shadi" and I set this permission for it In this situation I have others permissions but why I can not delete the
3
votes
5answers
831 views

Cannot delete Directory, doesn't exist?

Somehow this folder got created when i was logged in via sftp. "Sep 19 18:50 " I tried to delete it via sftp. Tried to SSH in and delete with rm -rf as root Error: rm /home/user/Downloads/manual/...
3
votes
4answers
11k views

Command to delete all files from folders matching name recursivly?

I have my base folder (let's call it base). I have a bunch of folders inside, scattered at various depths within these folders are cache folders. I want to delete all files from within the cache ...
3
votes
2answers
359 views

Difference between rm executable >>dev/null and rm executable

What is the difference between rm executable and rm executable >>dev/null I had the later statement in a Makefile and changed it to the first one. I had the impression that nothing changed....
3
votes
1answer
504 views

How do I delete / remove a file

I am a beginner with Linux / Ubuntu, and I'm trying to remove / delete a file. The specific is a wallet I created in Electrum to import a paper wallet; I can see the wallet in the file list but can't ...
3
votes
4answers
6k views

`rm -rf ` and `rm -r` have the same results

Bear in mind that I just learning bash so please explain in moderate terms. rm -rf and rm -r appear to do the same thing. The tutorial (https://help.ubuntu.com/community/Beginners/BashScripting) ...
3
votes
2answers
438 views

rm if there's a file with same basename

Say I have the following files: foo.coffee foo.js bar.js Is there an easy way how to rm *.js if there's a corresponding .coffee file? In the example such a command would remove foo.js leaving: foo....
3
votes
2answers
16k views

How to remove single file from /usr directory?

I am using Ubuntu 12.04 LTS, and I want "XnRetro.desktop" file to be removed from directory /usr/share/applications using terminal . How to do it ? I am new into Linux & I know something like "rm"...
3
votes
1answer
932 views

File wont delete from trash even after sudo rm -rf ~/.local/share/Trash/

I've tried using sudo rm -rf ~/.local/share/Trash/files/ and even going myself as root doing the same, and recreating the folder its still there, it was from a pendrive at one point and I deleted it ...
3
votes
2answers
2k views

How to prevent directory from being deleted by user?

Suppose a directory dir1 is created by sudo on Desktop. sudo mkdir dir1 Then I applied chown and chmod as following: sudo chown root:root dir1 sudo chmod go-rwx dir1 Now dir1 is only accessible ...
3
votes
2answers
7k views

how to download “rtsp” flow

I could download a conference from this link (rtsp://real2.infn.it/webcast/2012-esploratori-invisibile/esploratori-dell-invisibile.rm). How can I do it? Thank you previuosly..