Category Archives: Tips&Tricks

Empty recycle bin for all users on Windows

Before I worked at a Linux only company, but since I changed job I’ve been working some with Windows servers. Something that got me frustrated last night was that somebody had put large files in the recycle bin but not emptied it. This made the server almost run out of space, so after a bit googling I found out that you actually can empty the recycle bin for all users.

This is a easy way to do this:

rd /s c:\$Recycle.Bin
rd /s c:\recycler

If you have multiple drives just change c:\ accordingly. And of course, answer yes (y) to the question that pops up.

A big thanks to the lifehacker blog for posting this.

Get sizes of database and tables in specific database

Often in my day to day work I need to figure out which database on a particular database that take up all the space, one easy way to do this is the following command that you run in your MySQL prompt or preferred MySQL manager:

´┐╝SELECT table_schema "Database Name", 
       SUM(data_length + index_length) / (1024 * 1024) "Database Size in MB" 
       FROM information_schema.TABLES GROUP BY table_schema;

If you need to know which table in a database run the following query:

SELECT table_name AS "Tables", 
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" 
FROM information_schema.TABLES 
WHERE table_schema = "test"
ORDER BY (data_length + index_length) DESC;

This was inspired from: StackOverflow – How to get the sizes of the tables of a mysql database?

Take backend out of rotation in varnish

When using Varnish and multiple backends it’s sometimes convenient to remove a particular backend without restarting the service Please note that this requires a Varnish version of at least 3.0.3 to work.

To remove a backend issue the following commands:

root@lb-01:~# varnishadm -T localhost:6082 -S /etc/varnish/secret
varnish> backend.set_health backend01 sick
200
varnish>

To re-add it to rotation use the following commands:

root@lb-01:~# varnishadm -T localhost:6082 -S /etc/varnish/secret
varnish> backend.set_health backend01 auto
200
varnish>

backend01 are backend name that can be required by issuing backend.list in the Varnish cli.

Killing specific processes with ps, grep, awk and xargs

Often when you work with Linux you need to kill a bunch of processes matching a certain pattern. This could be accomplished using ps, grep, awk and xargs like this:

ps -aux |grep php-fpm |grep -v grep | awk '{print $2}' | xargs kill

If the process won’t die you could add -9 to kill which can’t be blocked by anything. Of course you need to own the processes you try to kill (or use sudo).

References:
Article on commandlinefu.com