Questions relating to the Linux remove command (rm)

learn more… | top users | synonyms

101
votes
6answers
122k 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 ...
57
votes
6answers
10k 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 ...
42
votes
9answers
204k 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...
28
votes
5answers
33k 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 ...
27
votes
5answers
4k 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 ...
26
votes
5answers
171k 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 ...
21
votes
2answers
2k 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 ...
19
votes
5answers
2k 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 ...
14
votes
3answers
1k 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 ...
9
votes
1answer
7k 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
2answers
4k 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 ...
8
votes
3answers
10k 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 ...
8
votes
3answers
3k 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

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
4answers
2k 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, ...
7
votes
2answers
521 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
4answers
7k 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)?
7
votes
1answer
1k 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?
6
votes
7answers
3k 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
1answer
481 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
7k 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. ...
5
votes
4answers
497 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
2answers
412 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
1answer
4k 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 ?
5
votes
4answers
758 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 ...
4
votes
3answers
2k 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: ...
4
votes
2answers
6k 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
3answers
6k 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
584 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
86 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
184 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
2answers
176 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
425 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 ...
3
votes
5answers
594 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 ...
3
votes
4answers
9k 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
393 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: ...
3
votes
1answer
879 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
760 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
4k views

Copying from mount share drive to local folder through script

This is my first time trying to work with Linux Scripts so this may be something obvious. Here is what I am trying to do: Remove all contents from local folder - rm /home/user/Documents/Exercise/ ...
3
votes
2answers
2k views

how to restore boot folder?

No laughing! I just did sudo rm -vr /boot/*. Is there a way to restore the content? Just to clarify why I would do this: I have a SD-card with a boot-partition mounted at /media/boot that I wanted ...
3
votes
3answers
14k views

Can't delete/edit files on my pendrive

I'm trying to delete the .Trash-1000 from my pen drive, but with sudo rm -rf .Trash-1000/ I got rm: cannot remove `.Trash-1000/expunged/2660089871/apps.log': Read-only file system (one line of ...
3
votes
1answer
278 views

Removing a tree

CODE EDIT So now that I'm off work I can do a little coding in my free time. The way that I think I want this to work is take a tarball (what I would normally extract to a folder anyway) and compare ...
2
votes
4answers
250 views

Delete a list of directories stored in a file

I have a list of directories names in the following path /home/list/list.txt The directories are all in the following path /home/directory/ How can I delete the directories contained in the ...
2
votes
1answer
217 views

Piping find -name to xargs results on filenames with space 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 ...
2
votes
2answers
53 views

Only delete files but not folders with rm

I have a directory like this: <folder1> <folder2> <folder3> file1 file2 file3 What is the rm command like that removes only file1, file2, file3 but leaves folder1, folder2 and ...
2
votes
2answers
2k views

Delete directory by referencing symbolic link

To set up the question, imagine this scenario: mkdir ~/temp cd ~/ ln -s temp temporary rm -rf temporary, rm -f temporary, and rm temporary each will remove the symbolic link but leave the directory ...
2
votes
3answers
730 views

how to remove files in a list of paths easily?

I have a list of lines like /usr/lib/i386-linux-gnu/libavfilter.so /usr/lib/i386-linux-gnu/libavfilter.so.3 /usr/lib/i386-linux-gnu/libavfilter.so.3.42.103 ...
2
votes
4answers
3k 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) ...