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

Create a directory list in CSV format UNIX
Sometimes you may need to get a sorted list of all files in a direcoty transformed in a database format, so, after getting the directory list you may end cutting and pasting the data to your database. On the other hand, there's an easy way to do that, if you just follow this tip. Open Terminal and type:
ls -lT | \
awk '{print "\""$10"\""";""\""$6" "$7", "$9"\""";""\""$5"\""}' \
| pbcopy
This will generate a CSV (comma-delimited) directory listing on the clipboard in the following format:
"Filename";"Creation Date";"Size"
For example:
"a2p";"Mar 21, 2005";"104608"
"aclocal";"Mar 20, 2005";"12606"
"aclocal-1.6";"Mar 20, 2005";"12606"
"addftinfo";"Mar 20, 2005";"59852"
"afmtodit";"Mar 20, 2005";"165346"
"alias";"Mar 21, 2005";"147"
"appleping";"Mar 21, 2005";"19656"
If you want to generate a file instead of sending the result to the clipboard, just replace the | pbcopy part with > xxx, where xxx is the file name you want to create.

[robg adds: When this hint was submitted, Geeklog killed the backslashes in the above command. After much trial and error, I believe I have them back where they need to be to generate the proper output. If there are errors, however, they are mine, not the original poster's. I also split the command onto three lines for a narrower display, but it should copy and paste.]
  Post a comment  •  Comments (11)  
  • Currently 3.40 / 5
  You rated: 3 / 5 (5 votes cast)
[15,943 views]  View Printable Version
10.4: Build Apache 2.2.3, php 5.1.15 and mysql 5.0.24 UNIX
This hint will only work if you have Xcode installed -- get it for free at Apple's Developer website.

The following steps use Terminal, and you'll probably have to use sudo on some of the commands if you're not logged in as root.

$ wget\
$ wget
$ wget
$ gnutar -xzf httpd-2.2.3.tar.gz 
$ gnutar -xzf php-5.1.5.tar.gz
Backup mysql data and install mysql
  1. cp -Rp /usr/local/mysql/data /Users/your_user_name/ -- only necessary if you're updating.
  2. Install mysql-max-5.0.24-osx10.4-powerpc.dmg -- install everything.
  3. rm -rf /usr/local/mysql/data -- only necessary if you're updating.
  4. mv data /usr/local/mysql/data -- only necessary if you're updating.
Read the rest for the Apache and php instructions...
read more (127 words)   Post a comment  •  Comments (9)  
  • Currently 2.75 / 5
  You rated: 4 / 5 (4 votes cast)
[26,451 views]  View Printable Version
Some perl scripts to help track stolen computers UNIX
As an owner of two iBooks and a Mac mini, it has struck me that these are all likely targets for a thief. A while ago I recalled this story about how someone used Timbuktu Pro to recover a stolen iMac. I then realised that because we use Apple's Remote Desktop software at work, then all I need is the current IP address of a computer to be able to observe/control it.

So I wrote a perl script to lookup my computer's IP address and email it to me at regular intervals. I then had the idea to make the script determine the location of the computer based on the IP address. This is not always an exact science, but it can often pinpoint the town where the computer is. Recently I also realised that I could use the UNIX screencapture command to also email myself a screen capture (to potentially see what any thief is viewing/typing). This might be of more use to those who don't own Remote Desktop. Finally, my latest source of inspiration occurred after buying an iSight camera for my Mac mini. I discovered the great (and free) isightcapture utility, which now allows me to email pictures taken by the iSight camera.

So I now have my computers send me regular emails throughout the day which get automatically filtered by a rule in my Mail application. Because each of these three different functions (IP address, screen capture, and isight capture) require different tweaks to the system, I wrote three different perl scripts so people can pick and choose what functionality they want. These three scripts can be downloaded as a tarball, or downloaded separately from my blog, which has full and detailed instructions on how to install each script (some require some tweaks to the system).

The main limitations of these scripts are that a) the stolen computers need to be online long enough for the scripts to run, and b) the thief doesn't just wipe your hard drive. I try to counter the second option by not using a password on the screensaver, and setting the computers to automatically log into a somewhat-restricted guest account following any reboot. Hopefully this would encourage someone to use the computer just long enough for you to get some helpful information emailed to you.

