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

Fix a mis-formatted text file with perl and regex UNIX
Dear readers: Sigh, third try's a charm? I promise this one has no formatting errors ... but then again, that's what I thought the last time, too.

Dear readers: This hint originally appeared yesterday. However, somewhere between Smultron, Geeklog, and publication, I badly munged the contents. I managed to repeat the intro while skipping all the details I intended to explain. My apologies for this; I have nobody to blame but myself for not concentrating on the task at hand. The corrected hint appears below. Given how badly I messed up the original, I chose to re-run this one again today, just so folks would have a chance to read the corrected version.

So as to not confuse people, I also removed a couple of comments that basically just talked about the formatting issues with the original hint. I've left the remainder of the comments, however, and actually chose to refer to sweth's explanation directly in the hint, as it's much clearer than mine ever was! I also adjusted the command per his comments on "w" vs. "S," and re-titled the hint to make it a bit less confusing.

Finally, for those who commented that this hint doesn't belong here, I'd just like to point out that we have 1,226 other Unix tips in the system, and I have no intention of not publishing such tidbits. If you have no interest in seeing Unix tips, registered users can easily disable the entire category in their preferences. But OS X is built on Unix, and to claim that a Unix tip isn't relevant to OS X just isn't accurate.

-rob.

Yesterday, I was doing some global editing on a relatively large text file, and accidentally made one change too many, saved changes, and quit the editor before I noticed the problem. The result? My file was now littered with sentences that ran together at the period:
...my bearers would hurl me.As they bore me along...
...glanced at the thermometer."Gad!" he cried...
...might make reparation.I made up my mind that...
For the curious, those lines are from Edgar Rice Burroughs' book At the Earth's Core, the text of which I'm using in a comment spam blocker I'm writing for my blog site. I was editing the text to remove some of the spurious punctuation that was causing my code to misinterpret the position of word breaks, and I got overly aggressive removing some spaces. Read on to see how I resolved it with some help from a friend, and the Unix underpinnings of OS X.
read more (181 words)   Post a comment  •  Comments (8)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,479 views] Email Article To a Friend View Printable Version
How to uninstall MacFUSE UNIX
Last week, we ran this hint about using MacFUSE to install sshfs, which lets you mount ssh-connected servers like regular folders in the Finder. I tried it last weekend, and while I was generally thrilled with it (it's amazingly handy being able to work in remote folders as if they're local), I had some issues. In particular, it seems not to interact well with Path Finder (sshfs connections don't show as mounted volumes, for instance, unless they're in /Volumes, but they will do so in the Finder). I also had two kernel panics when I tried to unmount a mounted file system, so I decided to remove MacFUSE for now.

