rm with progress indicators
This commit is contained in:
1
bin/rm-progress
Symbolic link
1
bin/rm-progress
Symbolic link
@@ -0,0 +1 @@
|
||||
../files/rm-progress
|
||||
72
files/rm-progress
Executable file
72
files/rm-progress
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
function helpexit() {
|
||||
echo Delete files with a progress bar.
|
||||
echo This command is always recursive to folders!
|
||||
echo '-f to force'
|
||||
exit
|
||||
}
|
||||
|
||||
FORCE=0
|
||||
FOLDERS=( )
|
||||
for ((i=1; i<=${#@}; i++)) {
|
||||
[[ "${!i}" = "-h" ]] && helpexit
|
||||
[[ "${!i}" = "--help" ]] && helpexit
|
||||
[[ "${!i}" = "-f" ]] && { FORCE=1; RMFORCE="-f"; continue; }
|
||||
[[ "${!i}" = "-"* ]] && helpexit
|
||||
FOLDERS+=( "${!i%/}" )
|
||||
}
|
||||
[[ "${#FOLDERS[@]}" -eq 0 ]] && helpexit
|
||||
|
||||
function listfiles() {
|
||||
while IFS= read -r -d $'\0' line; do
|
||||
files=$((files+1))
|
||||
printf "\r%02d:%02d:%02d %d" $(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $files
|
||||
done < <(find "$@" \( -type f -or -type l \) -print0)
|
||||
printf "\r"
|
||||
}
|
||||
function deletefiles() {
|
||||
i=0
|
||||
while IFS= read -r -d $'\0' line; do
|
||||
i=$((i+1))
|
||||
percent=$((200*$i/$files % 2 + 100*$i/$files))
|
||||
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
|
||||
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $files $percent "$line"
|
||||
rm "$line"
|
||||
done < <(find "$@" \( -type f -or -type l \) -print0)
|
||||
printf "\n"
|
||||
}
|
||||
function listfolders() {
|
||||
while IFS= read -r -d $'\0' line; do
|
||||
folders=$((folders+1))
|
||||
printf "\r%s %02d:%02d:%02d" $(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $folders
|
||||
done < <(find "$@" -type d -print0)
|
||||
printf "\r"
|
||||
}
|
||||
function deletefolders() {
|
||||
i=0
|
||||
while IFS= read -r -d $'\0' line; do
|
||||
i=$((i+1))
|
||||
percent=$((200*$i/$folders % 2 + 100*$i/$folders))
|
||||
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
|
||||
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders $percent "$line"
|
||||
rmdir "$line"
|
||||
done < <(find "$@" -depth -type d -print0)
|
||||
printf "\n"
|
||||
}
|
||||
echo Listing files...
|
||||
files=0
|
||||
folders=0
|
||||
listfiles "${FOLDERS[@]}"
|
||||
echo Prepared to delete $files files
|
||||
|
||||
if [[ $FORCE -eq 0 ]]; then
|
||||
echo '<ctrl-c> to quit'
|
||||
read foo
|
||||
fi
|
||||
deletefiles "${FOLDERS[@]}"
|
||||
listfolders "${FOLDERS[@]}"
|
||||
echo Removing remaining $folders folders
|
||||
deletefolders "${FOLDERS[@]}"
|
||||
|
||||
Reference in New Issue
Block a user