{"id":154683,"date":"2013-08-08T05:05:03","date_gmt":"2013-08-08T01:05:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=154683"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=154683","title":{"rendered":"<span class=\"post_title\">\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 bash-\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430 \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0438\u0445 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\u041d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u043e\u0432<\/li>\n<li>\u0421\u043b\u043e\u0436\u043d\u043e \u0438 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435<\/li>\n<\/ul>\n<p>  \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u0438\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043a \u0441\u0430\u043c\u044b\u043c \u043b\u0443\u0447\u0448\u0438\u043c \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e.<\/p>\n<h4>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438<\/h4>\n<p>  \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e png \u0444\u0430\u0439\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <b>optipng<\/b> \u0438 <b>pngcrush<\/b>, \u0430 \u0434\u043b\u044f jpg \u2014 <b>jpegtran<\/b>. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c optipng:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/090\/6a8\/334\/0906a8334eaf9d02f45e376eb80a3554.png\"\/><a name=\"habracut\"><\/a><\/p>\n<p>  <i>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0421 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 -o7 optipng \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0441\u0430\u043c\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u0414\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f -o0.<\/i><\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c pngcrush:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/614\/3f2\/e88\/6143f2e888fc20cbb21000fa56491854.png\"\/><\/p>\n<p>  \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f JPG \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e jpegtran:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/c5f\/92c\/400\/c5f92c4005be51445e3d15a0f11da3cc.png\"\/><\/p>\n<h4>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/h4>\n<p>  \u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/gist.github.com\/lgiraudel\/6065155\">\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 GitHub&#8217;\u0435<\/a>. \u041d\u0438\u0436\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>-i \u0438\u043b\u0438 &#8212;input \u0434\u043b\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u0438<\/li>\n<li>-o \u0438\u043b\u0438 &#8212;output \u0434\u043b\u044f \u043f\u0430\u043f\u043a\u0438 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c<\/li>\n<li>-q \u0438\u043b\u0438 &#8212;quiet \u0434\u043b\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/li>\n<li>-s \u0438\u043b\u0438 &#8212;no-stats \u0434\u043b\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438<\/li>\n<li>-h \u0438\u043b\u0438 &#8212;help \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u043f\u0440\u0430\u0432\u043a\u0438<\/li>\n<\/ul>\n<p>  \u0414\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0438 \u043f\u043e\u043b\u043d\u044b\u0445 \u0438\u043c\u0435\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<pre><code class=\"bash\">SHORTOPTS=&quot;h,i:,o:,q,s&quot; LONGOPTS=&quot;help,input:,output:,quiet,no-stats&quot; <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c getopt \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0432 \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0446\u0438\u043a\u043b \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">ARGS=$(getopt -s bash --options $SHORTOPTS --longoptions $LONGOPTS --name $PROGNAME -- &quot;$@&quot;)   eval set -- &quot;$ARGS&quot; while true; do \tcase $1 in \t\t-h|--help) \t\t\tusage \t\t\texit 0 \t\t\t;; \t\t-i|--input) \t\t\tshift \t\t\tINPUT=$1 \t\t\t;; \t\t-o|--output) \t\t\tshift \t\t\tOUTPUT=$1 \t\t\t;; \t\t-q|--quiet) \t\t\tQUIET='1' \t\t\t;; \t\t-s|--no-stats) \t\t\tNOSTATS='1' \t\t\t;; \t\t--) \t\t\tshift \t\t\tbreak \t\t\t;; \t\t*) \t\t\tshift \t\t\tbreak \t\t\t;; \tesac \tshift done <\/code><\/pre>\n<\/div>\n<\/div>\n<h4>HELP<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<ul>\n<li>usage(), \u0432 \u0446\u0438\u043a\u043b\u0435, \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u043f\u0440\u0430\u0432\u043a\u0438 <\/li>\n<li>main() \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439<\/li>\n<\/ul>\n<p>  \u041e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u0434\u043e \u0446\u0438\u043a\u043b\u0430.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">PROGNAME=${0##*\/}  usage() {   cat &lt;&lt;EO Usage: $PROGNAME [options]   Script to optimize JPG and PNG images in a directory.   Options: EO cat &lt;&lt;EO | column -s\\& -t \t-h, --help  \t   & shows this help \t-q, --quiet \t   & disables output \t-i, --input [dir]  & specify input directory (current directory by default) \t-o, --output [dir] & specify output directory (&quot;output&quot; by default) \t-ns, --no-stats    & no stats at the end EO }  SHORTOPTS=&quot;h,i:,o:,q,s&quot; LONGOPTS=&quot;help,input:,output:,quiet,no-stats&quot; ARGS=$(getopt -s bash --options $SHORTOPTS --longoptions $LONGOPTS --name $PROGNAME -- &quot;$@&quot;) <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. <\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/829\/31e\/e9f\/82931ee9f0e45cb86314b33202281af8.png\"\/><\/p>\n<p>  <i>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u0440\u043e\u0434\u0435 &quot;.\/optimize.sh: line 2: $&#8217;\\r&#8217;: command not found&quot;, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 Sublime Text 2 \u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c Unix Mode \u0432 View &gt; Line endings &gt; Unix.<\/i><\/p>\n<h4>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (main)<\/h4>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">main() { \t# If $INPUT is empty, then we use current directory \tif [[ &quot;$INPUT&quot; == &quot;&quot; ]]; then \t\tINPUT=$(pwd) \tfi   \t# If $OUTPUT is empty, then we use the directory &quot;output&quot; in the current directory \tif [[ &quot;$OUTPUT&quot; == &quot;&quot; ]]; then \t\tOUTPUT=$(pwd)\/output \tfi   \t# We create the output directory \tmkdir -p $OUTPUT   \t# To avoid some troubles with filename with spaces, we store the current IFS (Internal File Separator)... \tSAVEIFS=$IFS \t# ...and we set a new one \tIFS=$(echo -en &quot;\\n\\b&quot;)   \tmax_filelength=`get_max_file_length` \tpad=$(printf '%0.1s' &quot;.&quot;{1..600}) \tsDone=' [ DONE ]' \tlinelength=$(expr $max_filelength + ${#sDone} + 5)   \t# Search of all jpg\/jpeg\/png in $INPUT \t# We remove images from $OUTPUT if $OUTPUT is a subdirectory of $INPUT \tIMAGES=$(find $INPUT -regextype posix-extended -regex '.*\\.(jpg|jpeg|png)' | grep -v $OUTPUT)   \tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\techo --- Optimizing $INPUT --- \t\techo \tfi \tfor CURRENT_IMAGE in $IMAGES; do \t\tfilename=$(basename $CURRENT_IMAGE) \t\tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\t    printf '%s ' &quot;$filename&quot; \t\t    printf '%*.*s' 0 $((linelength - ${#filename} - ${#sDone} )) &quot;$pad&quot; \t\tfi   \t\toptimize_image $CURRENT_IMAGE $OUTPUT\/$filename   \t\tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\t    printf '%s\\n' &quot;$sDone&quot; \t\tfi \tdone   \t# we restore the saved IFS \tIFS=$SAVEIFS   \tif [ &quot;$NOSTATS&quot; == &quot;0&quot; -a &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\techo \t\techo &quot;Input: &quot; $(human_readable_filesize $max_input_size) \t\techo &quot;Output: &quot; $(human_readable_filesize $max_output_size) \t\tspace_saved=$(expr $max_input_size - $max_output_size) \t\techo &quot;Space save: &quot; $(human_readable_filesize $space_saved) \tfi } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438, \u043b\u0438\u0431\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0443 mkdir. \u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f\u0445 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u0435\u043b\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c IFS (Internal File Separator). \u0424\u0443\u043d\u043a\u0446\u0438\u044f optimize_image, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u2014 \u0434\u043b\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439.<\/p>\n<p>  <b>optimize_image:<\/b><\/p>\n<pre><code class=\"bash\"># $1: input image # $2: output image  optimize_image() { \tinput_file_size=$(stat -c%s &quot;$1&quot;) \tmax_input_size=$(expr $max_input_size + $input_file_size)   \tif [ &quot;${1##*.}&quot; = &quot;png&quot; ]; then \t\toptipng -o1 -clobber -quiet $1 -out $2 \t\tpngcrush -q -rem alla -reduce $1 $2 &gt;\/dev\/null \tfi \tif [ &quot;${1##*.}&quot; = &quot;jpg&quot; -o &quot;${1##*.}&quot; = &quot;jpeg&quot; ]; then \t\tjpegtran -copy none -progressive $1 &gt; $2 \tfi   \toutput_file_size=$(stat -c%s &quot;$2&quot;) \tmax_output_size=$(expr $max_output_size + $output_file_size) } <\/code><\/pre>\n<h4>\u0412\u044b\u0445\u043e\u0434\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">file1 ...................... [ DONE ] file2 ...................... [ DONE ] file_with_a_long_name ...... [ DONE ] ... <\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u043b\u0438\u043d\u044b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u0444\u0430\u0439\u043b\u043e\u0432<\/li>\n<li>\u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438<\/li>\n<li>\u0417\u0430\u0434\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0430 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0438 \u0442\u0435\u043a\u0441\u0442\u0430 &quot; [ DONE ]&quot;<\/li>\n<\/ol>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430, \u0442\u043e\u0447\u043a\u0438 \u0438 DONE \u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">max_filelength=`get_max_file_length` \tpad=$(printf '%0.1s' &quot;.&quot;{1..600}) \tsDone=' [ DONE ]' \tlinelength=$(expr $max_filelength + ${#sDone} + 5)   \t# Search of all jpg\/jpeg\/png in $INPUT \t# We remove images from $OUTPUT if $OUTPUT is a subdirectory of $INPUT \tIMAGES=$(find $INPUT -regextype posix-extended -regex '.*\\.(jpg|jpeg|png)' | grep -v $OUTPUT)   \tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\techo --- Optimizing $INPUT --- \t\techo \tfi \tfor CURRENT_IMAGE in $IMAGES; do \t\tfilename=$(basename $CURRENT_IMAGE) \t\tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\t    printf '%s ' &quot;$filename&quot; \t\t    printf '%*.*s' 0 $((linelength - ${#filename} - ${#sDone} )) &quot;$pad&quot; \t\tfi   \t\toptimize_image $CURRENT_IMAGE $OUTPUT\/$filename   \t\tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\t    printf '%s\\n' &quot;$sDone&quot; \t\tfi \tdone <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<pre><code class=\"bash\"># All parameters to default .\/optimize.sh # Or with custom options .\/optimize.sh --input images --output optimized-images # Or with custom options and shorthand .\/optimize.sh -i images -o optimized-images <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/34b\/c05\/306\/34bc053065bdb0efeeb3cfd4dec77712.png\"\/><\/p>\n<h4>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430<\/h4>\n<p>  \u0414\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c input_file_size \u0438 output_file_size, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"http:\/\/unix.stackexchange.com\/questions\/44040\/a-standard-tool-to-convert-a-byte-count-into-human-kib-mib-etc-like-du-ls1\">human_readable_filesize()<\/a>.<\/p>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0435\u0449\u0435 \u0440\u0430\u0437 \u0438 \u0432\u0438\u0434\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/28f\/f84\/5e2\/28ff845e2233656ea54551be30cf2a28.png\"\/><\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"bash\">if [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\techo --- Optimizing $INPUT --- \t\techo \tfi \tfor CURRENT_IMAGE in $IMAGES; do \t\tfilename=$(basename $CURRENT_IMAGE) \t\tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\t    printf '%s ' &quot;$filename&quot; \t\t    printf '%*.*s' 0 $((linelength - ${#filename} - ${#sDone} )) &quot;$pad&quot; \t\tfi   \t\toptimize_image $CURRENT_IMAGE $OUTPUT\/$filename   \t\tif [ &quot;$QUIET&quot; == &quot;0&quot; ]; then \t\t    printf '%s\\n' &quot;$sDone&quot; \t\tfi \tdone <\/code><\/pre>\n<p>  \u0412\u0441\u0435! \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. <a href=\"https:\/\/gist.github.com\/lgiraudel\/6065155\">\u0421\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u0430 GitHub&#8217;\u0435<\/a>.   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/154683\/\"> http:\/\/habrahabr.ru\/post\/154683\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430 \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0438\u0445 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\u041d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u043e\u0432<\/li>\n<li>\u0421\u043b\u043e\u0436\u043d\u043e \u0438 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435<\/li>\n<\/ul>\n<p>  \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u0438\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043a \u0441\u0430\u043c\u044b\u043c \u043b\u0443\u0447\u0448\u0438\u043c \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e.<\/p>\n<h4>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438<\/h4>\n<p>  \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e png \u0444\u0430\u0439\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <b>optipng<\/b> \u0438 <b>pngcrush<\/b>, \u0430 \u0434\u043b\u044f jpg \u2014 <b>jpegtran<\/b>. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c optipng:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/090\/6a8\/334\/0906a8334eaf9d02f45e376eb80a3554.png\"\/><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-154683","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/154683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154683"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/154683\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}