Unfortunately, there's no uninstaller included with the disk image distribution. After some rooting around on the MacFUSE site, I found these removal instructions on the Issues tab. I'm posting this hint mainly to say that I indeed tried the removal script posted there, and it seems to have worked well. I also checked the programs listed in the removal script against my MacBook Pro (which hasn't ever had MacFUSE installed), and found no overalp (so nothing listed there is used by anything else). The only extra step I took was to also remove the MacFUSE receipts from /Library -> Receipts.

There's a lot of promise in MacFUSE, but I think I'll wait a couple generations before trying it again!
  Post a comment  •  Comments (9)  
  • Currently 3.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[150,374 views] Email Article To a Friend View Printable Version
10.4: How to create an SSH volume using FUSE UNIX
Amit Singh posted an entry on his blog that mentioned the MacFUSE project -- the implementation of FUSE for Mac OS X.

Using the references that he mentions, one can have one's SSH account appear as a directory -- making it easy to handle and manage. Here's how...
read more (237 words)   Post a comment  •  Comments (20)  
  • Currently 3.25 / 5
  You rated: 2 / 5 (4 votes cast)
 
[41,609 views] Email Article To a Friend View Printable Version
Compile a powerful command-line download tool UNIX
I have always found that Mac OS X lacks an elegant yet free downloading tool that supports segmented downloading until I met ">aria2, which is a linux-based command-line downloading tool. From their website:
aria2 is a download utility with resuming and segmented downloading. Supported protocols are HTTP/HTTPS/FTP/BitTorrent. It also supports Metalink version 3.0.
It is very stable and fast (at least no slower than Speed Download and iGetter on my computer. However, the latest 0.9 version of aria2 does not compile on Mac OS X. After some work, I figured out how to make it compile -- read on for the how-to.
read more (155 words)   Post a comment  •  Comments (9)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[11,854 views] Email Article To a Friend View Printable Version
10.4: Add readline support to Tiger's python UNIX
For licensing reasons, Python on OS X comes without readline support (libreadline is GPL). Unfortunatley, this earlier hint no longer works in Tiger.

There is, however, a standalone readline distutils package made by Bill Bumgarner. I have slightly adapted it [click to download] to work either with a pre-installed readline from Fink, or with the included readline-5.1 without installing it. Hope this helps!

[robg adds: I haven't tested this one.]
  Post a comment  •  Comments (4)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[14,051 views] Email Article To a Friend View Printable Version
10.4: Trigger backups on connect with launchd UNIX
I have been searching for some sort of automated backup while I wait patiently for 10.5's Time Machine. While searching, I found this article on TUAW covering one method of automating the process.

I have re-written the backup scripts from that article to make them a little friendlier. Current features include:
  • Supports the backing up of multiple source directories
  • Uses rsync to cut down on un-necessary file transfers
  • Designed to allow for a minimum time between backups (default 24 hours) to prevent un-necessary system interruption.
I am planning on implementing several new features when time permits, including different backup profiles for different devices (eg: full backup to this drive, but only backup my documents and keychain when my iPod is plugged in...), and network rsync support...

Full code and instructions can be found here, and comments and suggestions welcome...

[robg adds: I haven't tested this one, but since backup is a personal hot topic of mine (not enough people have working (ideally multiple) backups), I thought it worth sharing.]
  Post a comment  •  Comments (9)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[19,089 views] Email Article To a Friend View Printable Version
Describe all Unix apps in current PATH UNIX
Previous hints have mentioned that you can get a list of Unix-level commands in the Terminal via auto-completion features of the shell, and that you can get a one-line synopsis of a specified Unix command with the whatis command -- and that this can be used to search for a desired command.

The hint presents a way to generate a list of all of the Unix commands in your execution PATH (see this Unix FAQ for an explanation of the execution PATH variable) with a one-line synopsis for each program (assuming this one-line description is available). This is accomplished via a rather complicated pipeline of commands:

echo $PATH | sed -e 's/:/ /g' | xargs -J % find % -maxdepth 1 \( -type f -or -type l \) | xargs basename | sort | uniq | xargs whatis 2> /dev/null | grep -E '\((1|1m|6|8)\)' | perl -ne '($name, $descrip) = m/^(.*?)\s+- (.*)$/; $name =~ s/\((1|1m|6|8)\)//g; printf("%-20s - %s\n", $name, $descrip)'

Here are the first several lines of output from the above command when run on my Mac:
SystemStarter    - Start, stop, and restart system services
Xmark            - summarize x11perf results
Xnest            - a nested X server
Xquartz          - X window system server for Quartz operating system
Xvfb             - virtual framebuffer X server for X Version 11
a2p              - Awk to Perl translator
...
If you want the output of the above command to be saved into a file instead of appearing in the Terminal window, add a greater-than sign and then the name of the file you want to create at the end of the command.
read more (905 words)   Post a comment  •  Comments (14)  
  • Currently 2.25 / 5
  You rated: 5 / 5 (4 votes cast)
 
[12,069 views] Email Article To a Friend View Printable Version
A simple MacPorts and Fink update script UNIX
If you use the MacPorts and Fink package managers, you might find it useful to be able to update both package managers with one simple command. I wrote the following simple script which does just that:
#!/bin/bash
#the script updates MacPorts and Fink packages;

if [ "$(whoami)" != 'root' ]; then
  echo "You have no permission to run $0 as non-root user."
  exit 1
fi

port selfupdate
port -d sync
portindex
port upgrade installed
apt-get update
apt-get upgrade
fink -q -y selfupdate
fink -q -y update-all
Just create a file containing that code and save it, say, to your home folder. Assuming that the file's been saved as ~you/updf (where you is your short username), just cd to that directory and make the code executable:
chmod u+x upfg
If it's not already set, you might also add the line PATH=$PATH:~you to your profile. Then simply type sudo upfd, wait a little bit, and you're done. Hopefully, that is, if there are no compilation errors, but that's another story!
  Post a comment  •  Comments (5)  
  • Currently 3.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[25,595 views] Email Article To a Friend View Printable Version
Create an HTML page from Safari's bookmarks UNIX
I was trying to figure out a way to be able to access my my Safari bookmarks from anywhere, without having to dig through the plist folder over ssh (especially on a slow connection). So, I wrote a shell script to do it; it does require plcat, which is part of the free PLtools package.

[robg adds: Set the script to executable (chmod a+x script_name), and edit the script to replace **YOUR USERNAME** with, well, your user name. I tested the script, and it works -- it creates an index.html file in whichever directory you run it in. You can then edit or view the index.html file using any text editor, such as vi.]
  Post a comment  •  Comments (11)  
  • Currently 3.00 / 5
  You rated: 2 / 5 (4 votes cast)
 
[16,123 views] Email Article To a Friend View Printable Version
An easy install of the ffmpeg command line tool UNIX
I always wanted to use the ffmpeg command line tool (the one ffmpegX is the GUI of) in Terminal, but I didn't find it in Fink, and I didn't want to compile it from an experimental source. Well, there is a working binary of ffmpeg bundled with ffmpegX. To get it, simply follow these steps:
  1. Get ffmpegX from the above URL. It's a pretty useful tool, because the ffmpeg synatx isn't quite easy to handle.
  2. Control-click on the ffmpegX application, choose Show Package Contents from the pop-up menu, and navigate into Resources.
  3. Copy ffmpeg to /usr/local/bin.
  4. Execute the following in Terminal (as admin):
    sudo chown root:wheel /usr/local/bin/ffmpeg
    sudo chmod 755 /usr/local/bin/ffmpeg
Now you have a working version of ffmpeg in the Terminal.

[robg adds: There may be other ways to get the binary as well, but this one seems quite simple.]
  Post a comment  •  Comments (10)  
  • Currently 3.29 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[96,228 views] Email Article To a Friend View Printable Version