Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measure disk space of certain file types in aggregate

I have some files across several folders:

/home/d/folder1/a.txt /home/d/folder1/b.txt /home/d/folder1/c.mov /home/d/folder2/a.txt /home/d/folder2/d.mov /home/d/folder2/folder3/f.txt 

How can I measure the grand total amount of disk space taken up by all the .txt files in /home/d/?

I know du will give me the total space of a given folder, and ls -l will give me the total space of individual files, but what if I want to add up all the txt files and just look at the space taken by all .txt files in one giant total for all .txt in /home/d/ including both folder1 and folder2 and their subfolders like folder3?

like image 994
Dan Avatar asked Aug 31 '09 19:08

Dan


People also ask

How do I see multiple file sizes in Linux?

To get the total size of a directory in Linux, you can use the du (disk-usage) command.

What command is used to estimate file space usage it will summarize disk usage of the set of files recursively for directories?

The du command estimate file space usage and summarize disk usage of each FILE, recursively for directories. It displays the file system block usage for each file argument and for each directory in the file hierarchy rooted in each direc tory argument.

Which command can be used to eports the amount of disk space in use for the files or directories you specify?

'du' command in Linux We can get the total disk usage size for the underlying directory with the command 'du -sh'. We can see in the out total 3.6GB.


2 Answers

find folder1 folder2 -iname '*.txt' -print0 | du --files0-from - -c -s | tail -1

like image 86
Barry Kelly Avatar answered Oct 05 '22 03:10

Barry Kelly


This will report disk space usage in bytes by extension:

find . -type f -printf "%f %s\n" |   awk '{       PARTSCOUNT=split( $1, FILEPARTS, "." );       EXTENSION=PARTSCOUNT == 1 ? "NULL" : FILEPARTS[PARTSCOUNT];       FILETYPE_MAP[EXTENSION]+=$2     }    END {      for( FILETYPE in FILETYPE_MAP ) {        print FILETYPE_MAP[FILETYPE], FILETYPE;       }    }' | sort -n 

Output:

3250 png 30334451 mov 57725092729 m4a 69460813270 3gp 79456825676 mp3 131208301755 mp4 
like image 22
Barn Avatar answered Oct 05 '22 02:10

Barn