Walker News

How To Display Total File Size In Linux Command Prompt?

In Linux command prompt, you can use the du command with appropriate option switch to easily display a summary of total file size for selected files, in addition to printing individual file’s size.

Say for example, you have a directory to keep daily image backup files that stick to a naming convention as IB-mmddyy.

1) To check the total file size of files created in May 2009:
du -ch IB-05??09 | grep total 

Using du command to show total file size of some selected files in Linux command prompt.

The option switch -c and -h (or combined as -ch) instruct du to print a grand total of file size (-c option switch) in a human readable format (-h option switch).

2) To check total file size of files in each month of year 2009, you can manually execute the du sample command at above for each month, one by one:
du -ch IB-01??09 | grep total
du -ch IB-02??09 | grep total

Or, write a simple shell script to automatically execute a series of du -sh command:

declare -i i=1
declare    j=''

until [ $i -gt 12 ]
  [ `echo $i | wc -c` -eq 2 ] && j='0'$i || j=$i
  echo Mth $j : `du -ch IB-$j??09 | grep total`
  let i++

Custom Search

2018  •  Privacy Policy