Skip to content

Instantly share code, notes, and snippets.

@fbarriga
Created March 28, 2017 20:07
Show Gist options
  • Save fbarriga/fc3cd7e367ec3f551c984e5d76ea4525 to your computer and use it in GitHub Desktop.
Save fbarriga/fc3cd7e367ec3f551c984e5d76ea4525 to your computer and use it in GitHub Desktop.
btrfs defrag files
# 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