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

2 Answers 2

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
    
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

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.