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

Compare two Mac-formatted text files UNIX
The standard UNIX (command-line) utility 'diff' compares two text files, showing you the lines which differ between the two. It works well for all UNIX text files, including most of those you will encounter in OS X (e.g. the plist files holding preference information).

But it isn't useful for comparing files which use the traditional Mac end-of-line marker ("\r") since the 'diff' utility, like most UNIX tools, expects lines to be ended with "\n". OS X itself and most OS X applications use "\n" as the end-of-line marker, but some applications which exist in both OS 9 and OS X versions use the traditional Mac "\r" end-of-line marker for their files. An example is iMovie - its project files are editable text but they use "\r" and hence cannot be usefully compared with 'diff'.

All of the above was a long-winded motivation for the following shell script (for use in the Terminal) which provides a 'diff' comparison of two traditional Mac ("\r") files. Read the rest of the article for the script...
read more (181 words)   Post a comment  •  Comments (3)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[21,222 views] Email Article To a Friend View Printable Version
A command-line weather getter UNIX
I'm a big fan of the PERL scripts that have previously been posted here, especially the command line speech generator and the command-line alarm clock. I use these two so frequently that I wrote a script to go with them; it gets the current weather and daily forecast off of weather.com, outputting the information in an speech-friendly way. To use this script, you must have wget installed, which you can do in a number of ways (This hint explains how, or through fink if it's installed, or via macosx.forked.net).

Read the rest of the article for the script...
read more (419 words)   Post a comment  •  Comments (8)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[9,202 views] Email Article To a Friend View Printable Version
Change IP addresses from the Terminal UNIX
The System Prefs panel makes it easy to change or add IP addresses, but what if you want to do it automatically or remotely? Most Darwin documentation talks about a nifty, "nonexistent since the Public Beta" tool called ipconfigd.

After much, much experimentation and research, I learned that to successfully change IPs from the command line the hard way, you must manually create a ton of routes. However, the ipconfig tool (not ipconfigd, which is now a plugin to configd) will do much of it for you. After manually setting the ip address of your interface (probably en0), just delete the current default route and recreate a route to your router.

Read the rest of the article for a script which uses this fact to automatically assign the next available IP using this technique.

[<b>Editor's note:</b> I have not tested this script.]
read more (471 words)   Post a comment  •  Comments (3)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[11,479 views] Email Article To a Friend View Printable Version
Search for commands by keyword in the Terminal UNIX
This trick may be obvious, but by combining a couple commands in the Terminal, you can search the descriptions of all the commands in that path. Open a Terminal and type:
 % whatis /usr/bin/* | grep "search string"
This will return the description of every command in that path and then filter it with your search string. This is a quick way to find a way of doing something, if you don't know all the commands. For example:
 % whatis /usr/bin/* | grep "memory"
leaks(1) - Search a process's memory for...
vm_stat(1) - show Mach virtual memory statistics
vmmap(1) - Display the virtual memory regions...
These example results were trimmed for width, but you get the idea...

[Editor's note: You can use this syntax to find anything on any path, of course. If you're just interested in user commands, you could also use man -k "search string" | grep \(1 to return the same results a bit faster. The 'whatis' version of the command will also only work if you have built the whatis databases - see this hint for more about the 'whatis' database.]
  Post a comment  •  Comments (7)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[4,430 views] Email Article To a Friend View Printable Version
Enable command-line portscanning UNIX
Just found this over at the macnn.com forums (credit to kennethmac2000 for that). There is no real command for doing portscans in the Terminal, so instead of installing nmap, just use the Network Utility from the command line like this:
 % cd /Applications/Utilities/'Network Utility.app'
% sudo cp Contents/Resources/stroke /bin/portscan
% rehash
Now you can do portscans from the command line using the following syntax:
portscan [address] [startPort] [endPort]
[Editor's note: I thought we had published something similar before, but I can't seem to locate it...]
  Post a comment  •  Comments (2)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[4,589 views] Email Article To a Friend View Printable Version
Quickly define words in the Terminal UNIX
Add the following alias to your aliases.mine file to have an on-call dictionary at your fingertips:
alias dict 'curl dict://dict.org/d:\!*'
Now to look up a word, just type dict word_to_define.

[Editor's note: There's at least one service (OmniDictionary) which will return the definition of a selected word if you prefer the GUI for your dictionary browsing ... but this is quite nice when you don't want to touch the mouse or the menu to define a word. Note that I have substantially (completely?) rewritten what Carthag submitted ... primarily because, although it was fun reading an IRC transcript, it really didn't fit the layout of the macosxhints page all that well! ;-)]
  Post a comment  •  Comments (4)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[6,774 views] Email Article To a Friend View Printable Version
Count all files in a folder hierarchy UNIX
In the Finder, it's relatively easy to see how many files are within one level of a folder, but I'm not aware of a way to see a count for all of the files in that folder hierarchy (anyone?).

Someone asked a similar question on the Macworld forums, and with some help from a friend, we managed to come up with a UNIX command string that will return the answer. Say you wish to count all the files in the folder "Stuff" stored on your desktop. Simply type the following into the Terminal:
  % cd ~/Desktop
% find "Stuff/" | wc -l
This will return a count all files, including invisibles and the top level "Stuff" folder itself. If you just want to see the visible files, use:
  % find "Stuff/" \! -name ".*" | wc -l
I'm not sure if this is the most efficient means of answering the question, but it seems to work reasonably quickly and it was accurate on all the folders I tested it on. Any other alternatives, in either the Finder or the Terminal?

If you'd like to know more about how the command works, or how to create a shortcut to make it easier to use in the future, read the rest of the article.
read more (314 words)   Post a comment  •  Comments (11)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[62,995 views] Email Article To a Friend View Printable Version
Add full ANSI color support to Terminal.app UNIX
I was becoming fairly frustrated with terminal.app because it would not do a good job of displaying ANSI color. I found a hack that would let me display colors with ls, but mutt, lynx, emacs and so on would stubbornly stay in black and white. The solution is to make the proper terminfo file for a VT100 terminal (which is what terminal.app more or less emulates) with color support.

Read the rest of the article for the how-to...
read more (210 words)   Post a comment  •  Comments (52)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[99,483 views] Email Article To a Friend View Printable Version
Convert 'man' pages to text files UNIX
I can't really take credit for this as it came straight from the Unix Guru Universe Tip of the Day (subscribe). To save a copy of any man page to text simply type:
man command_name | col  -b > output_file_name
For example:
man grep | col -b > grep.txt
This can be especially useful for larger man pages (tcsh, for example), as you can now open and work with the text file in any GUI text editor.
  Post a comment  •  Comments (5)  
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[6,339 views] Email Article To a Friend View Printable Version
An AppleScript front end to 'calendar' UNIX
Now that we have all these cool Unix utilities I decided to unleash some AppleScript upon them. The following script will display the output of the calendar command in a dialog, allowing you to then place the contents on the clipboard. Paste the following into script editor, modify to your liking and compile:
set n to do shell script "calendar -f ~/Library/calendar"

display dialog "Calender:\r" & n buttons {"Clipboard", "OK"}¬
default button 2
if the button returned of the result is "Clipboard" then
set the clipboard to n
display dialog "The calendar is on the clipboard." buttons¬
{"Cool"} giving up after 10 default button 1
-- the "giving up after 10 " part basically assumes it's cool
-- after 10 seconds of inactivity and removes the dialog
end if
Some notes to help make this easier to use:
  1. Create the calendar file first with touch ~/Library/calendar, and then edit it to add your entries.
  2. Read the man pages for calendar (man calendar) for information on how to format your calendar file.
  3. There are some sample calendars in /usr/share/calendar; to see the script in action, try using /usr/share/calendar/calendar.computer (or any of the others in that directory) in the first line after the "-f". You can also add extra options (-l 30 to show the next 30 days, for example).
Save the script in compiled mode, and then just double-click any time you'd like to access the calendar file.
  Post a comment  •  Comments (4)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[9,204 views] Email Article To a Friend View Printable Version