[robg adds: I haven't tested these scripts.]
  Post a comment  •  Comments (32)  
  • Currently 3.25 / 5
  You rated: 5 / 5 (8 votes cast)
[29,965 views]  View Printable Version
Compile a universal binary Windows remote desktop app UNIX
The Remote Desktop Client app is a pretty handy way to remotely manage/control a Microsoft Windows workstation. However, the solution Microsoft provided is a little bit outdated and runs on Rosetta, which hogs CPU and memory. An alternative way of doing this is by using the rdesktop program, which is open source for Linux/Unix.

First, go to their download page and download the latest source code. Extract the source to say ~/rdesktop. Then, we need to compile the program on Mac OS X. Open Terminal and cd ~/rdesktop, run the following commands:
$ ./configure
$ make
$ sudo make install
Finally, you can use X11 to run the rdesktop program.

[robg adds: You'll need to have the X11 application installed in order to compile and use rdesktop. I had some issues initially, due to an X11 install that was somehow messed up (no X11R6 directory in /usr). After some retries with the X11 installer, compiling worked as described above.]
  Post a comment  •  Comments (12)  
  • Currently 3.20 / 5
  You rated: 3 / 5 (5 votes cast)
[15,739 views]  View Printable Version
A script to aid in script logging/debugging UNIX
As a Mac OS X administrator and as someone who likes to use shell and perl scripts to automate things, I find myself doing a lot of debugging and logging. To make things simpler, I wrote a perl script which I call from other scripts to output errors, warnings, and info in an ordered, easy-to-read system-log-like format.

Save the script text to a file (, open Terminal and change the file mode to allow execution (chmod u+x /path/to/, and call the script within (or without) another a script like this: /path/to/your.log calling-process "log text"
Note the log file will be created if it doesn't already exist.

[robg adds: I haven't tested this one...]
  Post a comment  •  Comments (6)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
[3,678 views]  View Printable Version
Use top as a quick replacement for Activity Monitor UNIX
The process list of Activity Monitor is very nice, but oftentimes I want a lightweight alternative that is easy to start, and has very little impact on system resources. In order to achive this goal, I started with the top command as my basis. In its standard mode, top is still a bit resource hungry, so I added a few options (remove costly traversals of kernel datastructures, update every 10 seconds, sort by resident memory size):
/usr/bin/top -R -F -s 10 -o rsize
For making this command easily usable (either by double-click or by Spotlight opening), I used the Execute this command feature (Execute command in a shell activated) with the exec command at the beginning of the above command line in the Save dialog of Terminal. Together with setting the Close the window option in Window Settings... > Shell, this ensures that very little memory is consumed (the shell is replaced by using exec). The resulting Terminal window containing top can be easiy terminated by just typing q when it is active. Additionally, the scrollback buffer should be disabled in Window Settings... > Buffer.

Saving the resulting file under the name topmem.term makes it possible to either double-click the file, or start it by typing topmem in Spotlight and hitting Command-Return. Additional commands can be built, which sort by different fields (e.g. -o cpu, -o time). I have put a ready-made topmem.term as shown above (with green on black colors and slight background transparency) on my website.

[robg adds: I haven't tried the linked topmem.term file, but the rest works as described.]
  Post a comment  •  Comments (3)  
  • Currently 1.75 / 5
  You rated: 2 / 5 (4 votes cast)
[8,251 views]  View Printable Version
View valid 'top' output on the desktop via GeekTool UNIX
The great and free GeekTool (PowerPC | Intel) can write the contents of any file, and the output of any shell command, right onto the desktop. Unfortunately it doesn't support self-updating commands like top, and the official workaround (break the loop with top -lk and set Refresh to keep restarting it) is rather Heisenbuggy:
  1. Taking k = 1, the CPU usage line and column stop making sense.
  2. With k > 1, they become skewed by an overestimated CPU usage for top itself.
  3. Either way, relaunching top every few seconds soon causes pid's to roll over 30000, so that recent processes must be hunted down the list rather than conveniently appearing on top.
In short, watching top this way perturbs it more than we'd like. In this hint, I describe a different (k = 0) workaround which appears to solve the problem, i.e. display top exactly like Terminal does.
read more (247 words)   Post a comment  •  Comments (15)  
  • Currently 1.00 / 5
  You rated: 1 / 5 (5 votes cast)
[25,978 views]  View Printable Version
10.4: Run Automator workflows at the command line UNIX
Looking through applications in Terminal, I stumbled upon automator, which simply lets you run an existing Automator workflow from the Terminal. This could be useful in Perl, Bash, and other scripting.

[robg adds: The man page for the command is quite brief; it says just this: automator runs the specified workflow document. To create or edit a workflow, use the Automator application. There are no options.]
  Post a comment  •  Comments (2)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
[16,929 views]  View Printable Version
Yet another simple command line Calculator UNIX
Add the following to your .bashrc for a quick calculator:
calc () { 
    echo "$@" | bc -l
Now at the prompt you may try something like...
$ calc "2 * 3F"
...and instantly receive the result -- no need for some GUI tool.

[robg adds: There are two other command line calculator hints here. This one worked for me, at least with the commands added to my .bash_profile file.]
  Post a comment  •  Comments (4)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
[22,032 views]  View Printable Version
Randomize Thunderbird (or other mail client) signatures UNIX
This hint allows you to randomize your e-mail signatures. I use this with Thunderbird, but this hint should work with any e-mail client that refers to an external file for your signature. I needed a solution that just worked and didn't really require anything more from me. Some of the plug-ins out there require some user action each time you write an e-mail -- which I didn't like. Also, most of my signature remains the same, so I wanted my solution to simply change one part of my signature (a tagline), the rest remains the same.

Basically, my solution is composed of a couple files which can be merged to form a random signature (and any supporting graphic files, etc). These should be placed in your normal directory holding your signature. For this example, let's say this is the directory /Users -> jbloggs -> signature/:
  • signature-template.html - my normal signature (and all of its support files), but with a minor change: I've replaced the tagline with a marker [TAGLINE].
  • taglines.txt - this is a list of all my taglines that I want to randomly choose from for each e-mail. There is one tagline per line, and any characters that might be special to the shell must be escaped properly.
Other files required to make up this solution are the following, which are to be placed in the directory /Library -> StartupItems -> SignatureRandomizer, which is owned by root, has its group set to wheel and has permissions 0755 (drwxr-xr-x):
  • SignatureRandomizer.watchdog - this is the magical bit. This shell script monitors my signature.html file to see if it has been used, and if it has, it creates another one by randomly selecting a line from my taglines.txt file and inserts it into the signature-template.html file.
  • SignatureRandomizer - this script controls the watchdog-script.
  • StartupParameters.plist - this is required to automatically start the service when my Mac boots up.
Read on for the details on each piece of code.
read more (662 words)   Post a comment  •  Comments (4)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
[9,753 views]  View Printable Version