fastdu, and arhiver improvements
This commit is contained in:
@@ -7,32 +7,39 @@ function helpexit() {
|
||||
echo " -n No compression. Exit after tar archive"
|
||||
exit
|
||||
}
|
||||
function listfolders() {
|
||||
find "$1" -mindepth 1 -maxdepth 1 -type d | sort | tr '\n' '\000'
|
||||
}
|
||||
function fsize() {
|
||||
echo -en "\e[2K\r"
|
||||
[[ -z "$2" ]] || echo -n "$2 -> "
|
||||
ls -sh "$1" | xargs echo -n
|
||||
}
|
||||
|
||||
[[ "$1" = "-h" ]] && helpexit
|
||||
|
||||
echo 'Existing files will be overwritten!'
|
||||
echo Archive the following folders:
|
||||
|
||||
find . -mindepth 1 -maxdepth 1 -type d | tr \\n " "
|
||||
listfolders . | tr "[:cntrl:]" " "
|
||||
echo ''
|
||||
echo '<ctrl-c> to quit'
|
||||
read foo
|
||||
|
||||
|
||||
find . -mindepth 1 -maxdepth 1 -type d -print0 | while read -r -d "" d; do
|
||||
listfolders . | while read -r -d "" d; do
|
||||
echo -n $d
|
||||
tar cvf "$d.tar" $d > "$d.tar.txt" &
|
||||
tar cvf "$d.tar" "$d" > "$d.tar.lst" &
|
||||
PID=$!
|
||||
DU=$( nice fastdu -h "$d" & )
|
||||
DUPID=$!
|
||||
while kill -0 "$PID" &>/dev/null; do
|
||||
[[ -f "$d.tar" ]] && fsize "$d.tar" "$DU"
|
||||
for i in {1..5}; do
|
||||
sleep $i; kill -0 "$PID" &>/dev/null || break 2
|
||||
done
|
||||
fsize "$d.tar"
|
||||
done
|
||||
fsize "$d.tar"
|
||||
fsize "$d.tar" "$DU"
|
||||
kill -0 "$DUPID" &>/dev/null || kill "$DUPID" &>/dev/null
|
||||
echo ''
|
||||
done
|
||||
[[ "$1" = "-n" ]] && {
|
||||
@@ -43,17 +50,17 @@ done
|
||||
read foo
|
||||
}
|
||||
|
||||
find . -mindepth 1 -maxdepth 1 -type d -print0 | while read -r -d "" d; do
|
||||
ls -sh "$d.tar"
|
||||
gzip "$d.tar"
|
||||
listfolders . | while read -r -d "" d; do
|
||||
DU=$( fastdu -h "$d.tar" )
|
||||
gzip -f "$d.tar" &
|
||||
PID=$!
|
||||
while kill -0 "$PID" >/dev/null 2>&1; do
|
||||
[[ -f "$d.tar.gz" ]] && fsize "$d.tar.gz" "$DU"
|
||||
for i in {1..5}; do
|
||||
sleep $i; kill -0 "$PID" &>/dev/null || break 2
|
||||
done
|
||||
fsize "$d.tar.gz"
|
||||
done
|
||||
fsize "$d.tar.gz"
|
||||
fsize "$d.tar.gz" "$DU"
|
||||
echo ''
|
||||
done
|
||||
|
||||
|
||||
39
files/fastdu
Executable file
39
files/fastdu
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
function helpexit() {
|
||||
echo "Display file/folder sizes like 'du', but faster and actual byte sizes"
|
||||
echo "Returns only the size as number"
|
||||
echo " -h Human readable units"
|
||||
echo " --help This help"
|
||||
exit
|
||||
}
|
||||
function filesize {
|
||||
# Return a human readable size from integer of bytes
|
||||
# Usage: filesize 10000
|
||||
|
||||
[ "$1" = "0" ] && {
|
||||
echo "0 B"
|
||||
return 0
|
||||
}
|
||||
|
||||
awk 'BEGIN{ x = '$1'
|
||||
split("B KB MB GB TB PB EB ZB",type)
|
||||
for(i=7;y < 1;i--)
|
||||
y = x / (2^(10*i))
|
||||
str=int(y*10)/10 " " type[i+2]
|
||||
if (x==0) { str = "0 B" }
|
||||
print str
|
||||
}' || return $?
|
||||
}
|
||||
|
||||
[[ -z "$1" ]] && what="."
|
||||
[[ "$1" = "-h" ]] && { HUMAN=1; shift 1; }
|
||||
[[ "$1" = "--help" ]] && helpexit
|
||||
|
||||
SIZE=$( find $what "$@" -type f -printf %s"\n" | awk '{ sum += $1 } END { print int(sum)+0 }' )
|
||||
|
||||
[[ "$HUMAN" -eq 1 ]] && {
|
||||
filesize "$SIZE"
|
||||
exit
|
||||
}
|
||||
echo $SIZE
|
||||
Reference in New Issue
Block a user