#!/bin/bash # Desc: Updates all ots files in $HOME and /mnt/ directories recursively. # Depends: bash 5.1.16, GNU Findutils 4.8.0, GNU Coreutils 8.32 # Version: 0.1.3 # Depends: GNU Coreutils (nproc) main() { # Specify find targets declare -a find_targets; ## User home directory find_targets+=("$HOME"); ## Subdirectories of /mnt/ mapfile -t -O "${#find_targets[@]}" find_targets < <(find /mnt/ -mindepth 1 -maxdepth 1 -type d; ); # Specify options find_depth=12; # find directory depth cpu_count="$(nproc)"; # get logical CPU count batch_size_xargs=100; # xargs batch size cpu_duty="$((cpu_count / 4 + 1))"; # logical CPU cores to use # Remove OTS backup files find "${find_targets[@]}" -maxdepth "$find_depth" -type f -name "*.ots.bak" -exec rm '{}' \; 2>/dev/random; # Upgrade OTS files find "${find_targets[@]}" -maxdepth "$find_depth" -type f -name "*.ots" -print0 2>/dev/random | \ sort -uz | \ shuf -z | \ xargs -0 -n "$batch_size_xargs" -P "$cpu_duty" ots u; }; # main program time { main "$@"; };