[Last Call] Learn how to a build a cloud-first strategyRegister Now


wrapper script for VI

Posted on 2014-08-27
Medium Priority
Last Modified: 2014-08-28
I sometimes type something bad or want to put a file back the way it was before I "improved' it.

I want to put an alias in .bashrc that would backup a file to /root/bk before I edit the file with VI.

the script should copy the named myfile to /root/bk/myfile.YearMonthDayHour and then open it with vi.

Software can not be installed for this, I would like It to be something I can use on any system.

This is for redhat Linux 5.0, vi and bash.
Question by:TIMFOX123
  • 2
  • 2
  • 2
LVL 62

Expert Comment

ID: 40289772
There is etckeeper package available from EPEL repository that does version control on /etc/

Author Comment

ID: 40290837
Great idea Gheist except ... I can not do that.

adding software is an big no no.

Expert Comment

ID: 40290857
This is what i use to save the file in a directory defined by $SAVEDIR
will put date and time at the end of the filename

in home directory, add to .bash_profile
  alias vi='$HOME/bin/myvi'

contents of $HOME/bin/myvi:

# cp $1 file to $SAVEDIR with the time/date extensions
# only the file, not the subdirectory it is in
if [ -e "$1" ]
    cp -p "$1" $SAVEDIR/$NameOfFile`date +%y%m%d%H%M%S`
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


Accepted Solution

penguins_rule earned 2000 total points
ID: 40290885
another option:
I use vim instead of vi
in $HOME/.vimrc  add
:set backup

this will create filename~ of the file just before the change
LVL 62

Expert Comment

ID: 40290914
etckeeper is a script. Extract from rpm and save in /tmp or any other unsafe place.

Author Closing Comment

ID: 40291126
this is just what need

thank you all for your input

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question