Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- declare -a files
- declare -i total_count=0
- declare -i exec_size=0
- declare -i total_size=0
- desired_type="x-executable; charset=binary"
- function check {
- local filepath="$1"
- local -i size="`stat --format="%s" "$filepath"`"
- (( total_count++ ))
- (( total_size += size ))
- if file --mime "$filepath" | grep "$desired_type" > /dev/null; then
- files+=("$filepath")
- (( exec_size += size ))
- echo $filepath
- fi
- }
- function find {
- local directory="$1"
- for elem in "$directory"/*; do
- if [[ -d "$elem" ]]; then
- find "$elem"
- elif [[ -f "$elem" ]]; then
- check "$elem"
- fi
- done
- }
- declare -i base
- (( base = 1024 ** 2 ))
- function print_size {
- LC_ALL=C printf '%.1lf MiB' `echo "$1" / $base | bc --mathlib`
- }
- if [[ -z "$1" ]]; then
- directory=.
- else
- directory="`echo "$1" | sed -r 's,/$,,'`"
- fi
- echo '[*] Search for files...'
- find "$directory"
- label="[*] Directory contains %d files (total size %s)\n"
- printf "$label" $total_count "`print_size $total_size`"
- label="[?] Are you sure to remove %d files (total size %s)? [yes/no]\n"
- printf "$label" ${#files[@]} "`print_size $exec_size`"
- read -r
- if [[ "$REPLY" == "yes" ]]; then
- rm --force "${files[@]}"
- echo "[+] Operation complete"
- else
- echo "[*] Operation canceled"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement