du: Add an option to print the human readable sizes in powers of 10

This commit is contained in:
Arda Cinar 2023-01-10 15:08:57 +03:00 committed by Jelle Raaijmakers
parent ae36a80a6c
commit b1c7575769
Notes: sideshowbarker 2024-07-17 01:39:12 +09:00

View File

@ -26,6 +26,7 @@ struct DuOption {
};
bool human_readable = false;
bool human_readable_si = false;
bool all = false;
bool apparent_size = false;
i64 threshold = 0;
@ -97,6 +98,7 @@ ErrorOr<void> parse_args(Main::Arguments arguments, Vector<DeprecatedString>& fi
args_parser.add_option(du_option.all, "Write counts for all files, not just directories", "all", 'a');
args_parser.add_option(du_option.apparent_size, "Print apparent sizes, rather than disk usage", "apparent-size", 0);
args_parser.add_option(du_option.human_readable, "Print human-readable sizes", "human-readable", 'h');
args_parser.add_option(du_option.human_readable_si, "Print human-readable sizes in SI units", "si", 0);
args_parser.add_option(du_option.max_depth, "Print the total for a directory or file only if it is N or fewer levels below the command line argument", "max-depth", 'd', "N");
args_parser.add_option(summarize, "Display only a total for each argument", "summarize", 's');
args_parser.add_option(du_option.threshold, "Exclude entries smaller than size if positive, or entries greater than size if negative", "threshold", 't', "size");
@ -174,6 +176,8 @@ ErrorOr<u64> print_space_usage(DeprecatedString const& path, DuOption const& du_
if (du_option.human_readable) {
out("{}", human_readable_size(size));
} else if (du_option.human_readable_si) {
out("{}", human_readable_size(size, AK::HumanReadableBasedOn::Base10));
} else {
out("{}", ceil_div(size, du_option.block_size));
}