I wanted to make a copy of my file and I generally use

cat file1> file2

This time, I typed mistakenly

cat file1> file1

Because of which the the contents of my original file are lost. Is there any way to recover it?


No, there is no practical* way to recover this file.

*In principle, that actual data are still located on the storage medium, but locating and recovering these data (before some other data is written over all or part of the file) is practically impossible.


It is not practical, unless the data is worth a lot, and you stop the machine immediately, take it to an expert, pay them lots of money, and get lucky.

For the future.

What you need is a revision control system. It won't help this time, but will in the future.

A revision control system, keeps a history of your files. Here is an example session.

hg init
hg add file1
hg commit -m "add initial file1"
change file1
hg commit -m "add/change …"
cat file1> file1
hg revert file1

You can even go back farther.

hg update -r 1 #goes to initial version

svn is an easy one for beginners, and still powerful. Mercurial (hg), has more features, so a bit harder to learn. svn is also better for some document types (un-mergable: Office documents).

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