2

I tried this command to compress all the css files in all subdirectories.

find . -iname "*.css*" -exec gzip -c '{}' > '{}'.gz  \;

But it only creates a {}.gz file. I ended up using this:

find . -iname "*.css" -exec sh -c "gzip -c '{}' > '{}'.gz"  \;

which works well.

The question is why the first one didn't work and second one did?

Note: I could easily use gzip -k switch to keep the source files, but gzip on CentOS 7 does not support it.

Sohail
  • 131

1 Answers1

1

It's all about when and by which shell the command gets interpreted. In the first, your command line shell interprets the >, making a local file before find even starts. In the second, the subshell does, after find replaces the {}, so it works as expected.