Skip to content

Instantly share code, notes, and snippets.

@Busyrev
Last active December 3, 2018 08:20
Show Gist options
  • Save Busyrev/1e41c58ad081cf861c167eee3f554ea9 to your computer and use it in GitHub Desktop.
Save Busyrev/1e41c58ad081cf861c167eee3f554ea9 to your computer and use it in GitHub Desktop.
Хинты для работы с *nix command line

Суммарный вес png в мегабайтах, рекурсивно
find . -type f -iname \*.png -ls | awk '{a+=$7}END{print a/1024/1024}'
Суммарная площадь png в мегапикселях, рекурсивно
find . -type f -iname \*.png | xargs file | awk '{a+=$5*$7}END{print a/1024/1024}'
Количество png, рекурсивно
find . -type f -iname \*.png | wc -l
Скопировать все png в отдельное место, рекурсивно
find . -type f -iname "*.png" -exec cp {} ./pngs \;
выбрать самый большой png по размеру
find . -type f -iname \*.png -printf "%s\t%p\n" | sort -n | tail -1
Собрать json array из содержимого текстовых файлов, рекурсивно
find . -type f -iname \*.eee | perl -e 'print "["; my @a; while(<>){ local $/ = undef; open my $fh, "< $_"; push(@a, <$fh>);} print join(",", @a) . "]"' > meta.json
Используя xargs просунуть переданное значение в несколько мест
echo a b c | xargs -n1 -I% echo %.zzz %.asdf
Найти все логи, взять последнюю строчку, от неё взять первое число, отсортировать и сложить в файл
find . -type f -name log.txt | xargs -n1 tail -n1 | awk '{print $1}' | sort -n > times.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment