system || exec || %x

You can use system() or %x[] depending what kind of result you need.

system() returning true if the command was found and ran successfully, false otherwise.

>> s = system 'uptime'
10:56  up 3 days, 23:10, 2 users, load averages: 0.17 0.17 0.14
=> true
>> s.class
=> TrueClass
>> $?.class
=> Process::Status

%x[..] on the other hand saves the results of the command as a string:

>> result = %x[uptime]
=> "13:16  up 4 days,  1:30, 2 users, load averages: 0.39 0.29 0.23\n"
>> p result 
"13:16  up 4 days,  1:30, 2 users, load averages: 0.39 0.29 0.23\n"
>> result.class
=> String

Read More

delete old kernels / cleanup /boot (ubuntu/debian)

http://askubuntu.com/questions/89710/how-do-i-free-up-more-space-in-boot

  • verwendeten kernel anzeigen

    uname -r

  • alle nicht verwendeten (alten) kernels anzeigen:

    dpkg -l linux-* | awk ‘/^ii/{ print $2}’ | grep -v -e uname -r | cut -f1,2 -d"-" | grep -e [0-9]

  • alle nicht verwendeten (alten) kernels löschen

    dpkg -l linux-* | awk ‘/^ii/{ print $2}’ | grep -v -e uname -r | cut -f1,2 -d"-" | grep -e [0-9] | xargs sudo apt-get -y purge

(befehle müssen im edit-modus kopiert werden, da WP aus “ ein code-quote erstellt und den befehl damit unbrauchbar macht)


ubuntu/debian only!

Read More

irb tabcompletion and history

Since its unfortunalely not a built in functionality:
in .irbrc
 require ‘irb/completion’
ARGV.concat [ “–readline”, “–prompt-mode”, “simple” ]
module Readline
module History
LOG = “#{ENV[‘HOME’]}/.irb-history”def self.write_log(line)
File.open(LOG, ‘ab’) {|f| f << “#{line}
“}
end

def self.start_session_log
write_log(”
# session start: #{Time.now}

“)
at_exit { write_log(”
# session stop: #{Time.now}
“) }
end
end

alias :old_readline :readline
def readline(*args)
ln = old_readline(*args)
begin
History.write_log(ln)
rescue
end
ln
end
end

 
Readline::History.start_session_logrequire ‘irb/ext/save-history’
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = “#{ENV[‘HOME’]}/.irb-save-history”

 

Read More