Here's a nifty but somewhat useless quickie that will pick random words from the built-in dictionary file:
perl -e 'open IN, "</usr/share/dict/words";rand($.) < 1 && ($n=$_) while <IN>;print $n'
Inspired by an example in the 'Camel' book and the fact that I couldn't come up with a non-Bash way to generate random numbers from the shell. (Any ideas why there's no /dev/random? It kinda seems that this was a design decision rather than an oversight...)
The /usr/share/dict/words exists on most Unix systems. Curiously, the words seem to be different from that of the system-wide spellchecker service built into OSX.
You can use the standard backtick operator to plop the word into another cmd-line program.
DO NOT *EVER* USE THIS [OR ANY DICTIONARY] TO GENERATE PASSWORDS!
[To the editor: I admit this is sort of off-topic as far as Mac OSX is concerned. Perhaps you can use it when there's a dry spell in hints or as a 'stupid shell tricks' feature.]
[From the editor: Hey, it is a bit slow with everyone awaiting 10.1's arrival, and this is an interesting trick. There are some strange words in the dictionary!]
I have spent the last few days trying to get xspim (a MIPS emulator) to work with OS X and have finally got it going. After spending many frustrating hours on it I figured that I would post how to get it working for the few who might need it (unless you are really into assembler or need it for class or work there is really no point). fyi: download spim from here
Read the rest of the article for detailed installation instructions...
Since reading a recent Hint, I'm compiling a C++ scientific computing package to run on OSX and do some parallel calculations on my dual G4 (MPI and OpenMP). It's all working fine except when I turn on a feature that uses the functions drand48() and sdrand48(), which are a random number generator and a seed respectively. In OSX they aren't defined.
On other *nix systems these functions are defined in stdlib.h, and the corresponding library. Taking into account that I have never compiled a library without explicit instructions - is there an easy way to add these functions without doing anything dangerous to the libraries that came with OSX? Could I replace the standard library safely?
I've currently installed bash and rpm if that would shorten the instruction list at all. Thanks for any help,
I would have never really pushed to get this to work, but I needed to have xwindow working for a class that I am taking... After all the work I put in I figured I would give a few pointers that took many hours to figure out (mostly because of my unix ignorance). First of all download the files from xfree86 download. I put all the files into a folder called xfree86 and stashed it onto my harddrive. I then fired up the terminal and got to the xfree86 directory. Next I entered
sudo perl Xinstall.sh
I tried it the first 2 times with out sudo and it did not work very well. After this runs go to and download the newer XDarwin. This runs rootless (this means that OS X is still visible in the back ground). It takes a little while for the whole thing to load, but it seems to work. Granted I do not know much about this whole thing... but it may be nice to know if you are like me, that using Sudo makes the install actually work!
The following will search the current dir (and subdirs) for any files that contain identical content and are of identical size, regardless if they are named differently. Open a terminal shell, and 'cd' to the dir you want to search, then type:
[Editor's note: I inserted a carriage return for readability -- type the command on one line when entering it!]
This will produce a list of duplicate files (if any) in dup.txt. True there are some nicely written apps that will do the same thing, but ain't it great that you can do this right from within your OS?
This will ignore files that are smaller than 10k. (remove/alter the '+size 20' to change this). But a warning: really small files may produced identical CRCs. i.e. show up as duplicates even if they really aren't.
If you want to search a filesystem you don't own (i.e. /) you'll need to sudo or su or 'find' will complain.
The built-in cksum cmd only uses CRC32. MD5 would be better. Anyone know why it's not enabled under OSX?
If you're gonna write a script to delete the duplicates from the produced dup.txt list, just remember that it contains ALL instances of the duplicate files.
This has become a major area of frustration for me. Specifically, I'm trying to get the command line version of setiathome to kick off on startup (and automatically if it goes down). In the past, I've had no problems with getting the Rhapsody version of seti@home running in a cron job, but that was before MacOS X as we know it came along. To make a long story short, I have tried every variation of users' crontabs to get this line in the cron execution pipe, and nothing seems to want to kick the process off. I have even resorted to Cronnix (excellent app) to get the job done. The line as it appears in my various crontabs:
0 * * * * cd [path to my seti dir here];[space] ./setiathome -nice 19 > /dev/console 2> /dev/console
[Editor's note: Line break inserted for readability; it's really one line, and replace '[space]' with a true space character.]
I'm on the verge of giving up, but postings on this site have given me hope (someone is making this command work).
Perhaps I'm missing something really obvious, but in any case, I need help. How do you make a cron job kick off? What am I missing -- or misunderstanding? Links to a good Cron or MacOS X (or FreeBSD) UNIX tutorial?
In the spirit of learning from others' mistakes, I'm sharing the following slightly embarassing story.
In the process of trying to use my web host's Linux OS "tar" command to compress a directory while excluding another, I managed to create a file called "-X". When I went to delete the mistakenly-named file, I quickly found myself stuck. Typing "rm -X" didn't work, because 'rm' interprets the "-" as the sign for a command-line switch, and it doesn't know what to do with "-X" as an option, leading to "unknown option" errors.
Thinking I was smarter than the box, I then tried to use the various UNIX quote characters to 'mark' the hyphen: rm "-X", rm \-X, and rm '-X'. None of these worked; each generated the same error message about unknown options. On my Mac, I would have simply used the GUI and dragged the file to the trash. On the Linux box, though, I was stumped - no GUI available, and a badly named file stuck in my directory.
One amusing ("You won't believe what I've done now...") call to a UNIX-knowledgeable friend provided two options. The first is to use two hyphens to let 'rm' know that there are no command-line switches: rm -- -X. The second is to refer to the file via its relationship to the parent directory: rm ./-X. Either of these will work just fine to delete the file (or you could use "mv" with the same syntax to rename it if you want to keep the file).
At least with OS X we have the option of using the GUI to correct our stupid mistakes! As such, there's an easy way out for X users ... but perhaps this story will save someone some command-line frustration at some point in the future. And please, all you advanced UNIX wizards out there, hold the snickering to a minimum! ;-)
Hello, I've sucessfully installed Ruby, a great newish scripting language. I recommend you try it out. Anyways, it works fine by itself, but I am having problems getting it to work as a script in Apache. I've installed mod_ruby, and have followed their directions. However, I can still not get it to work under Apache. Anyone had any luck?
Opera was crashing on me constantly, so I decided to trash my Opera preferences. Little did I know (until I was emptying the trash) that my Opera prefs folder contained 38,000 items! After waiting for about 10 minutes, I still had 35,000 items left to empty. I decided to bail out and do it from the command line, where it took approximately 15 seconds! A simple rm -r * to empty my .Trash folder did the trick.
[Editor's note: If you're new to the terminal, be very careful with the 'rm' command. There is no going back, and there's no confirmation (by default). To do this safely, you should first type cd ~/.Trash (to make sure you're in your trash directory) and you may want to use rm -ri * which will ask for confirmation on each file. Although this won't be fast, you'll be confident you're deleting the right files before they're all gone! A wise friend once said to me that there are two types of UNIX users ... those that have "rm -r *"ed the wrong directory, and those that will...]