wrapper script for VI

Posted on 2014-08-27
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
    LVL 61

    Expert Comment

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

    Author Comment

    Great idea Gheist except ... I can not do that.

    adding software is an big no no.
    LVL 1

    Expert Comment

    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`
    LVL 1

    Accepted Solution

    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 61

    Expert Comment

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

    Author Closing Comment

    this is just what need

    thank you all for your input

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now