Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I deleted my file content in the file how can i recover back using timestamps is it possible for ex: I am having the file1.txt

cat file1.txt 
i am linux user 
i am new to linux 
i love linux 

After sometime i later i delete the file content

cat file1.txt 
empty: 

how to get back the content again in the file

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Depends how you edited / deleted and how many times the content. Some editors like gedit creates a backup copy of file before saving with the '~' (tilde) suffix. These files with the '~' suffix are hidden files for most of file managers (like Nautilus). So, with a little bit of luck you can recovery your lost content from these files.

share|improve this answer
    
Thanks but ,i don’t have gedit i am using vi editor could tell me these editor also create file in same way –  Premkumar Mar 15 at 13:10
    
@Premkumar Sorry to inform you, but by default vi doesn't create backup files. You can see this guidelines about how you can make vi to store backups of the file you are editing. –  Radu Rădeanu Mar 15 at 13:37
    
oh thanks friend i try and tell u know –  Premkumar Mar 15 at 13:43

Backup file for some text document files will be automatically created if it was opened using gedit text editor.Which was hidden and it ends with ~.By default this text document backup option was enabled.If you dont want gedit to create any backups.Then you can disable this option from,

Gedit-->Edit-->Preferences-->Editor

enter image description here

To ensure it's presence try ls command after cding into the current directory.If it was located, then copy its contents to the main file by running the below command,

cat file1.txt~ > file1.txt
share|improve this answer
    
thanks but i don’t have GUI ,then how can i do that enabling, can i do that in command line is there any command and also i am not having gedit –  Premkumar Mar 15 at 13:07

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.