Python for Network Engineers

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 Find Command

By George El. • November 2018 • Reading time: 3 minutes

The find command allows to find files based on various criteria, some of which are: maxdepth : the number of directories depth type f : files type d: directories name : the name of the files like “*.txt” iname : same as above but ignore case size +10M : find files overs 10Mbytes size -5k: find files less than 5Kbytes size +1G : find files larger than 1gig mtime -7 : shows files modified last 7 days mtime -30 : shows files modified last 30 days ok prompt the user for permission Examples copy all files from /home/geo/temp to /tmp (you can also use xargs)