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?
To get the total size of a directory in Linux, you can use the du (disk-usage) command.
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.
'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.
find folder1 folder2 -iname '*.txt' -print0 | du --files0-from - -c -s | tail -1
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With