Я сделал утилиту Python, которая может сделать мудрое строкой объединение, пересечение, различие и продукт нескольких файлов. Это назвало SetOp, можно найти его на PyPI (здесь). Синтаксис похож на это:
$ setop -i file1 file2 file3 # intersection
$ setop -d file1 file2 file3 # difference
Если можно использовать GNU, находят (не встроил Linux или Cygwin), сделать find
распечатайте размеры файла и выполните последующую обработку вывод с awk
отсортировать каждый размер в категорию, sort
и uniq
сгруппироваться категориями, и awk
или sed
к структурной распечатке программы результат. Что-то как:
find /usr/opt -type f -printf '%s\n' |
awk '{
if ($1 ~ /^[2-9]......../) { print "3 G" }
else if ($1 >= 1073741824) { print "3 G" }
else if ($1 >= 1048576) { print "2 M" }
else if ($1 >= 1024) { print "1 k" }
else if ($1 >= 1) { print "0" }
}' |
sort | uniq -c |
awk '{print $1 " files are in the " $3 "B range"}'
Лучшее, которое я придумал, должно было обратиться к awk сценарию.
{
if ( substr( $5, length($5), length($5) ) == "K" ) {
totK++;
totKsize = totKsize + substr($5, 0, length($5) - 1 );}
else if ( substr( $5, length($5), length($5) ) == "M" ) {
totM++;
totMsize = totMsize + substr($5, 0, length($5) - 1 );}
else if ( substr( $5, length($5), length($5) ) == "G" ) {
totG++;
totGsize = totGsize + substr($5, 0, length($5) - 1 );}
else {
totB++;
totBsize=totBsize + $5; }
}
END{
print "NR of files less than 1k => " totB " total " totBsize;
print "NR of files less than 1M => " totK " total " totKsize;
print "NR of files less than 1G => " totM " total " totMsize;
print "NR of files bigger than 1G => " totG " total " totGsize;
}
И выполните передачу как это:
find . -type f |xargs ls -lh |/usr/xpg4/bin/awk -f count_files.awk