Created
March 28, 2017 20:07
-
-
Save fbarriga/fc3cd7e367ec3f551c984e5d76ea4525 to your computer and use it in GitHub Desktop.
btrfs defrag files
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
# get the files and amount of extends | |
find . -type f -exec filefrag '{}' \; > frags.txt | |
# sort by extends | |
cat frags.txt | sed 's/\([^:]*\)\: \([0-9]*\) extent[s]* found/\2 \1/g' | sort -n -r > sorted_frags.txt | |
# defrag the files | |
cat sorted_frags.txt | cut -d' ' -f2- | xargs -d'\n' -I{} sudo btrfs filesystem defragment -v "{}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment