Skip to content

Instantly share code, notes, and snippets.

@lyndell
Last active December 16, 2015 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyndell/853a2ade7e579f281933 to your computer and use it in GitHub Desktop.
Save lyndell/853a2ade7e579f281933 to your computer and use it in GitHub Desktop.
tarNdate
#!/bin/bash -x
#
# Name: tarNdate
# Desc: Wrap up a directory in a tar file with the directy's date.
# URL: https://gist.github.com/lyndell/853a2ade7e579f281933
#
# Author: Lyndell Rottmann
# WWW: http://Lyndell.US
# Copyright (c) 2015 Lyndell Rottmann
#
set -x
if [ -z $1 ]
then
echo "Please provide a directory.";
exit 1;
fi
# TO-DO: remove trailing slash.
dir=$1
if [ ! -d $dir ]
then
echo "$1 is not a directory."
exit 3
fi
fil=${dir}.tar
if [ -e $fil ]
then
echo "${fil} already exists."
exit 2;
fi
# tar the directory
#
tar -cvf ${fil} ${dir}
# change date to match direcory
#
# -r the original day, from the directory
touch -r ${dir} ${fil}
# delete directory
#
# Assuming Mac OS X
#
if [[ "$OSTYPE" == "darwin"* ]]; then
#
trash -v $dir
# show shiny new file
#
open -R $fil
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
# ...
echo "linux-gnu"
trash -v $dir
# list shiny new file
#
ls -gloh $fil
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment