included shred option for rm-progress

This commit is contained in:
Ville Rantanen
2017-05-30 10:51:10 +03:00
parent 8b693a52ce
commit 12b596ec3e

View File

@@ -4,18 +4,21 @@ set -e
function helpexit() { function helpexit() {
echo Delete files with a progress bar. echo Delete files with a progress bar.
echo This command is always recursive to folders! echo This command is always recursive to folders!
echo '-f Dont ask questions' echo '-f Do not ask questions'
echo '--nc Dont count files first' echo '--nc Do not count files first'
echo '--shred Use "shred -u" instead of rm'
exit exit
} }
FORCE=0 FORCE=0
RMCOMMAND=rm
FOLDERS=( ) FOLDERS=( )
for ((i=1; i<=${#@}; i++)) { for ((i=1; i<=${#@}; i++)) {
[[ "${!i}" = "-h" ]] && helpexit [[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "--help" ]] && helpexit [[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-f" ]] && { FORCE=1; RMFORCE="-f"; continue; } [[ "${!i}" = "-f" ]] && { FORCE=1; RMFORCE="-f"; continue; }
[[ "${!i}" = "--nc" ]] && { NOCOUNT=1; continue; } [[ "${!i}" = "--nc" ]] && { NOCOUNT=1; continue; }
[[ "${!i}" = "--shred" ]] && { RMCOMMAND="shred -u"; continue; }
[[ "${!i}" = "-"* ]] && helpexit [[ "${!i}" = "-"* ]] && helpexit
FOLDERS+=( "${!i%/}" ) FOLDERS+=( "${!i%/}" )
} }
@@ -35,7 +38,7 @@ function deletefiles() {
[[ $files -ne 0 ]] && percent=$((200*$i/$files % 2 + 100*$i/$files)) [[ $files -ne 0 ]] && percent=$((200*$i/$files % 2 + 100*$i/$files))
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \ printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $files "$percent" "$line" $(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $files "$percent" "$line"
rm "$line" $RMCOMMAND $RMFORCE "$line"
done < <(find "$@" \( -type f -or -type l \) -print0) done < <(find "$@" \( -type f -or -type l \) -print0)
printf "\n" printf "\n"
} }
@@ -53,7 +56,7 @@ function deletefolders() {
[[ $folders -ne 0 ]] && percent=$((200*$i/$folders % 2 + 100*$i/$folders)) [[ $folders -ne 0 ]] && percent=$((200*$i/$folders % 2 + 100*$i/$folders))
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \ printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders "$percent" "$line" $(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders "$percent" "$line"
rm -r "$line" rm $RMFORCE -r "$line"
done < <(find "$@" -depth -type d -print0) done < <(find "$@" -depth -type d -print0)
printf "\n" printf "\n"
} }