From a95b20120ce09b6cbad89356631ff7060d314f5e Mon Sep 17 00:00:00 2001 From: q Date: Mon, 15 Feb 2016 22:43:36 +0200 Subject: [PATCH] folder archiver --- bin/archive_subfolders | 1 + files/archive_subfolders | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 120000 bin/archive_subfolders create mode 100755 files/archive_subfolders diff --git a/bin/archive_subfolders b/bin/archive_subfolders new file mode 120000 index 0000000..863fc47 --- /dev/null +++ b/bin/archive_subfolders @@ -0,0 +1 @@ +../files/archive_subfolders \ No newline at end of file diff --git a/files/archive_subfolders b/files/archive_subfolders new file mode 100755 index 0000000..161a6c8 --- /dev/null +++ b/files/archive_subfolders @@ -0,0 +1,49 @@ +#!/bin/bash + + +function helpexit() { + echo Archive the subfolders of the current directory + echo " -z Compress. If not passed, will ask after tar archive" + exit +} + +[[ "$1" = "-h" ]] && helpexit + +echo Archive the following folders: + +find . -mindepth 1 -maxdepth 1 -type d | sort | tr \\n " " +echo '' +echo ' to quit' +read foo + + +find . -mindepth 1 -maxdepth 1 -type d -print0 | sort | while read -r -d "" d; do + echo -n $d + tar cvf "$d.tar" $d > "$d.tar.txt" & + PID=$! + while kill -0 "$PID" >/dev/null 2>&1; do + sleep 5 + echo -en "\r" + ls -sh "$d.tar" | xargs echo -n + done + echo -en "\r" + ls -sh "$d.tar" +done +[[ "$1" = "-z" ]] || { + echo 'Proceed to compress? to quit' + read foo +} + +find . -mindepth 1 -maxdepth 1 -type d -print0 | sort | while read -r -d "" d; do + ls -sh "$d.tar" + gzip "$d.tar" + PID=$! + while kill -0 "$PID" >/dev/null 2>&1; do + sleep 5 + echo -en "\r" + ls -sh "$d.tar" | xargs echo -n + done + echo -en "\r" + ls -sh "$d.tar" +done +