Created
January 5, 2021 15:30
-
-
Save nicman23/5fabd882c4c60e5659156955bdad7b14 to your computer and use it in GitHub Desktop.
defrag.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash -e | |
if [ -z "$1" ]; then | |
echo 'usage: [OPTIONS] <file>|<dir>' | |
echo 'same as btrfs filesystem defrag (look at its --help)' | |
exit | |
fi | |
if [ ! "$(id -u)" -eq 0 ]; then | |
echo 'This probably needs root, if not edit' "$0" | |
echo 'Remove line 10: sed -e '\''10d'\'' -i' "$0" | |
exit 2 | |
fi | |
path=${*:${#*}} | |
opts=${*:1:$((${#*} -1))} | |
t=$(find "${path}" -xdev -type f | wc -l) | |
[ $t -eq 0 ] && exit | |
echo Found $t files; | |
btrfs -v filesystem defrag $opts "${path}" 2>&1 | pv -i2 -betlap -s $t > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment