Skip to content

Instantly share code, notes, and snippets.

@planetceres
Created December 5, 2019 22:56
Show Gist options
  • Save planetceres/1404c50ba0ba173e43fa96644a987d88 to your computer and use it in GitHub Desktop.
Save planetceres/1404c50ba0ba173e43fa96644a987d88 to your computer and use it in GitHub Desktop.
Count/show file types in recursive tree
#!/bin/bash
# Reference: https://unix.stackexchange.com/a/387631
for d in */ ; do
echo $d
find $d -type f | sed -r 's/.*\/([^\/]+)/\1/' | sed 's/^[^\.]*$//' | sed -r 's/.*(\.[^\.]+)$/\1/' | sort | uniq -c | sort -nr
# files only | keep filename only | no ext -> '' ext | keep part after . (i.e. ext) | count | sort by count desc
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment