-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarit
36 lines (27 loc) · 1002 Bytes
/
tarit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# a 'tar' wrapper that picks up directory name from the cli / stdin
# and archive them to the current dir in a way dirname.date.tar.gz
# if no arguments are given, archives the current dir
#
# Usage: tarit [dirname1 [dirname2 [dirname3 ...]]]
# or command | tarit
# Copyright (C) 2018 ivan.tervanto /at/ aalto.fi
# Released under the GNU General Public License
# by default no directories to archive. i.e. current
args=''
# checking for STDIN, if any, assigning STDIN to $args
[[ -p /dev/stdin ]] && args=$(</dev/stdin)
# if arguments are given, appending the $args with $@
(($#)) && args+=" $@"
# no arguments, no stdin, then it is a current dir
[[ -z "$args" ]] && args="$(pwd)"
# by now we should have a directory list in $args to archive
for d in $args; do
# checking that directory exists, if so, archive it
if [[ -d "$d" ]]; then
echo Archiving $d ...
tar caf ${d##*/}.$(date +%Y-%m-%d).tar.gz "$d"
else
echo " $d does not exist, skipping."
fi
done