touch & gzip all HTML, CSS, JS files in a directory recursively
Clash 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)?
find nginx gzip
add a comment |Â
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)?
find nginx gzip
add a comment |Â
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)?
find nginx gzip
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
find nginx gzip
edited Apr 27 '14 at 18:47
slmâ¦
239k65495665
239k65495665
asked Apr 27 '14 at 18:29
Ronak
1256
1256
add a comment |Â
add a comment |Â
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.
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
add a comment |Â
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
.
add a comment |Â
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).
add a comment |Â
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 --
add a comment |Â
up vote
-1
down vote
find dist -type f -exec sh -c "gzip < '' > ''.gz" ;
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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
.
add a comment |Â
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
.
add a comment |Â
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
.
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
.
answered Oct 4 '14 at 23:03
Srinidhi
40625
40625
add a comment |Â
add a comment |Â
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).
add a comment |Â
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).
add a comment |Â
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).
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).
answered Feb 25 '17 at 21:39
Nicholas White
1011
1011
add a comment |Â
add a comment |Â
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 --
add a comment |Â
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 --
add a comment |Â
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 --
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 --
edited May 11 '17 at 12:26
answered May 11 '17 at 12:16
user348878
11
11
add a comment |Â
add a comment |Â
up vote
-1
down vote
find dist -type f -exec sh -c "gzip < '' > ''.gz" ;
add a comment |Â
up vote
-1
down vote
find dist -type f -exec sh -c "gzip < '' > ''.gz" ;
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
find dist -type f -exec sh -c "gzip < '' > ''.gz" ;
find dist -type f -exec sh -c "gzip < '' > ''.gz" ;
edited Sep 19 at 20:44
Goro
6,16552763
6,16552763
answered Sep 19 at 20:21
user3226321
11
11
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password