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

Speed up perl operations on large files UNIX
Yesterday I was faced with a 21 megabyte text file that needed several find/replace operations. Tex-Edit would open the file, but not change it. BBEdit would chug through the changes, but it was taking forever. I dropped into a Terminal window and used:
perl -pi -e 's/find/replace/g' filename
However, this too was slow -- much slower than I expected.

Because I was checking the file in Tex-Edit after each find/replace, the process was taking some time, until on a whim I used Tex-Edit to change the line endings from "Mac" to "Unix" style.

From that point on, the 'perl s/' command ran blazingly fast.
  Post a comment  •  Comments (8)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[4,002 views] Email Article To a Friend View Printable Version
Two keystroke 'ls -F' shortcut UNIX
A very silly hint, but one I haven't seen anywhere else and which might prove useful to someone...

In a terminal window, hit ESC twice to perform an ls -F. Saves typing a few characters.

[Editor's note: Wow, it works! Is this a bug or a feature??]
  Post a comment  •  Comments (10)  
  • Currently 5.00 / 5
  You rated: 5 / 5 (3 votes cast)
 
[2,437 views] Email Article To a Friend View Printable Version
SSH configuration change with 10.1.3 UNIX
The upgrade to 10.1.3 also included OpenSSH 3.0.2p1.

I found out that there is a change in how authentication with other servers is handled in this version. When I connect to one of my OpenBSD boxen, I get asked for my S/key password before I have a chance to enter my normal password. That's of course very unfortunate if you have not set up your s/key passwords, or do not carry them with you.

The fix was for me to add one line to the /etc/ssh_config file:
PreferredAuthentications publickey,password,
keyboard-interactive
[Shown on two lines; enter as one]

If you do not intend to use S/key password authentication, you could leave away the keyboard-interactive part.
  Post a comment  •  Comments (1)  
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[2,323 views] Email Article To a Friend View Printable Version
A simple command-line calculator UNIX
tc is yet-another-calculator. This time written in tcl, and it's very easy to personalize. It has a few symbols showing the ways you can customize it. With this script (I put it in ~/bin/tc; chmod +x and rehash), you can write arithmetic expressions in a natural way, avoiding the use of the * and () signs that are preinterpreted by the shells. It is also very easy to add symbols that are replaced before the expression is evaluated. I use it also as a euroconverter, showing how easy it is to expand its behaviour. For example:
  % tc sin 3 eu
sin(3) * 166.386 = 23.480393661
% tc 2 2
2 * 2 = 4
% tc 2 x 2
2 * 2 = 4
Read the rest of the article for the script...
read more (71 words)   Post a comment  •  Comments (5)  
  • Currently 3.00 / 5
  You rated: 3 / 5 (3 votes cast)
 
[7,043 views] Email Article To a Friend View Printable Version
Make utility Terminal windows less intrusive UNIX
This falls into a "nitpicky" category. As someone who enjoys the extreme customization ability of X11's (e.g. XFree86) ATerm program, but hates the holdbacks that go along with using X11, I am always looking for ways to make Terminal behave more like ATerm.

One of the things I like to do is to see a couple of my log files all of the time. With ATerm, I can make a 100x8 character window, remove the scroolbars, titlebar, and resize handles, turn it 60% transparent, and put it in a corner. Good stuff.

In Terminal, you can't get quite that handy, but you can get close. Read the rest of the article for some settings to make "utility" terminal windows less intrusive...
read more (136 words)   Post a comment  •  Comments (7)  
  • Currently 3.33 / 5
  You rated: 1 / 5 (3 votes cast)
 
[11,707 views] Email Article To a Friend View Printable Version
Work with resource forks in the Terminal UNIX
While visiting a friend the other night, he showed me a trick in the terminal that I hadn't seen before, and I'm pretty sure hasn't been mentioned here as of yet. I'm also not sure of the usefulness of this trick, but it is interesting.

You can work with the resource fork for any file by simply adding "/rsrc" to the end of some file handling commands. For example, you could use this method to see which files within a directory contain resource forks:
% ls -al */rsrc
-rw-r--r-- 1 robg staff 0 Apr 25 2001 top.term/rsrc
-rwx---rwx 1 robg staff 0 Nov 21 22:33 travel.pdf/rsrc
You can also use this flag on "cat" and "cp" commands, allowing you to display (not very useful) or copy the resource fork of a given file.

I'm not sure how long this has been there, nor if the Developer Tools are required or not, but perhaps someone can find a good use for this modifier.
  Post a comment  •  Comments (5)  
  • Currently 1.00 / 5
  You rated: 1 / 5 (2 votes cast)
 
[8,679 views] Email Article To a Friend View Printable Version
UNIX mail notification in the dock UNIX
All i wanted was a simple biff program for the dock, just a little, unobstrusive, audio/visual "new mail" signal, so that i wouldn't keep popping open my mutt window every N minutes (bad discipline). No such luck and too lazy to write something myself (and afraid of SOMEHOW managing to screw something up and lose mail). Here's what i ended up doing.

Read the rest of the article for the how-to. This hint assumes you have mutt and esound installed ... check out fink first if you don't...

[Editor's note: This tip also assumes the Dev Tools are installed and you have some knowledge of compiling UNIX software. I have not tried it myself, since I'm pretty happy with Mail.app]
read more (310 words)   Post a comment  •  Comments (1)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[7,111 views] Email Article To a Friend View Printable Version
Wake a sleeping Mac from the network UNIX
Most modern computers offer a feature called "Wake on LAN". This is designed to allow a network administrator to turn on a computer remotely, even when it is turned off, by sending a "magic packet". This is used, for instance, to allow backup programs to run at night.

I haven't found any trace of this documented on Apple's web site, but it seems Macs also implement this feature (at least my iMac G4 does). I use this feature to turn on my iMac from my office when I want to log on using ssh (I have a Solaris machine on my home LAN that runs 24/7).

The magic packet format is very simple: it must include anywhere in the packet 6 times hexadecimal FF, followed by 16 times the Mac's MAC address (pun intended). The easiest way to do this is to send a broadcast.

Here is a Python script that does this (if your MAC address is 01-23-45-67-89-0a:
#!/usr/bin/env python
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto('\xff'*6+'\x01\x23\x45\x67\x89\x0a'*16, ('192.168.1.255', 80))
[Editor's note: Sounds very cool, but I don't run Python ... any way to replicate this script in something that's installed on all OS X boxes? I know there are a lot of people that would probably be interested in such a solution, myself included!]
  Post a comment  •  Comments (36)  
  • Currently 3.30 / 5
  You rated: 5 / 5 (10 votes cast)
 
[183,882 views] Email Article To a Friend View Printable Version
Edit iTools sites from the command line UNIX
For those of us who prefer to edit (or at least fine-tune) a webpage in a good old-fashioned text editor, iTools has made it pretty easy. If you have .html files in your Sites folder on iTools, you can simply open a terminal window and edit those files. They are located in
/Volumes/iToolsName/Sites/
where iToolsName is replaced with your iTools username.

Use vi or emacs or pico to edit whatever files you choose and save. The changes are instantaneous because you are editing the source right out. You can even create new files this way.
  Post a comment  •  Comments (3)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[2,180 views] Email Article To a Friend View Printable Version
An alias to ease unit conversions UNIX
An earlier hint and comments discussed using "units", a built-in UNIX tool for unit conversion. Here is a way to use the utility in a convenient way. Put this line in your aliases.mine file:
alias uni 'echo '\''scale=4; \!:1'\''`units \!:2 \!:3` |
awk '\''{print $1, $2, $3}'\'' | bc -l'
NOTE: Shown on two lines; put a space between the "|" and "awk" and remove the line break!

Now, you can get unit conversion by typing uni [value] [starting unit] [out unit]. For example:
% uni 200 nmile mile
230.1558800
This converted 200 nautical miles to statute miles. To find out which units are available, examine the file units.lib in /usr/share/misc/.
  Post a comment  •  Comments (5)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[3,786 views] Email Article To a Friend View Printable Version