UNIX tee in real life
on April 29, 2010 @ 02:13 AM

I wrote a nice little article on using the UNIX tee command in real life. If you’re wanting to see the purpose of tee or learn something new about bash, check it out:

http://mutuallyhuman.com/2010/4/29/unix-tee-in-real-life

Happy coding!

0 comments | Filed Under: | read on

⌘-k Hotkey in bash, on linux
on December 29, 2007 @ 02:50 PM

I never thought I would say “I wish my console acted more like the OSX’s Terminal.app”, but the truth is that I said that two days ago. That day my MacBook Pro (MBP) went out of commission due to an accidental overdose of Raspberry Iced Tea. Ever since then I’ve been plugging away on my Kubuntu box using Yakuake and Emacs23 to develop.

I have this obsessive need to clear the terminal all the time during development, primarily when I’m going to run tests. On my MBP I would just hit ⌘-k to clear the terminal, but I don’t have that luxury in Yakuake or any other terminal that I know of. So why not roll my own?

After googling around for a while I found this article by Bryan Henderson from the Linux Gazette . Even though the article is seven years old it still applies. In addition to this article I also read the man page for readline which has a lot of cool information in it. Since bash relies on readline to do the input processing new doors have opened for what I want to tinker with on my system.

Writing Your ⌘-k Hotkey

Create a ~/.inputrc file. In that file put the following contents. Now log out and log back in (or fire up a new terminal session):

1
2
"\ek":"\C-a\C-kclear\n\C-y"
"\C-x\C-r": re-read-init-file

The first line expresses that I want Meta-k to map to the following set of keystrokes:

  • C-a which brings me to the beginning of the line
  • C-k which cuts the line
  • clear which is used to clear the terminal
  • a newline which executes the clear command just as if I typed it and hit enter
  • C-y which pastes what I cut with C-k back onto the terminal

And now you have a Terminal.app ⌘-k hotkey on any system that uses bash. The only difference is that its mapped to Meta-k.

The second line is a simple nicety so you can reload your ~/.inputrc file without having to log out and log back in. Just type C-x C-r to reload any changes.

2 comments | Filed Under: | read on

rak, ack and findit
on December 13, 2007 @ 04:52 AM

In Helpful Command Line Tools from last month I posted on my custom findit script.

Jason Porrit commented on that post and mentioned ack , a perl alternative to grep and find which offers terminal color highlighting to your results. I also found this morning a ruby alternative called rak

All of these utilities do the same thing, they search a directory structure for files whose contents match a given pattern.

Here’s Ack

Here’s Rak

Here’s findit

Overall ack and rak beat out findit, but findit has a much better name. I think I’ll just alias findit to rak. (yes I”m biased to ruby code over perl code).

The only thing ack and rak are missing is a filename only option. If I can find every file matching a pattern from a given start directory that would rid me of findfile as well!

3 comments | Filed Under: | read on

less shift f
on April 24, 2007 @ 05:19 PM

If you use a combination of piping to files and using the tail command with the -f option and/or using grep you may want to try just sticking with the less command and using the Shift-f to tell less to continue waiting for input from the file.

Before Shift-f you’ll see your normal output as shown by less:


Apr 23 20:24:39 elijah com.apple.SecurityServer: Succeeded authorizing 

You can tell if its working by looking at the last line of your less output.

1
2
Apr 23 20:24:39 elijah com.apple.SecurityServer: Succeeded authorizing 
Waiting for data... (interrupt to abort)

Now less is going to get updated whenever the file you are lessing has more data appended to it. Now hit / and start looking for whatever it is you want to find.

Another way to use one tool rather then three.

0 comments | Filed Under: | read on

.screenrc configuration
on January 07, 2007 @ 02:14 AM

I spend most of my time in screen when I’m coding or doing any system administration work. It gives me the ability to do multiple things in a single window, and never have to remove my hands from my keyboard to switch terminal sessions or split windows. It even provides the flexibility of detaching and reattaching to screen sessions while leaving your terminal sessions in existence.

I’ve been using the below .screenrc file recently to give me some more useful information.

The screenshot

Screen_thumb

Note the following things in the screenshot:
  • system hostname
  • system ip addresses for each interface configured (see below “whatsmyip” file information)
  • system load (updates every few seconds)
  • date
  • current time (this updates every second)

The .screenrc file

altscreen on
hardstatus on
hardstatus alwayslastline
backtick 1 60 60 /home/zdennis/bin/whatsmyip
hardstatus string "%-Lw %{= kG}Host: %{Y}%H%? %{c}(%1`) \
%{= kG} %-=Load: %{Y}%l%{kG}  %{= kG}Date: %{Y}%m/%d\
/%y%{= kG}  Time: %{Y}%C:%s%a%{= kG}%{W}" 
caption always
caption string "%-Lw%{= bw}%50>%n %t%{-}%+Lw%<" 

Note: The lines that end in \ note a continuation of the line.

The whatsmyip file

The whatsmyip file is a simple ruby script which parses out all interfaces configured with an ip address.

1
2
3
4
5
6
7
8
9
#!/usr/bin/ruby

interfaces = `ifconfig`.scan( /^(\w+)/ ).flatten.delete_if{ |interface| interface =~ /lo/ }
arr = interfaces.inject( [] ) do |arr,interface|
  md = `ifconfig #{interface}`.match( /((\d+\.){3}\d+)/ )
  arr << "#{interface}: #{md.captures.first}" if md
  arr
end
print arr.join( ' ' )
2 comments | Filed Under: linux | read on

Fixing Sound on eMachines M5405
on October 29, 2006 @ 03:49 AM

While working on my sister’s laptop (eMachines M5405) tonight I noticed that I couldn’t hear any sound coming out of it. The fix was simple. In KDE, load up KMix and select the Switches tab and disable the External Amplifier, and it should work fine.

0 comments | Filed Under: linux | read on

Join Your Local LUG!
on October 25, 2006 @ 06:11 AM

In order to learn GIMP better and support our local Grand Rapids Linux Users Group here’s a Tux version of the “For a better life” campaigns.

Join Your Local LUG

0 comments | Filed Under: linux | read on