Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I get the feeling I'm going to need it one day, like if I've just deleted something I shouldn't have, or renamed something and can't remember what it should be called, etc.

share|improve this question
No OS that I know of supports such a feature. To be able to support undo for a rm -Rf / would require that there be a complete backup of the drive in existence somewhere. This is never going to be possible (or desired due to the immense time maintaining these types of backups would take). That's just one thing that one program could do; never mind undo for something like mke2fs /dev/hdb1. – krowe2 Oct 24 '14 at 21:47
Ah, I got here thinking more along the lines of undoing a paste (or text entered at the command line), e.g.… – Pat Jul 22 '15 at 19:47

Negative. There is no magic undo button in Linux.

share|improve this answer
But if you screw something up with a typo, you can frequently use the command history to find out what you actually did as opposed to what you thought you did. – Velociraptors Oct 3 '10 at 3:00
2 – Corey Oct 3 '10 at 3:05
good point history | grep partofwhatidid can be helpful – RobotHumans Oct 3 '10 at 3:05


Unix doesn't natively provide an undo feature. The philosophy is that if it's gone, it's gone. If it was important, it should have been backed up.

Instead of removing a file, you can move it to a temporary “trash” directory. Some desktop environments make their “delete” command move the file to the trash. But beware that only a few applications will use it; others will just remove the file.

Many commands can be reversed, e.g., a file move can be undone by moving the file back. Commands that delete or overwrite a file can't easily be undone if at all; some of them can be made more robust against accidental data loss through shell settings. In particular:

  • On the command line, cp and mv will overwrite any existing target file, but you can make them prompt:

    alias cp='cp -i'
    alias mv='mv -i'

    I recommend these two aliases because without them, cp and mv do two jobs: copying/moving and deleting. Not having cp and mv delete files is more in keeping with the unix philosophy (one command does one job) and less error-prone. (This is completely different from rm -i, which asks for confirmation before doing its job — such a systematic prompt tends to trigger an automatic response and thus becomes a useless annoyance.)

  • You can make the > redirection operator only accept to create files, so that you have to write >|foo to allow overwriting an existing file foo.

    set -o noclobber

There is a FUSE filesystem that automatically keeps copies of old versions: copyfs, available for most unices (*BSD, Linux, OS X, Solaris). Of course, that can use a lot of resources.

If you've moved a file to a different directory and remember (part of) its name but not its location, you can use the locate command to find it.

The best way to protect against such accidents is to use a version control system (cvs, bazaar, darcs, git, mercurial, subversion, ...). It takes a little time to learn, but it pays off awesomely in the medium and long term.

share|improve this answer

There is not any "undo" option, only if you used the Trash feature.

To recover removed files, it really depends which file system you have.

There is:

It supports most of the major file systems.

HFS Plus

For HFS Plus (OS X) there are a few commercial solutions such as:

Read more: Recover Files From Formatted HFS+ Partition

For a complete list, check:

To avoid similar situations, please do the backups more frequently, use version control or read how to Make rm move to trash.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .