Tuesday, 27 November 2012

Killing all processes that match a given string

If you want to kill all processes matching a given executable, you can easily use killall:

killall -9 my_executable

But what if you don't want to kill processes based on an executable name, but rather on some argument name, or something else? That is, all processes that match some string?

You can. Here is the trick:

kill -9 $(ps aux | grep -v grep | grep my_process | awk '{print $2}') 

(originally from here)

Friday, 12 October 2012

Using wget to get multiple files from http servers

The Unix wget utility support globbing, but only when pointed to Unix FTP servers. So this could work:

wget ftp://something.com/*.jpg

but this will not

wget http://something.com/*.jpg

What do you do when you want to do this for an http server? A common case is where you have numbers for example, like

http://something.com/0.jpg
http://something.com/1.jpg
http://something.com/2.jpg

etc.

In this case the solution is

wget http://something.com/{0,1,2,3,4,5,6,7,8,9}.jpg

In this case the command will be repeated for all numbers and you get all 10 images in one go.

Monday, 14 May 2012

Search your installed Debian packages by repository

If (like me in this exact moment) you have a mess of a Debian (Ubuntu, Mint) system, and you want to know what packages you have installed from what branch / origin (stable, testing, unstable, experimental, backports) you can use Aptitude for that:


aptitude search '?narrow(~i, ~Abackports)'
 
Substitute to "backports" the repo you want to list, and you will obtain a fancy package list.

The ?narrow option tells aptitude to list only the installed packages. If you remove it, you'll get all packages you can install from that branch.

Another way is to install apt-show-versions and then use:


apt-show-versions -b | grep experimental


(again, substitute to "experimental" the branch you're interested in)