1

I was trying to move around some files and got a result I didn't want to. How would I undo sudo mv tmp/* usr/local/bin?

3 Answers 3

1

You'll have to distinguish which files in /usr/local/bin are actually binary files meant to stay there and which are temporary files moved accidentally with mv, anyway /tmp is used by applications to temporary store files which are to be deleted in any case upon the next reboot, so as long as you're not concerned with the applications running in the current session possibly crashing/losing data, the worst case scenario is you might have a handful of unuseful temporary files in /usr/local/bin, but still, such directory is always empty upon Ubuntu installation, so it might even have been still empty/almost empty before the mv unless some application installed some binary in there, plus temporary files should be easy distinguishable from binaries, in the end you should be able to easily restore everything back to normal manually moving the temporary files back to /tmp

1

Unfortunately the answer is a "NO". Only thing you can do is to be careful when you do something as root user. May be you can search the directory for that file and move it back using the same mv command

1

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

There is a fuse filesystem that automatically keeps copies of old versions: copyfs, available in all good distributions. Of course, that can use a lot of resources.

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

You must log in to answer this question.

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