AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Find file size program2/29/2024 The good news is I can sort the output in any order I want by passing sort -k1 -rh as input. That way, it's even easier to read at a glance. While this output is good, it would be even better to sort it by capacity. Here's the sample output from my usual du command: $ du -ahx -max-depth=1 /var Unlike the -one-file-system option, the size reported remains the same with this option I just don't have to see as much output. If you use 2 instead, it prints folders two levels below /var. -max-depth=1 ( -d): Print the total for a directory (or file, with -all) only if it is, in this case, one level below /var.This ensures I see the disk space used under only one directory path and not across physical media. The result is that if /var/log is mounted separately, it isn't counted because it's on a separate filesystem. -one-file-system ( -x): Skip directories on different filesystems.-human-readable ( -h): Print sizes in big chunks rather than in bytes (for instance, 1K instead of 1024).Here is a breakdown of each option (with the short version in parentheses):ĭownload now -all ( -a): Print all files and folders. Here's my standard du command, with long options for clarity: $ du -all -human-readable \ Suppose I want to check all directories in /var. This way, I know which directories are my biggest offenders. I usually like to check the usage of multiple directories simultaneously. Here is one of my favorite tricks with du. For all of the options, refer to the du man page. It offers many helpful options individually or in the correct combinations. The du command summarizes disk usage of each file and recursively for each directory. My favorite command for this type of data gathering is the du command. This knowledge allows you to plan for storage upgrades, manage and rotate files, and do other necessary sysadmin tasks. Knowing how much space a file or folder consumes on a partition is essential for a system administrator or developer. How well do you know Linux? Take a quiz and get a badge.Linux system administration skills assessment.A guide to installing applications on Linux.Download RHEL 9 at no charge through the Red Hat Developer program.So, we had to exert more effort to get a less accurate result. So, we do the calculation 198 * 2^20 = 198 * 1048576 = 207618048, which gives us a rough estimate of the actual 207270832, rounded to the closest Mebibyte. Now, does M stand for Mega (10^6) or Mebi (2^20)? We have to check the documentation, which tells us that it’s the latter. With the -h or –human-readable flag, ls shows 198M instead of 207270832 bytes. rwxr-xr-x 1 baeldung baeldung 198M Jun 10 06:23 /dir/file Hence, it’s not really a value we’re after.įinally, many applications provide a way for users to see human-readable instead of raw byte values: $ ls -l /dir/file This is a common minimum allocation unit on filesystems. Importantly, the number of blocks differs from the total number in bytes, as blocks are based on values defined during partition filesystem formatting.Īlso, the directory entry, as identified by the d prefix, has a byte value of 4096. However, with the -l long list format, it also displays the total number of blocks all files take at the top of its output. In the code snippet above, the fifth column of ls shows the size of each file in bytes. rw-r-r- 1 baeldung baeldung 660 Jul 29 11:20 file4ĭrwxr-xr-x 2 baeldung baeldung 4096 Aug 18 18:16 subdir rw-r-r- 1 baeldung baeldung 160 Oct 29 05:10 file3 rw-r-r- 1 baeldung baeldung 565 Oct 19 16:50 file2 rw-r-r- 1 baeldung baeldung 666 Oct 18 15:10 file1
0 Comments
Read More
Leave a Reply. |