1

I am trying to find file extensions with sorted by size in a directory and sub directory.

Something like this:

 76K    .pek  ./Adobe Premiere Pro Preview Files/demo.PRV/1d860051-77c9-4acb-973e-3b6b4428c54e+57631ed274ffb879a432291c 48000.pek
 18M    .cfa  ./Adobe Premiere Pro Preview Files/demo.PRV/1d860051-77c9-4acb-973e-3b6b4428c54e+57631ed274ffb879a432291c 48000.cfa
 19M          ./.git/objects/e6/66dcd00fc197154f89563f2f1aa508e2ab3b50
 21M    .mov  ./Demo 2.mov

and also if possible search excluding some directories like .git

I have tried this https://superuser.com/a/397662

1

The find command on my system works like this

 # find . -type f -ls 
... 
145890044    12192 -rw-rw-r--   1 USER GROUP        239234 Jun  7 15:03 ./QA/Audits/scripts/MYFILE.pdf 
...

find . -type f finds all the files in the current directory and sub directories

-ls lists the files

If you wish to exclude directories you can use the prune switch https://stackoverflow.com/questions/1489277/how-to-use-prune-option-of-find-in-sh

The size is in column number 7 of the output. So if I want to sort the results, I do this

# find . -type f -ls | sort -nr -k7 

-n number -r reverse order (optional) -k7 column number 7

| improve this answer | |
0

I can find the file size

$ find . -type f -print0 | xargs -0 du | sort -rn | head -10 | cut -f2 | xargs -I{} du -sh {}

  346M   ./Downloads/The Walking Dead S02E02 ... (dutch subs nl).avi
  159M   ./.local/share/Trash/files/funky chicken.mpg
  117M   ./Calibre Library/Robert Martin/cc.mobi
  114M   ./Dropbox/snapshots/monthly.tgz
  114M   ./Dropbox/snapshots/daily.tgz
  114M   ./Dropbox/snapshots/weekly.tgz
  76M    ./tmp/projects/onthisday/onthisday.tar.gz
  76M    ./snapshots/projects/weekly.3/onthisday/onthisday.tar.gz
  76M    ./snapshots/projects/weekly.2/onthisday/onthisday.tar.gz
  76M    ./snapshots/projects/weekly.1/onthisday/onthisday.tar.gz

and extensions count

$ find . -type f -name "*.*" | grep -o -E "\.[^\.]+$" | sort | uniq -c | sort -rn

 353 .JPG
  53 .png
  45 .mov
  33 .DS_Store
  15 .prproj
     ...
   2 .MXF
   1 .xmp
   1 .psd
   1 .mp4
   1 .md
   1 .m4a
   1 .gitignore
   1 .gitattributes

How to combine both, to get count max file size extensions?

| improve this answer | |
  • . will match things such as my.test.file.txt with the extension "test.file.txt" – ventsyv Oct 28 '15 at 3:56
0

Off the top of my head:

du -h --exclude=".git" <starting directory> | sort -h | grep -o "\.[:alnum:]+$"
| improve this answer | |
  • Answers are intended to be definitive. If you are sure this will solve the problem, consider leaving off the comment that casts doubt. If you aren't sure, then posting this as an answer is premature. Also, can you expand your answer to explain what this does? Thanks. – fixer1234 Oct 28 '15 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.