Display vpnc connection status

To display the connection status of your vpnc connection, use this command line:
pgrep vpnc > /dev/null && echo Connected || echo Disconnected; echo $(ps -p $(pgrep vpnc)

I placed this as a function in my .bashrc files so it is evaluated on every invocation. If this is added as a simple alias, the alias in only evaluated on this creation of the shell and will not get dynamically updated.

vpnc-status() {
  pgrep vpnc > /dev/null && echo Connected || echo Disconnected;
  if [ $(pgrep -c vpnc) -gt 0 ]
    then echo $(ps -p $(pgrep vpnc) -o etime=)
  fi
}

If you add it to your .bashrc file, don’t forget to source the file in order to activate the function:
. ~/.bashrc

Once this function has been activated, invoking it as vpnc-status will output ‘Connected’ or ‘Disconnected’.  If it is connected, it will also display the time it has been running in the [[dd-]hh:]mm:ss format.

Create tar ball from within a Git repo without .git files

Assuming we are sitting in the package development git repo, this command will create a tarball one directory up. Replace branch with the name of the branch you wish to archive.

git archive --format=tar --prefix=package-6.2.0/ <branch> | bzip2 > ../package-6.2.0.tar.bz2

This works great for me as I use .tar.bz2 files in my rpm spec files to build final rpm packages to deploy.

If you need gzip instead of bzip2, pipe the git archive command into gzip instead. And, of course, update the output filename accordingly.

Move mutiple files to a subdirectory

Sometimes I need to move an multiple file or an entire directory tree down one subdirectory level.

mv !(subdir) sudir

uses Bash’s extended pattern matching option – extglob.

To see it extglob is enabled:

shopt extglob

extglob on

To enable extended pattern matching:

shopt -s extglob