OSX Terminal Fun III: A better LS

term_mine_thumb.jpgMac OS 10.2 for an unknown reason ships with a version of ls which doesn't support colored output. This isn't a big deal, but having colored output for ls can make it a lot easier to quickly tell different types of files from each other, or directories from files (click the picture to the right to see mine).

Yeah, I know you've seen colored output in your Terminal.app before, in man pages and the like, but that is just basic bolding of text (which you can set a preference for under the Terminal.app's prefs).

To get actual colored output from the ls command, you have to replace the standard ls Apple ships with OSX with a more "robust" version which will return colored output to the shell when you use the ls command.

You'll need to make sure you have the Developer Tools installed from the CD that came with OSX (there should have been 3 CD's) and you're good to go. Remember, follow these instructions exactly and I'm not responsble for typos (or anything else, for that matter).

Open up your terminal, and type:

	% mkdir newLS

then

	% cd newLS/

Cool beans, you've created your working directory so that you aren't making a mess and have changed your path so that you're inside of it.

Now, using your browser right-click (or control-click) on this link and select "copy this url" or "copy this address".

Now in your terminal window again, type:

	% curl -O "(paste address here)"

That is -O as in "ohboy", not a zero. Paste the url (using paste from the Terminal's menu, or the apple key plus the v key) you copied from your browser in between the quotes (yes, you need the quotes). Hit return.

Curl will go out, get version 4.1 of the gnu file utilities and write it out to a file within the current directory. You'll be treated to some nice download stats... I prefer curl, but wget works fine too if you know it.

Type these commands in order. Remember, a % symbol means you should be doing it on a new line and seeing a prompt.


% tar -xzf fileutils-4.1.tar.gz
% cd fileutils-4.1/
% ./configure
% make

./configure and make might take a few minutes depending on the speed of your computer and disk, but afterwards you'll have an updated, freshly compiled ls waiting for you. The below commands will backup your old ls, rename it to ls.bak and move your fresh ls to where it needs to be.

% sudo mv /bin/ls /bin/ls.bak
% sudo cp src/ls /bin/ls
% rehash

The "% rehash" command refreshes your shell environment, but you might want to create a new terminal window anyways. Do not close the current terminal window though!

Now, when you type the following command you'll see a nice color-coded display of your files:

	% ls -ohS --color=auto

Since you've replaced the ls that comes with OSX, you're going to want to replace it's man page as the options (such as color) will be different.


% sudo mv /usr/share/man/man1/ls.1 /usr/share/man/man1/ls.1.bak
% sudo cp man/ls.1 /usr/share/man/man1/ls.1
Now, clean up your mess. ls was just one utility you compiled, so you might as well get rid of the rest. Use these commands to clean everything up.

% cd ..
% cd ..
% sudo rm -rf newLS/

All the other utilities are now deleted. Obviously you aren't going to want to type something like that out whenever you type want to use the ls command, which brings us to aliases...

yummy alcohol posted button Posted by drunkenbatman
    April 25, 2003, at 02:18 AM


Comments (7)




Post a comment



Anonymous comments are allowed, but please enter something for a name.

And do endeavor to appear sane.









Remember personal info?