Linux Search & Kill Group of Processes

0 comments


The following quick command can be used to kill one or more processes found using the combination of ps and grep.
ps -ef | grep FooBar | awk '{print $2}' | xargs kill -9

Ruby Error on Require JSON in Ubuntu

0 comments


Received the following error from a Ruby application when it called require 'json'.

irb(main):002:0> require 'rubygems'
=> true
irb(main):004:0> require 'json'
LoadError: no such file to load -- json
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from (irb):4
from :0
JSON is in the libjson-ruby package. So to fix this
sudo apt-get install libjson-ruby
and presto!
irb(main):001:0> require 'json'
=> true

Linux Argument List Too Long

0 comments

Encountered this cleaning out a directory overflowing with thousands of log files. When entering rm *.log or even a more narrow set such as rm *2011.log, the following error occurs.

sudo: unable to execute /bin/rm: Argument list too long

Solutions
Use find to output the file names one at a time, sending each to the rm (or some other) command.

find /home/username -type f -name "*.log" | xargs rm -f
find /home/username -maxdepth 1 -type f -name "*.log" | xargs rm -f
find $HOME -maxdepth 1 -type f -name "*.log" -exec rm "{}" \;