Questions relating to the Linux remove command (rm)

learn more… | top users | synonyms

44
votes
6answers
30k 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 ...
26
votes
5answers
3k 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 ...
21
votes
4answers
10k views

Can files/directories deleted from terminal 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 ...
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
4answers
915 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
5answers
72k 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 ...
9
votes
1answer
6k 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 ...
8
votes
3answers
6k 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
2answers
510 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
2answers
479 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 ...
6
votes
7answers
2k 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
2answers
4k 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. ...
6
votes
1answer
974 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?
5
votes
4answers
465 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
386 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
1k 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
3k 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
546 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
4answers
4k 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)?
4
votes
2answers
162 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
2answers
3k 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
104 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
372 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
225 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
2answers
3k 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 ...
3
votes
4answers
6k 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
287 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
728 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 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.
3
votes
2answers
1k 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
973 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
1answer
55 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 ...
3
votes
3answers
11k 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
256 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
626 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) ...
2
votes
2answers
5k 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..
2
votes
4answers
73 views

Protection For rm

I sometimes work with my server over ssh. I don't want to lose anything because of an accidental rm. Is there a way of creating a trashbin for my server? I know it sounds stupid, but I just want to ...
2
votes
2answers
201 views

Terminal command to remove unknown file

What is the command to remove unknown file from terminal. Edit after following answer: Example: I have two files يا مهدي- Times-يا محمد Events.html مهدي Events.html how do i only first file?
2
votes
2answers
564 views

rm -i alias not working with sudo as root

I have noticed in all my Ubuntu servers the alias rm -i is ignored when you run sudo rm * as root. Is there something in sudo that is causing this behavior? I know you don't need to use sudo when you ...
2
votes
2answers
1k views

Remove files in a directory based on partial name

I wanted to know what is the best way to remove any files no matter what their extension is based on a partial name. Example: 13-05-12_foo_something.jpg 13-06-01_something.png ...
2
votes
2answers
259 views

Cannot delete .Trash-503 directory, returns a $RECYCLE.BIN.trashinfo: Input/output error

I cannot delete .Trash-503 folder via GUI or terminal, it returns a $RECYCLE.BIN.trashinfo: Input/output error Not even sudo rm -r or even a simple ls works in that trash directory. Check terminal ...
2
votes
1answer
64 views

Aliased rm, how do I also alias sudo rm

I aliased rm to a echo use del or full path to rm to save myself from accidental rm (just lost my $HOME to it). But sudo rm still uses /bin/rm. How can I alias it to also print same message? PS: del ...
2
votes
1answer
608 views

LaTeX filepaths in Ubuntu

I'm sorry, this is quite a specific and esoteric question, but I thought if anyone could help... Well, anyway, last night I used ls to look at a directory and noticed some junk hidden files I didn't ...
2
votes
2answers
1k views

“sudo rm” fails to delete files

My main account is called "u1204" and I have some files created with another account called "dad": $ find . -user dad -print ./Documents/Zim Notes/.zim/state.conf ./Documents/Zim Notes ...
1
vote
2answers
114 views

rm file '??q:q '

I accidently created a file named ??q:q and i can't remove it. rm '??q:q' or rm '\?\?q\:q' (To escape the ?) says No such file or directory Another interesting thing: in ls it shows the name as ...
1
vote
3answers
58 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 ...
1
vote
2answers
888 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 ...
1
vote
2answers
82 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 ...
1
vote
2answers
4k views

Can't delete file even as root

I tried to delete a directory by running sudo rm -rf google-chrome. This gave no output message but the directory wasn't deleted. There is only one file remaining, google-chrome/default/User\ ...
1
vote
1answer
773 views

Why is “rm” so much slower than deleting files via the File Manager?

I witnessed that deleting directories (with the size of a couple of gigabytes) which contain many files is very slow when using rm. It takes up to several minutes! When deleting the same folder via ...