Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a tool or a way to minify (similar to Compress my code and this question on Stack) all of the code in my .xml, .css, .html and .js files through Ubuntu's terminal. Eventually I will bash script the process, but at the moment I would like to just find something to test. Is there a tool out there that I can use to compress all these file formats through the terminal?

share|improve this question
Have you tried something like tar -czvf compressed.tar.gz *.xml *.css *.html *.php ? – roadmr Jul 17 '13 at 14:52
I am looking to compress the code itself. Something like CSS Minify – Darth_Vader Jul 17 '13 at 15:10
Then I think you're not asking for compression. By compression on regular files (non-media like music/videos) we mostly only consider lossless compression, but you're looking for a way to minimize the whitespace (in which you lose this data). And because minifying is lossy, you can't decompress (because it's not reversible). To me this makes it "unclear what you're asking". – gertvdijk Jul 17 '13 at 15:31
up vote 22 down vote accepted

This is not the best option but it's probably the easiest. The YUI compressor was long thought to be the best compressor for Javascript and CSS, offering 20-40% improvements over other minifiers.

It has since been superseded by newer projects like Uglify.JS (which Grunt will probably suggest) but it's still a fairly easy thing to get up and running in Ubuntu.

sudo apt-get install yui-compressor

That's it. Now you can run yui-compressor myfile.js and it'll do its magic, just not as well, or as conveniently as a properly install Node/Grunt/Uglify+YUI stack.

share|improve this answer
Not everyone who uses js or css is using node.js or doing node.js projects. It is yet another framework to learn and configure if you want to use grunt. Yes grunt is cool. But now-a-days, we already have enough to learn before we can even start coding. So node/grunt is not always convenient. :) I myself am going to try your suggestion of yui-compressor. – BillR Sep 28 '14 at 7:06
@BillR I sort of agree with the sentiment but while I don't have any node.js projects, I still use things like lessc and uglify.js because they are the best tools for the job. I don't use Grunt because I've replaced it with my own tooling but for the actual work, I'd never hobble myself just to avoid Node. If you want to stay in the industry, you have to keep up with best practices. – Oli Jan 20 '15 at 9:53
You are making the assumption that using node is best practice. Maybe in your world which is not everyone's world. – BillR Jan 20 '15 at 18:07
In many cases the output (the minification, or whatever) is the best. Objectively. That's what I'm taking about here. If you only ever use what's easiest for what you currently know, you'll go extinct faster than a dinosaur. – Oli Jan 20 '15 at 21:01
My point is if what you know works, then you use what's easiest with what you know. Chasing change for change's sake has no value. There's been too many silver bullets. New languages break out faster than a social disease in a whore house. Sure, many flock to them because they are new, but that is a fool's game. I can and will learn new things if there is a benefit to do so. If learning node.js were to help me, I'd learn it. It's just another language. But to learn it, I need to reallocate time to it. My time is valuable to me, and so far I haven't seen the justification in terms of that cost. – BillR Jan 20 '15 at 21:19

There is no reason to minify php files (except you have very limited disk space and want to use every bit of it).

If you could add a goal (What do you want to accomplish and why?), somebody might show you a better way.

JS and CSS files are minified on runtime and cached in most webprojects. There is minify (, a php "library" which is able to do exactly this. (can also be executed with php from the terminal)

But keep in mind that one big javascript file does not necessary load faster than 5 small files. If you need a reason and a solution for this statement, take a look at

May the source be with you...

share|improve this answer

I would recommend using Grunt.js. It's an automation tool that has minifiers available as plugins and can be run in your terminal via Node.js. It should not be necessary to minify PHP as the code executes on the server side and only its HTML output is sent to the client.

You can find available plugins here

share|improve this answer
Be aware that choosing Grunt implies a learning curve. – Rick-777 Jan 4 '15 at 18:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.