Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create on-the-fly hostname lists for ssh tab completion UNIX
If you don't want to manage server lists for tab completion with ssh, put the following line in your .bash_profile file in your home directory: This will allow you to tab complete any hostname you've previously ssh'd to.

[robg adds: This worked as described for me. The complete command is a built-in bash function that lets you specify lists of options to be used with tab completion on a given command. The version above parses your known_hosts to create the list of options. You can read more about the complete built-in function in the bash man pages -- man bash, then search for the section titled Programmable Completion.]
  Post a comment  •  Comments (20)  
  • Currently 2.27 / 5
  You rated: 3 / 5 (11 votes cast)
[22,362 views]  View Printable Version
10.5: Get TinyCA2 to build under Leopard UNIX
With the advent of 10.5, MacPorts has had to undergo a lot of updates, some of which have been painfully slow in coming. As a freelance security consultant, I *have* to have TinyCA2 working. Unfortunately, the MacPort project to update it for 10.5 took five months before the trouble ticket was finally even assigned to a maintainer. (I suppose these guys have a lot to do.) So here are some workarounds to make it compile under Leopard:
  • Edit the files (as root) that are listed in the error output (I had six instances total in four different files) following the command sudo port install tinyca2.
  • In those files, delete the ' character (apostrophe) mentioned on the line number indicated, which follows the colon in the error output. (If you use nano to edit the files, press Contrl-C to find the current line number.) These are in commented lines, but for some reason, they still keep the files from being processed.
  • cd to the directory mentioned in the error output (probably /opt » local » var » macports » build » _opt_local_var_macports_sources_rsync.macports.org_release_ports_security_tinyca2 » work » tinyca2-0.7.3 » po) and edit (as root) the language file mentioned in the error output. Change anything not important (ie add a space to the end of the file), then save the file.
  • Re-run the sudo port install command.
  • Edit the new language file mentioned in the error output, and do the same thing again (edit, change inconsequential info, save).
After doing this for four or five of the language translation files, the compiling works, and you should now be able to finish compiling the program. Hopefully the great guys at MacPorts can get this port updated, but until they do, this should get you up and running.
  Post a comment  •  Comments (8)  
  • Currently 1.78 / 5
  You rated: 2 / 5 (9 votes cast)
[7,572 views]  View Printable Version
Open data from a pipeline in any application UNIX
The open(1) command (man page) provides a -f option, which open's own help says "Reads input from standard input and opens with TextEdit". But, in fact, you can load the data into nearly any application. Simply combine the -f flag with the -a flag:
  • curl '' | open -a 'Hex Fiend' -f
  • curl '' | open -a 'TextMate' -f
  • curl '' | open -a 'Preview' -f
  • curl '' | open -a 'QuickTime Player' -f
Of course, the source of the data doesn't have to be curl; it can be any command. Note that the last two examples aren't even textual data: one is an image, and the other is a video file. You aren't limited to text; any data will work. But there is a catch: open will save the file with a .txt extension, regardless of what kind of data it is (it doesn't look). This could confuse some applications that rely on the filename extension to determine what type of document to open it as. Preview works, but I wouldn't count on any other applications without testing them first.

This hint works in 10.4, and should also work in 10.5. I don't know whether it works in any earlier versions of Mac OS X.
  Post a comment  •  Comments (5)  
  • Currently 1.50 / 5
  You rated: 2 / 5 (8 votes cast)
[7,069 views]  View Printable Version
10.5: Fix the sudo shell prompt UNIX
This hint assumes you are using the default bash shell. If you need to run a series of commands interactively as root (or any other user) using sudo, it's most convenient to start a new shell session with the effective user ID you want by typing sudo -s.

Prior to Leopard, you would then get a shell prompt similar to the usual one, but with the effective username in place of your username. For example, if you were logged into host foo.local as user bar, your regular shell prompt would be
[foo:~] bar$ 
...where the ~ represents your home directory (and it will change to show the current directory). If you started a root shell with sudo -s, the prompt would become...
[foo:~] root# you could see at a glance where you were and who you were. Under Leopard, though, the behavior of sudo has changed -- you now get a default prompt with a # to indicate you're running as root -- bash-3.2#. This is much less useful, because now you can't see what host you're logged into or what your working directory is. You have to type extra commands to get that information.

To get back the old-style prompt, you need to set the environment variable SUDO_PS1 in one of your shell initialization files. One way to do this is to start a shell (not a sudo shell) and enter...
cat >> .profile
export SUDO_PS1="\[\h:\w\] \u\\$ "
...then type Control-C to exit the cat process. Close the Terminal window or tab, open a new one, and start a sudo shell. You should now have the old prompt back. To revert the change, edit the file named .profile in your home directory to remove the line you added above.
  Post a comment  •  Comments (20)  
  • Currently 2.63 / 5
  You rated: 4 / 5 (8 votes cast)
[18,327 views]  View Printable Version
10.5: Fix Control-R in the Ruby interactive shell UNIX
It appears that Leopard ships with popular UNIX tools linked against a new BSD-licensed libedit library instead of more popular readline (which was the case in Tiger). This may cause few surprises if you are a hardcore shell prompt surfer.

I was especially irritated by Control-R (reverse history search) not working in irb (ruby interactive shell), which was using the new libedit library. The solution to this particular deficiency is very simple -- just configure libedit by editing a file named .editrc in your home directory. Add this line:
bind "^R" em-inc-search-prev
You can also set many different options in that file -- for more help, run man editrc.
  Post a comment  •  Comments (3)  
  • Currently 2.64 / 5
  You rated: 2 / 5 (11 votes cast)
