Recently I accidentally did rm
on a set of files and it got me thinking where exactly these files end up?
That is to say, when working with a GUI, deleted files go to the Trash. What's the equivalent for rm
and is there a way of undoing an rm
command?
Best Answer
Nowhere, gone, vanished. Well, more specifically, the file gets unlinked. The data is still sitting there on disk, but the link to it is removed. It used to be possible to retrieve the data, but nowadays the metadata is cleared and nothing's recoverable.
There is no Trash can for
rm
, nor should there be. If you need a Trash can, you should use a higher-level interface. There is a command-line utility intrash-cli
on Ubuntu, but most of the time GUI file managers like Nautilus or Dolphin are used to provide a standard Trash can. The Trash can is standard itself. Files trashed in Dolphin will be visible in the Trash from Nautilus.Files are usually moved to somewhere like
~/.local/share/Trash/files/
when trashed. Therm
command on UNIX/Linux is comparable todel
on DOS/Windows which also deletes and does not move files to the Recycle Bin. Another thing to realize is that moving a file across filesystems like to your USB disk from your hard disk drive is really 1) a copy of the file data followed by 2) unlinking the original file. You wouldn't want your Trash to be filled up with these extra copies.