Last active
December 16, 2015 08:21
-
-
Save lyndell/853a2ade7e579f281933 to your computer and use it in GitHub Desktop.
tarNdate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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