Find the Total Size of All Files With Certain Extension with one Line
By George El. • January 2019 •
Reading time: 2 minutes
find all files with a certain extension in current directory and add the file sizes to calculate total file size in Mbytes
find . -iname "*.txt" | xargs ls -l | awk '{print $5 }' | paste -sd+ | bc | awk '{print $1/1024/1024 }' the above example finds all files ending in txt, starting from the current directory.
Using Linux Awk
By George El. • October 2018 •
Reading time: 3 minutes
awk is a utility that automatically splits lines on white space or tabs into columns and also features a full programming language
$ ls -la total 4 drwxrwxr-x 2 geo geo 159 Jan 3 12:13 . drwxr-xr-x. 7 geo geo 4096 Jan 2 14:50 .. -rw-rw-r-- 1 geo geo 0 Jan 2 11:07 file1.