touch & gzip all HTML, CSS, JS files in a directory recursively

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I'm trying to optimize Nginx server. I've enabled Gzip_Static_Module to serve pre-compressed gzip static files like CSS, JS, HTML.



Nginx Wiki says that the timestamps of the compressed and uncompressed files match. So, I'm trying to touch the files before Gzipping.



I'm trying to touch and generate *.gz for these static files using the commands below:



$ su -c "find . -type f -name "*.css" -size +1024b -exec sh -c "touch 
&& gzip -9v < > .gz" ;"

$ su -c "find . -type f -name "*.js" -size +1024b -exec sh -c "touch
&& gzip -9v < > .gz" ;"

$ su -c "find . -type f -name "*.html" -size +1024b -exec sh -c "touch
&& gzip -9v < > .gz" ;"


but I receive "User not found" error.



Can anyone please help me what's wrong in the above command? And is there any better approach for generating *.gz automatically, whenever the timestamp of any uncompressed file changes (Cronjob may be)?










share|improve this question



























    up vote
    2
    down vote

    favorite












    I'm trying to optimize Nginx server. I've enabled Gzip_Static_Module to serve pre-compressed gzip static files like CSS, JS, HTML.



    Nginx Wiki says that the timestamps of the compressed and uncompressed files match. So, I'm trying to touch the files before Gzipping.



    I'm trying to touch and generate *.gz for these static files using the commands below:



    $ su -c "find . -type f -name "*.css" -size +1024b -exec sh -c "touch 
    && gzip -9v < > .gz" ;"

    $ su -c "find . -type f -name "*.js" -size +1024b -exec sh -c "touch
    && gzip -9v < > .gz" ;"

    $ su -c "find . -type f -name "*.html" -size +1024b -exec sh -c "touch
    && gzip -9v < > .gz" ;"


    but I receive "User not found" error.



    Can anyone please help me what's wrong in the above command? And is there any better approach for generating *.gz automatically, whenever the timestamp of any uncompressed file changes (Cronjob may be)?










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm trying to optimize Nginx server. I've enabled Gzip_Static_Module to serve pre-compressed gzip static files like CSS, JS, HTML.



      Nginx Wiki says that the timestamps of the compressed and uncompressed files match. So, I'm trying to touch the files before Gzipping.



      I'm trying to touch and generate *.gz for these static files using the commands below:



      $ su -c "find . -type f -name "*.css" -size +1024b -exec sh -c "touch 
      && gzip -9v < > .gz" ;"

      $ su -c "find . -type f -name "*.js" -size +1024b -exec sh -c "touch
      && gzip -9v < > .gz" ;"

      $ su -c "find . -type f -name "*.html" -size +1024b -exec sh -c "touch
      && gzip -9v < > .gz" ;"


      but I receive "User not found" error.



      Can anyone please help me what's wrong in the above command? And is there any better approach for generating *.gz automatically, whenever the timestamp of any uncompressed file changes (Cronjob may be)?










      share|improve this question















      I'm trying to optimize Nginx server. I've enabled Gzip_Static_Module to serve pre-compressed gzip static files like CSS, JS, HTML.



      Nginx Wiki says that the timestamps of the compressed and uncompressed files match. So, I'm trying to touch the files before Gzipping.



      I'm trying to touch and generate *.gz for these static files using the commands below:



      $ su -c "find . -type f -name "*.css" -size +1024b -exec sh -c "touch 
      && gzip -9v < > .gz" ;"

      $ su -c "find . -type f -name "*.js" -size +1024b -exec sh -c "touch
      && gzip -9v < > .gz" ;"

      $ su -c "find . -type f -name "*.html" -size +1024b -exec sh -c "touch
      && gzip -9v < > .gz" ;"


      but I receive "User not found" error.



      Can anyone please help me what's wrong in the above command? And is there any better approach for generating *.gz automatically, whenever the timestamp of any uncompressed file changes (Cronjob may be)?







      find nginx gzip






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 27 '14 at 18:47









      slm♦

      239k65495665




      239k65495665










      asked Apr 27 '14 at 18:29









      Ronak

      1256




      1256




















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          I think you're running into a quoting issue because you've got double quotes contained inside the command you're trying to get su -c ... to execute. You might want to try wrapping the whole thing inside single quotes instead.



          $ su -c 'find . -type f -name "*.css" -size +1024b -exec sh -c "touch && 
          gzip -9v < > .gz" ;'


          You can also escape these contained double quotes but this often can become messy to debug so I'd avoid that, but depending on your style/taste preferences is another option as well.






          share|improve this answer
















          • 1




            or putting all the commands into a script that is executed via 'sudo new-script'. Sure it is not a one-liner, but it will save you from all the layered quoting issues. (sudo is far perferred over su)
            – mdpc
            Apr 28 '14 at 1:42


















          up vote
          1
          down vote













          Why do you want to "touch" the file before calling gzip?



          From gzip's man page:




          Gzip reduces the size of the named files using Lempel-Ziv coding
          (LZ77). Whenever possible, each file is replaced by one with the
          extension .gz, while keeping the same ownership modes, access and
          modification times.




          You don't have to touch the file at all, simply run:



          $ su -c "find . -type f -name "*.css" -size +1024b -exec gzip -9vk '' ;



          I've used the -k option of gzip which will keep the original file around after compression. This option has been introduced in version 1.6 of gzip.






          share|improve this answer



























            up vote
            0
            down vote













            A more concise way:



            DIR=/var/www
            gzip -rk9 $DIR &&
            find $DIR -not -name '*.gz' -type f -exec touch -r .gz ;


            This gzips everything (at the 'best' level) in your www dir, then uses touch to set the mtime & atime of the gzip to that of the corresponding source file (as the nginx docs suggest).






            share|improve this answer



























              up vote
              -1
              down vote













              My version is:



              IFS=$'' find $DIR -type f -iname *.html -or -iname *.css -or -iname *.js | while read fn; do gzip -9vk -- "$fn" && touch -r "$fn" "$fn.gz"; done



              Update



              gzip actually keeps mod time needed by nginx to check if content is the same, so a simpler one liner is sufficient:



              find public/ -type f -iname *.html -or -iname *.css -or -iname *.js -or -iname *.xml -print0 | xargs --null --no-run-if-empty --verbose gzip -9vk --






              share|improve this answer





























                up vote
                -1
                down vote













                find dist -type f -exec sh -c "gzip < '' > ''.gz" ;





                share|improve this answer






















                  Your Answer







                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "106"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  convertImagesToLinks: false,
                  noModals: false,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                   

                  draft saved


                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f126794%2ftouch-gzip-all-html-css-js-files-in-a-directory-recursively%23new-answer', 'question_page');

                  );

                  Post as a guest






























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  1
                  down vote



                  accepted










                  I think you're running into a quoting issue because you've got double quotes contained inside the command you're trying to get su -c ... to execute. You might want to try wrapping the whole thing inside single quotes instead.



                  $ su -c 'find . -type f -name "*.css" -size +1024b -exec sh -c "touch && 
                  gzip -9v < > .gz" ;'


                  You can also escape these contained double quotes but this often can become messy to debug so I'd avoid that, but depending on your style/taste preferences is another option as well.






                  share|improve this answer
















                  • 1




                    or putting all the commands into a script that is executed via 'sudo new-script'. Sure it is not a one-liner, but it will save you from all the layered quoting issues. (sudo is far perferred over su)
                    – mdpc
                    Apr 28 '14 at 1:42















                  up vote
                  1
                  down vote



                  accepted










                  I think you're running into a quoting issue because you've got double quotes contained inside the command you're trying to get su -c ... to execute. You might want to try wrapping the whole thing inside single quotes instead.



                  $ su -c 'find . -type f -name "*.css" -size +1024b -exec sh -c "touch && 
                  gzip -9v < > .gz" ;'


                  You can also escape these contained double quotes but this often can become messy to debug so I'd avoid that, but depending on your style/taste preferences is another option as well.






                  share|improve this answer
















                  • 1




                    or putting all the commands into a script that is executed via 'sudo new-script'. Sure it is not a one-liner, but it will save you from all the layered quoting issues. (sudo is far perferred over su)
                    – mdpc
                    Apr 28 '14 at 1:42













                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  I think you're running into a quoting issue because you've got double quotes contained inside the command you're trying to get su -c ... to execute. You might want to try wrapping the whole thing inside single quotes instead.



                  $ su -c 'find . -type f -name "*.css" -size +1024b -exec sh -c "touch && 
                  gzip -9v < > .gz" ;'


                  You can also escape these contained double quotes but this often can become messy to debug so I'd avoid that, but depending on your style/taste preferences is another option as well.






                  share|improve this answer












                  I think you're running into a quoting issue because you've got double quotes contained inside the command you're trying to get su -c ... to execute. You might want to try wrapping the whole thing inside single quotes instead.



                  $ su -c 'find . -type f -name "*.css" -size +1024b -exec sh -c "touch && 
                  gzip -9v < > .gz" ;'


                  You can also escape these contained double quotes but this often can become messy to debug so I'd avoid that, but depending on your style/taste preferences is another option as well.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 27 '14 at 18:44









                  slm♦

                  239k65495665




                  239k65495665







                  • 1




                    or putting all the commands into a script that is executed via 'sudo new-script'. Sure it is not a one-liner, but it will save you from all the layered quoting issues. (sudo is far perferred over su)
                    – mdpc
                    Apr 28 '14 at 1:42













                  • 1




                    or putting all the commands into a script that is executed via 'sudo new-script'. Sure it is not a one-liner, but it will save you from all the layered quoting issues. (sudo is far perferred over su)
                    – mdpc
                    Apr 28 '14 at 1:42








                  1




                  1




                  or putting all the commands into a script that is executed via 'sudo new-script'. Sure it is not a one-liner, but it will save you from all the layered quoting issues. (sudo is far perferred over su)
                  – mdpc
                  Apr 28 '14 at 1:42





                  or putting all the commands into a script that is executed via 'sudo new-script'. Sure it is not a one-liner, but it will save you from all the layered quoting issues. (sudo is far perferred over su)
                  – mdpc
                  Apr 28 '14 at 1:42













                  up vote
                  1
                  down vote













                  Why do you want to "touch" the file before calling gzip?



                  From gzip's man page:




                  Gzip reduces the size of the named files using Lempel-Ziv coding
                  (LZ77). Whenever possible, each file is replaced by one with the
                  extension .gz, while keeping the same ownership modes, access and
                  modification times.




                  You don't have to touch the file at all, simply run:



                  $ su -c "find . -type f -name "*.css" -size +1024b -exec gzip -9vk '' ;



                  I've used the -k option of gzip which will keep the original file around after compression. This option has been introduced in version 1.6 of gzip.






                  share|improve this answer
























                    up vote
                    1
                    down vote













                    Why do you want to "touch" the file before calling gzip?



                    From gzip's man page:




                    Gzip reduces the size of the named files using Lempel-Ziv coding
                    (LZ77). Whenever possible, each file is replaced by one with the
                    extension .gz, while keeping the same ownership modes, access and
                    modification times.




                    You don't have to touch the file at all, simply run:



                    $ su -c "find . -type f -name "*.css" -size +1024b -exec gzip -9vk '' ;



                    I've used the -k option of gzip which will keep the original file around after compression. This option has been introduced in version 1.6 of gzip.






                    share|improve this answer






















                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      Why do you want to "touch" the file before calling gzip?



                      From gzip's man page:




                      Gzip reduces the size of the named files using Lempel-Ziv coding
                      (LZ77). Whenever possible, each file is replaced by one with the
                      extension .gz, while keeping the same ownership modes, access and
                      modification times.




                      You don't have to touch the file at all, simply run:



                      $ su -c "find . -type f -name "*.css" -size +1024b -exec gzip -9vk '' ;



                      I've used the -k option of gzip which will keep the original file around after compression. This option has been introduced in version 1.6 of gzip.






                      share|improve this answer












                      Why do you want to "touch" the file before calling gzip?



                      From gzip's man page:




                      Gzip reduces the size of the named files using Lempel-Ziv coding
                      (LZ77). Whenever possible, each file is replaced by one with the
                      extension .gz, while keeping the same ownership modes, access and
                      modification times.




                      You don't have to touch the file at all, simply run:



                      $ su -c "find . -type f -name "*.css" -size +1024b -exec gzip -9vk '' ;



                      I've used the -k option of gzip which will keep the original file around after compression. This option has been introduced in version 1.6 of gzip.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Oct 4 '14 at 23:03









                      Srinidhi

                      40625




                      40625




















                          up vote
                          0
                          down vote













                          A more concise way:



                          DIR=/var/www
                          gzip -rk9 $DIR &&
                          find $DIR -not -name '*.gz' -type f -exec touch -r .gz ;


                          This gzips everything (at the 'best' level) in your www dir, then uses touch to set the mtime & atime of the gzip to that of the corresponding source file (as the nginx docs suggest).






                          share|improve this answer
























                            up vote
                            0
                            down vote













                            A more concise way:



                            DIR=/var/www
                            gzip -rk9 $DIR &&
                            find $DIR -not -name '*.gz' -type f -exec touch -r .gz ;


                            This gzips everything (at the 'best' level) in your www dir, then uses touch to set the mtime & atime of the gzip to that of the corresponding source file (as the nginx docs suggest).






                            share|improve this answer






















                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              A more concise way:



                              DIR=/var/www
                              gzip -rk9 $DIR &&
                              find $DIR -not -name '*.gz' -type f -exec touch -r .gz ;


                              This gzips everything (at the 'best' level) in your www dir, then uses touch to set the mtime & atime of the gzip to that of the corresponding source file (as the nginx docs suggest).






                              share|improve this answer












                              A more concise way:



                              DIR=/var/www
                              gzip -rk9 $DIR &&
                              find $DIR -not -name '*.gz' -type f -exec touch -r .gz ;


                              This gzips everything (at the 'best' level) in your www dir, then uses touch to set the mtime & atime of the gzip to that of the corresponding source file (as the nginx docs suggest).







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Feb 25 '17 at 21:39









                              Nicholas White

                              1011




                              1011




















                                  up vote
                                  -1
                                  down vote













                                  My version is:



                                  IFS=$'' find $DIR -type f -iname *.html -or -iname *.css -or -iname *.js | while read fn; do gzip -9vk -- "$fn" && touch -r "$fn" "$fn.gz"; done



                                  Update



                                  gzip actually keeps mod time needed by nginx to check if content is the same, so a simpler one liner is sufficient:



                                  find public/ -type f -iname *.html -or -iname *.css -or -iname *.js -or -iname *.xml -print0 | xargs --null --no-run-if-empty --verbose gzip -9vk --






                                  share|improve this answer


























                                    up vote
                                    -1
                                    down vote













                                    My version is:



                                    IFS=$'' find $DIR -type f -iname *.html -or -iname *.css -or -iname *.js | while read fn; do gzip -9vk -- "$fn" && touch -r "$fn" "$fn.gz"; done



                                    Update



                                    gzip actually keeps mod time needed by nginx to check if content is the same, so a simpler one liner is sufficient:



                                    find public/ -type f -iname *.html -or -iname *.css -or -iname *.js -or -iname *.xml -print0 | xargs --null --no-run-if-empty --verbose gzip -9vk --






                                    share|improve this answer
























                                      up vote
                                      -1
                                      down vote










                                      up vote
                                      -1
                                      down vote









                                      My version is:



                                      IFS=$'' find $DIR -type f -iname *.html -or -iname *.css -or -iname *.js | while read fn; do gzip -9vk -- "$fn" && touch -r "$fn" "$fn.gz"; done



                                      Update



                                      gzip actually keeps mod time needed by nginx to check if content is the same, so a simpler one liner is sufficient:



                                      find public/ -type f -iname *.html -or -iname *.css -or -iname *.js -or -iname *.xml -print0 | xargs --null --no-run-if-empty --verbose gzip -9vk --






                                      share|improve this answer














                                      My version is:



                                      IFS=$'' find $DIR -type f -iname *.html -or -iname *.css -or -iname *.js | while read fn; do gzip -9vk -- "$fn" && touch -r "$fn" "$fn.gz"; done



                                      Update



                                      gzip actually keeps mod time needed by nginx to check if content is the same, so a simpler one liner is sufficient:



                                      find public/ -type f -iname *.html -or -iname *.css -or -iname *.js -or -iname *.xml -print0 | xargs --null --no-run-if-empty --verbose gzip -9vk --







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited May 11 '17 at 12:26

























                                      answered May 11 '17 at 12:16









                                      user348878

                                      11




                                      11




















                                          up vote
                                          -1
                                          down vote













                                          find dist -type f -exec sh -c "gzip < '' > ''.gz" ;





                                          share|improve this answer


























                                            up vote
                                            -1
                                            down vote













                                            find dist -type f -exec sh -c "gzip < '' > ''.gz" ;





                                            share|improve this answer
























                                              up vote
                                              -1
                                              down vote










                                              up vote
                                              -1
                                              down vote









                                              find dist -type f -exec sh -c "gzip < '' > ''.gz" ;





                                              share|improve this answer














                                              find dist -type f -exec sh -c "gzip < '' > ''.gz" ;






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Sep 19 at 20:44









                                              Goro

                                              6,16552763




                                              6,16552763










                                              answered Sep 19 at 20:21









                                              user3226321

                                              11




                                              11



























                                                   

                                                  draft saved


                                                  draft discarded















































                                                   


                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f126794%2ftouch-gzip-all-html-css-js-files-in-a-directory-recursively%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest













































































                                                  Popular posts from this blog

                                                  How to check contact read email or not when send email to Individual?

                                                  Displaying single band from multi-band raster using QGIS

                                                  How many registers does an x86_64 CPU actually have?