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?
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.
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).