Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i get the feeling i'm gonna need it one day, like if i've just deleted something i shuldn'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 at 21:47

3 Answers 3

Negative. There is no magic undo button in linux.

share|improve this answer
2  
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
1  
bash.org/?6899 –  Corey Oct 3 '10 at 3:05
1  
good point history | grep partofwhatidid can be helpful –  hbdgaf Oct 3 '10 at 3:05

No.

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, OSX, 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 no any "undo" option, only if you used 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+

For HFS+ (OSX) there are few commercial solutions such as:

Read more: Recover Files From Formatted HFS+ Partition


For 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.