Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts

Sunday, 14 April 2013

Uninstalling python packages

Continuing my system cleanup, I decided to get rid of all unnecessary python packages.

pip2 list | awk -F ' ' '{print $1}' | grep -vE "django-paypal|boto|mercurial|MySQL-python|nltk" | xargs pip2 uninstall -y

The -y flag indicates confirmation of uninstallation.

Wednesday, 10 April 2013

Uninstalling all gems

Some time back I was trying out jruby. I had installed multiple gems for it. Today, while cleaning up my system I was trying to get rid of it because it does not have much use to me. However, uninstalling the gems one by one is a pain. So, I wrote the following line to uninstall all gems.

jruby -S gem list | awk -F ' ' '{print $1}' | xargs jruby -S gem uninstall

P.S. : To understand how to construct such one liners please look at my previous post.

Tuesday, 8 January 2013

Kill all zombie processes of a process

Time and again I have found phpmyadmin not working because there are a lot of zombies of httpd. I do not know yet why these many instances of the daemon show up and why they turn into unresponsive zombie processes. Usually when this happens, I just kill all the zombies and spawn a new daemon and I carry on with my work. I used to kill all the zombies one at a time. However, today I figured out that I can do it with a single line.

ps aux | grep http | awk -F " " '{print $2}' | xargs kill -9

[If the working is clear to you, do read further and let me know if I can improve it or if I am interpreting anything incorrectly although things are somehow working.]

The one-liner above is easy to understand once we have understand the pieces. So, I am listing that below.


  • ps aux lists all running processes
  • grep http finds the lines containing the string 'http'
  • awk -F " " '{print $2}' splits each input line by delimiter specified with -F flag, space in this case and prints the second token thus obtained
  • kill -9 send SIGKILL signal to the processes whose ids are specified as arguments
  • xargs takes output of previous command and makes it input for the next
You should probably have a look at the man pages for more details on the commands.