0

I want to minify multiple CSS files automatically with "uglifycss" in a bash script (from here How to minify Javascript and CSS with command-line using minify tool?)

#minification of CSS files
find ./newcss -type f \
    -name "*.css" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec uglifycss --output {}.min.css {} \; \
    -exec rm {} \; \
    -exec mv {}.min.css {} \;

The files are in /newcss, the script is one folder above that, in /newcss are multiple .css files but the script says

newcss/glowcookies.css
find: ‘uglifycss’: No such file or directory

although there is a glowcookies.css in /newcss. What am I doing wrong here?

Chris
  • 1
  • The message suggests that `find` can't see `uglifycss` ... is it in your `$PATH`? If no, use the fully qualified path to it ... – tink Sep 02 '22 at 18:49
  • The files are in `/newcss` per your question or `./newcss` per your example? – roaima Sep 02 '22 at 18:53
  • The sad thing is i got it to work like one hour ago but forgot what I did... Anyways, if I type newcss instead of ./newcss or /newcss (shouldn't it all be the same?) I get the error newcss/glowcookies.css find: ‘uglifycss’: No such file or directory. I installed uglify with npm install -g uglifycss – Chris Sep 02 '22 at 18:59
  • And is it in your PATH? – tink Sep 02 '22 at 19:00
  • I just checked it with https://stackoverflow.com/questions/6569478/detect-if-executable-file-is-on-users-path, I replaced cmd=ls with cmd=uglifycss and it says that it is NOT in PATH, how do I add it? – Chris Sep 02 '22 at 19:14
  • when I type uglifycss it says "command not found" – Chris Sep 02 '22 at 19:30
  • npm list -g shows the path it is installed /home/chris/.npm-global/lib – Chris Sep 02 '22 at 19:56
  • 2
    You need to fix the issue, "_when I type uglifycss it says "command not found"_ first" – roaima Sep 02 '22 at 20:11
  • "_i got it to work like one hour ago but forgot what I did_" - use the `history` command to see what you typed – roaima Sep 02 '22 at 20:11
  • 1
    "_if I type newcss instead of ./newcss or /newcss (shouldn't it all be the same?)_" - No, not at all! `newcss` is broadly the same as `./newcss` but `/newcss` is almost certainly a totally different thing – roaima Sep 02 '22 at 20:12

1 Answers1

0

You can not run a command by just specifying it, unless it is in one of a few special places (see $PATH). This behaviour was removed from modern OSes a long time ago, as it is a security risk, and can lead to confusion (it can be enabled, but don't). However, it is still mandatory in less advanced OSes.

You have to specify its location. One way to do this (if the program is in the current working directory) is to add a ./ before the name. e.g. ./my-program. Else specify the location e.g. ../program or ~/dir/program or …

ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102