[11,133 views]  View Printable Version
Batch or one-time convert APE to MP3 via script UNIX
I've written a Ruby script that batch converts ape format files straight to individual ID3-tagged mp3 files for adding to your iTunes library. It uses all free software to do so. The muscle work is done by:
  • Mac ape conversion tool (ape => wav) named SuperMMX. There's no MacPorts version of this utility, so you have to hand install. SuperMMX - Google translation.
  • lame mp3 encoder using --preset extreme to convert to monolithic mp3 (available from MacPorts)
  • mp3splt to read the ape cue files and split the monolithic mp3 into tracks with ID3 tags. (also in MacPorts)
  • mp3split uses the -f (frames) setting assuming a variable bitrate. If you tweak the lame settings, then you probably want to read the man page for mp3split and tweak that, too.
  • I've included status bars for conversion and informative output.
  • I've also included fairly robust error checking, but I knocked it out pretty quick. If you run into errors I overlooked, let me know and I'll add them.
  • Contains a verbose mode so you can see exactly what's going on behind the scenes.
  • Uses ansi term colors for easy reading (oooo ahhh colors).
  • Provides a --clean option to move the old files (ape, cue, wav, monolithic mp3) to the trash, leaving only the desired mp3 tracks.
  • --test mode if you just want to see what happens.
  • Complete usage information.
Needed ruby modules:
  • rubygems
  • optparse
  • ostruct
  • term/ansicolor
  • pathname
  • fileutils
I believe all of these packages are in Leopard by default except term-ansicolor.

I just did this pretty quickly, so I could have overlooked a thing or two. Please let me know if I did. As always, YMMV. However, I've successfully converted single ape files as well as over 80 ape files in a batch conversion with no problems.

[robg adds: A queue review site commenter noted the availability of Max, a free GUI tool to do the same thing. I'm running the script because I haven't tested either solution, so I'm not sure if one does things the other can't. Also, a script can more easily be run remotely, in case you're doing this over a network.]
  Post a comment  •  Comments (7)  
  • Currently 1.60 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[15,437 views]  View Printable Version
Use a theme with X11 graphical (GTK) programs UNIX
This hint applies if you have GTK applications installed through MacPorts. It may also work with GTK applications installed through other means, but your mileage may vary. These applications, by default, look really ugly because there's no decent gtk2 theme engine installed. But it's actually very simple to install one. In Terminal, just type:
port search gtk2
Some gtk2 packages will be displayed, but we're interested specifically in the gtk2 theme engines, such as gtk2-aurora and gtk2-clearlooks. To install one (I highly recommend one of those two), simply type:
sudo port install gtk2-aurora
You will need to enter your administrative password for sudo.

As soon as you're finished, you should also install gtk-chtheme by typing sudo port install gtk-chtheme. You may also have to enter your administrative password here. You can now proceed to select the theme you will be using in newly-launched GTK apps by typing gtk-chtheme in your terminal. A graphical application will launch that provides live previews of your selected theme. When you find one you like, just press OK.

With a theme chosen, every GTK2 application launched will look beautiful.
  Post a comment  •  Comments (2)  
  • Currently 2.70 / 5
  You rated: 2 / 5 (10 votes cast)
[14,614 views]  View Printable Version
A shell function to make 'rm' move files to the trash UNIX
Command line users: Have you ever wished rm would put stuff in the Trash instead of just deleting it? After accidentally running rm -rf Desktop one day, I decided it was time to stop really deleting stuff when I ran rm. So I wrote is a shell function -- this means that the actual /bin/rm executable works like normal; only when you run rm from Terminal do files get moved to the Trash. This means that programs (and scripts) which delete files won't be affected.

So how do you use this? Open Terminal, and edit ~/.bash_profile (this is a script which is run every time you open a Terminal). Run nano ~/.bash_profile from the command prompt if you don't have a preferred editor. Add the following lines at the bottom of the file:
function rm () {
  local path
  for path in "$@"; do
    # ignore any arguments
    if [[ "$path" = -* ]]; then :
      local dst=${path##*/}
      # append the time if necessary
      while [ -e ~/.Trash/"$dst" ]; do
        dst="$dst "$(date +%H-%M-%S)
      mv "$path" ~/.Trash/"$dst"
Save the file and exit. (Hit Control-X in nano; it'll ask if you want to save, press Y and hit Enter to accept the default filename.)
read more (385 words)   Post a comment  •  Comments (28)  
  • Currently 2.20 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (10 votes cast)
[31,830 views]  View Printable Version
A script to download and convert multiple YouTube videos UNIX
There are many solutions on the web on how to download YouTube videos using bash scripts, e.g. see this one as an example. However, using scripts described in the above link may be a little uncomfortable if you wish to get lots of YouTube clips. So I've modified those scripts a little bit so that the URLs are put into a single file with this structure:
where urlN and nameN are Nth clip's URL and desired local filename for the saved movie file.
read more (253 words)   Post a comment  •  Comments (10)  
  • Currently 2.57 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
[30,755 views]  View Printable Version
A command line crossword solving assistant UNIX
I'd been looking for a simple way to leverage OS X's built-in Unix dictionary to solve crossword clues, and came up with this little gem of a script:

echo -n "Please enter a word pattern to search for (use a . for unknowns): "
read text

echo `grep -w $text /usr/share/dict/words`
Just paste into your text editor of choice, save somewhere, make sure to chmod +x the file and boom, you have yourself a very simple crossword solver! Granted it isn't perfect, but it's a good start.

[robg adds: Just to clarify, the Unix dictionary isn't the same as the built-in dictionary you access through the Dictionary program. While the Unix words file does hold a large number of words, it doesn't have everything you'll find in Dictionary app.]
  Post a comment  •  Comments (20)  
  • Currently 1.71 / 5
  You rated: 3 / 5 (7 votes cast)
[11,531 views]  View Printable Version