-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompress
executable file
·54 lines (43 loc) · 1.23 KB
/
compress
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#------------------------------------------------------------------------------#
#Title :compress
#Author :Ivan Batistic
#Date :01/2023
#Version :0.1
#Bash_version :5.1.16(1)-release
#Description :
#Note :checked with ShellCheck
#------------------------------------------------------------------------------#
if [[ ( $# -eq 0 ) || ( $1 == "--help" ) || ( $1 == "-h" ) ]] ; then
echo "Configured tar function to compress files"
echo " "
echo "Options used: -czvf"
echo " "
echo "Mandatory arguments: fileName"
echo " "
echo "Example:"
echo "tar -czvf fileName.tar.gz fileName"
exit 1
fi
if [[ $# -ne 1 ]]; then
echo "1 argument required, $# provided" >&2
return 1;
fi
lastChar=${1: -1}
t=""
if [[ "$lastChar" == "/" ]];
then
t=${1::-1}."tar.gz"
else
t=$1."tar.gz"
fi
echo "Compressing folder $1 into $t"
echo
tar -czvf "$t" "$1"
# Compressing using 16 cores
# tar cf - *.csv | pigz -p 16 -c > resuls.tar.gz
b_c=$(du -sh "$1" | awk '{print $1}')
a_c=$(du -h "$t" | awk '{print $1}')
echo
echo "Compression ratio: $b_c -> $a_c"
#------------------------------------------------------------------------------#