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
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 |
0 comments:
Post a Comment