fastdu, and arhiver improvements
This commit is contained in:
1
bin/fastdu
Symbolic link
1
bin/fastdu
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../files/fastdu
|
||||||
@@ -7,32 +7,39 @@ function helpexit() {
|
|||||||
echo " -n No compression. Exit after tar archive"
|
echo " -n No compression. Exit after tar archive"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
function listfolders() {
|
||||||
|
find "$1" -mindepth 1 -maxdepth 1 -type d | sort | tr '\n' '\000'
|
||||||
|
}
|
||||||
function fsize() {
|
function fsize() {
|
||||||
echo -en "\e[2K\r"
|
echo -en "\e[2K\r"
|
||||||
|
[[ -z "$2" ]] || echo -n "$2 -> "
|
||||||
ls -sh "$1" | xargs echo -n
|
ls -sh "$1" | xargs echo -n
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ "$1" = "-h" ]] && helpexit
|
[[ "$1" = "-h" ]] && helpexit
|
||||||
|
|
||||||
|
echo 'Existing files will be overwritten!'
|
||||||
echo Archive the following folders:
|
echo Archive the following folders:
|
||||||
|
|
||||||
find . -mindepth 1 -maxdepth 1 -type d | tr \\n " "
|
listfolders . | tr "[:cntrl:]" " "
|
||||||
echo ''
|
echo ''
|
||||||
echo '<ctrl-c> to quit'
|
echo '<ctrl-c> to quit'
|
||||||
read foo
|
read foo
|
||||||
|
|
||||||
|
listfolders . | while read -r -d "" d; do
|
||||||
find . -mindepth 1 -maxdepth 1 -type d -print0 | while read -r -d "" d; do
|
|
||||||
echo -n $d
|
echo -n $d
|
||||||
tar cvf "$d.tar" $d > "$d.tar.txt" &
|
tar cvf "$d.tar" "$d" > "$d.tar.lst" &
|
||||||
PID=$!
|
PID=$!
|
||||||
|
DU=$( nice fastdu -h "$d" & )
|
||||||
|
DUPID=$!
|
||||||
while kill -0 "$PID" &>/dev/null; do
|
while kill -0 "$PID" &>/dev/null; do
|
||||||
|
[[ -f "$d.tar" ]] && fsize "$d.tar" "$DU"
|
||||||
for i in {1..5}; do
|
for i in {1..5}; do
|
||||||
sleep $i; kill -0 "$PID" &>/dev/null || break 2
|
sleep $i; kill -0 "$PID" &>/dev/null || break 2
|
||||||
done
|
done
|
||||||
fsize "$d.tar"
|
|
||||||
done
|
done
|
||||||
fsize "$d.tar"
|
fsize "$d.tar" "$DU"
|
||||||
|
kill -0 "$DUPID" &>/dev/null || kill "$DUPID" &>/dev/null
|
||||||
echo ''
|
echo ''
|
||||||
done
|
done
|
||||||
[[ "$1" = "-n" ]] && {
|
[[ "$1" = "-n" ]] && {
|
||||||
@@ -43,17 +50,17 @@ done
|
|||||||
read foo
|
read foo
|
||||||
}
|
}
|
||||||
|
|
||||||
find . -mindepth 1 -maxdepth 1 -type d -print0 | while read -r -d "" d; do
|
listfolders . | while read -r -d "" d; do
|
||||||
ls -sh "$d.tar"
|
DU=$( fastdu -h "$d.tar" )
|
||||||
gzip "$d.tar"
|
gzip -f "$d.tar" &
|
||||||
PID=$!
|
PID=$!
|
||||||
while kill -0 "$PID" >/dev/null 2>&1; do
|
while kill -0 "$PID" >/dev/null 2>&1; do
|
||||||
|
[[ -f "$d.tar.gz" ]] && fsize "$d.tar.gz" "$DU"
|
||||||
for i in {1..5}; do
|
for i in {1..5}; do
|
||||||
sleep $i; kill -0 "$PID" &>/dev/null || break 2
|
sleep $i; kill -0 "$PID" &>/dev/null || break 2
|
||||||
done
|
done
|
||||||
fsize "$d.tar.gz"
|
|
||||||
done
|
done
|
||||||
fsize "$d.tar.gz"
|
fsize "$d.tar.gz" "$DU"
|
||||||
echo ''
|
echo ''
|
||||||
done
|
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
|
||||||
2
rc
2
rc
@@ -13,7 +13,7 @@ export PATH
|
|||||||
function _self_update() {
|
function _self_update() {
|
||||||
touch "$TOOLSPATH"/.lastupdate
|
touch "$TOOLSPATH"/.lastupdate
|
||||||
pushd "$TOOLSPATH" > /dev/null
|
pushd "$TOOLSPATH" > /dev/null
|
||||||
hg pull -u > /dev/null 2>&1
|
timeout 5 hg pull -u > /dev/null 2>&1
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user