Minify css files in linux shell

Minify css files in linux shell

Yesterday morning, I have few hours to work on my blog and I  decided to spend some time optimising my website load time. It is a bit tricky but should pay it in terms of Google traffic. So, to check the website speed, I am using the best tool ever! It is made by Google experts. It is called Google Page Speed available here:

After some time optimising my website I got to 97% for the Desktop, which I consider pretty good.

Minify css files in linux shell

As one of the steps, I had to combine and minify CSS files. For this, I used one of the free Python libraries called cssmin. I manage to run it in the shell. I installed Python cssmin using the following command:

pip install rcssmin

Here is a basic command to minify the CSS files:

python -c 'from rcssmin import cssmin; print cssmin(open("style.css","r").read())'

This is the final version of the command I used:

mv style.css style-original.css
python -c 'from rcssmin import cssmin; print cssmin(open("style-original.css","r").read())' > style.css

I hope you find this useful.

About the author

Yuli Stremovsky
Yuli StremovskyParanoid Security Guy
In my daily life, I am the founder of a GDPR privacy automation service available at I maintain the following open-source privacy project

Among my credits, I was a founder of a database security company GreenSQL/Hexatier which was acquired by Huawei.

Specialties: Software and cloud architecture, Compliance (GDPR, HIPAA, PCI, SOX), blockchain technologies, software development, secure architectures, project management, and low-level research.