Friday, 23 August 2013

Check the size of Files that Matches a Pattern

How to check the total size of files matching a pattern. (Linux)

To find files along with their sizes, in a directory ( including sub-directories) matching a specific pattern,
Use the below command.
?
1
find . -name "pattern" -ls
The 7th column shows the size of the file.
example
?
1
find . -name "*20120127_0259.zip" -ls
22612310    8 -rw-r--r--   1 root     root         4691 Jan 26 18:59 ./1789/stats_1789_1790_20120127_0259.zip
22612344   36 -rw-r--r--   1 root     root        36293 Jan 26 18:59 ./1789/stats_1789_1797_20120127_0259.zip
22612348   80 -rw-r--r--   1 root     root        77241 Jan 26 18:59 ./1789/stats_1789_1761_20120127_0259.zip
22612243    4 -rw-r--r--   1 root     root          884 Jan 26 18:59 ./1789/stats_1789_1818_20120127_0259.zip
13534698   32 -rw-r--r--   1 root     root        30533 Jan 26 18:59 ./17/stats_17_9264_20120127_0259.zip
13534592   12 -rw-r--r--   1 root     root        10037 Jan 26 18:59 ./17/stats_17_9289_20120127_0259.zip
To find the total size of all such files.
?
1
find . -name "pattern" -ls | awk '{total += $7} END {print total}'
example
?
1
2
find . -name "*20120127_0259.zip" -ls | awk '{total += $7} END {print total}'
1088968

Related Posts:

  • Install Windows XP on MAC using BOOT CAMP software.... make sure you have a blank, burnable CD disk on hand.Now, download Boot Camp from the Apple site and double click on the “.dmg” disk image… Read More
  • Reset Password in MACBOOK MAC OS X The good news is that it’s pretty straightforward to reset your password on a Mac OS X system if you have an install disk handy, but the bad news is… Read More
  • Find Files in LINUX The find command locates files in many different ways. Unlike the rest of the commands in this section, find does not look at the… Read More
  • Firefox OS Research in Motion has Android, Windows Phone, and iOS firmly in its sights, but Mozilla is targeting thebudget sector with its Firefox… Read More
  • Ubuntu for phones Ubuntu for Mobile Ubuntu may be a familiar name in Linux-loving desktop software circles, but it’s an unknown in the mobile world. This h… Read More

0 comments:

Post a Comment