This short article gives you step-by-step details on how to create a backup command so that it automatically creates a backup file for any file you create in Linux.
1) Check if this directory is existing
~/.vimrc
Check by typing ls ~/.
Press the tab key twice after typing ls ~/. (it’s not a full stop, it’s a dot, include it in the search)
You’ll find a list of files where ~/.vimrc will be present. If not present go to 2
2) Create a file
vi ~./.vimrc
3) Inside the file press “i” or insert and type/paste the following commands
set backup
set backupdir=~/vimtmp//,.
set directory=~/vimtmp//,.
4) Save and exit by “wq” command. The dots in the above files are mandatory
5) Try testing it by opening any file in your Linux, through terminal-example-> open vi demo.txt and exit the directory. Type ls in the present directory. If you find a file as demo.txt~ That will be your backup file.
6) Remember to open and close the file at least once to create a backup file.
NOTE:
1) If you make changes to a file and close it, it automatically won’t update the backup file automatically. Before closing the file type : update(it won’t show anything
the name won’t change) and type:wq. Now check with the backup file.
2) You can check the contents of the backup file using the cat demo.c~
3) Every time you open a new file, a backup file is created. If you open demo.c~ another file will be created: demo.c~~
4)You can use the below vim command (like cp, mv) to move the files into backup. (THIS IS NOT NECESSARY< BUT YOU CAN PLAY WITH VIM)
Make a directory by mkdir backup and use the following commands.
cp –backup
cp –backup file2.txt /home/name/backup
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An Article by: Yashwanth Naidu Tikkisetty
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
