I'm trying to figure out how much space all my JPGs within a particular directory ('Personal Drive') are taking up. I figure there is a command line command to accomplish this.
You might be able to use the du command ...
du -ch *.jpg
Found it.
ls -lR | grep .jpg | awk '{sum = sum + $5} END {print sum}'
As I understand it:
ls
says list all the files in the directory. -l
flag says show me more details like owner, permissions, and file size.tacking on R
to that flag says 'do this recursively'.
Piping that to grep .jpg
allows only the output from ls
that contains '.jpg' to continue on to the next phase.
Piping that output to awk '{sum = sum + $5} END {print sum}'
says take each line and pull its fifth column element (file size in this case) and add that value to our variable sum. If we reach the end of the list, print that variables value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With