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

Install better ls, du, and df tools in 10.3 UNIX
The standard ls that comes with 10.3 doesn't give us any colors. du and df report absurd numbers. du also doesn't take the "--max-depth" argument. These things can be annoying, so here's a way to fix them. ;)

** note: this hint assumes you have gcc or another working compiler installed, and that you're using /bin/bash as your shell. otherwise, it's up to you to interpret the instructions to your shell's scripting syntax. **

[robg adds: This hint is an update to several older ones (including two on adding color to the ls in Panther) which discussed similar solutions...]

First Step: Get New Software

For all of these features, you need GNU Fileutils, or GNU Coreutils. You can get these from ftp.gnu.org. Be sure to also visit the GNU webpages regarding Coreutils and Fileutils. coreutils is a later version than fileutils, and includes the shellutils and textutils sets as well. coreutils will also install via Darwinports, so if you have that, all you have to do is
port install coreutils
It will put all the utilities into /usr/local/bin (or other location you've specified to Darwinports), with all the commands prefixed with a g, like gls and gdf. If you install with Darwinports, you can go straight to Step Two as soon as it's done installing.

Otherwise, if you don't use Darwinports, you can download and compile from source. I've tested compiling fileutils v.4.0 manually on 10.3 with gcc 3.3 (the one that came with Panther's Dev Tools), and it worked just fine. I installed the latest version of coreutils with Darwinports, which does in fact compile the package from source, and since that worked, it's a safe assumption that you can probably download any version and do the standard
./configure --prefix=/path/to/install/to
make
make install
Note: Be sure to read the INSTALL and README that come with the source package, as different versions may or may not need configure flags for OS X, for specifying /usr/local/bin vs. /bin, or for adding the "g" prefix to the filenames. Your standard ls and other commands live in /bin, so be sure to back them up if you decide to completely replace them. I haven't tried outright replacing the commands, so I have no idea what it might break, but I don't recommend it. If you do replace them, and nothing breaks, you can skip to customizing the colors (and leave a comment to tell us whether it works if you do that!). You'll need admin or root priv's to install anywhere outside of your home directory, so if you don't have those permissions, you can still get the benefits of GNU utilities by installing to a "bin" directory in your home area, and adding that to your PATH during Step Two

Second Step: Set your shell to use the new software!

At this point, you should have the GNU coreutils or fileutils installed, and you should know where they are installed. If you installed with Darwinports or configured from source and didn't specify a path, they're probably in /usr/local/bin, prefixed with a "g".

An easy way to tell your system that you want to use the new ls or "gls" (with color) instead of your old one is to make an alias in the your login script. The bash shell under Terminal sources the file ~/.profile, or /etc/profile (if you're using another shell, it's up to you to know which files it runs at login). If you have admin privledges, you can edit /etc/profile, and the updated commands will be automatically used by everyone. If you don't have these privledges, edit or create a ".profile" file in your home directory.
Here's what you'll need to add (at least):
alias ls='gls --color=tty'
alias du='gdu'
alias df='gdf'
You can make aliases for as many of the GNU programs as you'd like.
Note: In order for these to work, you'll need the location of these new programs in your PATH. Type
echo $PATH
in your Terminal to find out. If the location isn't listed in the output, add the following to your .profile or /etc/profile, above the "alias" lines:
export PATH=$PATH:/path/to/install/dir
(where "/path/to/install/dir" is the location you installed the programs)

Before continuing, save the /etc/profile or .profile, then open a new terminal and make sure you're getting the aliases rather than the old programs. Use
type ls
to find out. If it says "ls is aliased to `gls --color=tty'", then you're good to go! Otherwise, you'll need to figure out why your Terminal isn't sourcing the file you thought it was. The first place to look is Terminal:Preferences, but a full investigation is beyond the scope of this hint.

Customizing the directory Colors

You may have noticed that you only get a couple of the standard terminal colors, even with "gls --color=tty", and you'll quickly find out why if you do:
echo $LS_COLORS
It's blank!!! What do we do? Well, GNU fileutils came with "dircolors" or "gdircolors", but even if you run it, it doesn't tell you much. The secret is to add the following color codes into your .profile or /etc/profile:

export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so
=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;
41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;
32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31
:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z
=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=0
1;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=
01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:'
Note: If you copy and paste that, make sure you remove any line breaks, or otherwise adjust for them, else your shell will give you errors when you login.

That's it!!! Have fun!!!
    •    
  • Currently 2.75 / 5
  You rated: 4 / 5 (4 votes cast)
 
[22,105 views]  

Install better ls, du, and df tools in 10.3 | 24 comments | Create New Account
Click here to return to the 'Install better ls, du, and df tools in 10.3' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Install better ls, du, and df tools in 10.3
Authored by: isd_glory on Apr 12, '04 11:32:58AM
Three words:
fink install fileutils
I swear, its the first thing I type into the command line as soon as Fink and the DevTools are installed on a computer.

http://fink.sourceforge.net/

[ Reply to This | # ]
fileutils...
Authored by: aeonflux on Apr 12, '04 12:23:07PM

is known to cause segmentation fault... so be cautious.



[ Reply to This | # ]
fileutils...
Authored by: isd_glory on Apr 12, '04 03:50:29PM

The only problems that I've occasionally ever had with fileutils are:
1. The "unstable" version is often very unstable
2. The build process chokes and fails to finish linking everything up when compiling

I have never had any issues running the current stable release of fileutils once it has been compiled it successfully. In the rare occurrences where I have seen segfaults, removing and rebuilding the package from source solved the problem pretty quick.



[ Reply to This | # ]
fileutils...
Authored by: mommsen on Apr 14, '04 01:52:59PM

This may happen if prebinding is acting up and can be easily solved by running 'sudo /sw/var/lib/fink/prebound/update-package-prebinding.pl -f'



[ Reply to This | # ]
Just for the record...
Authored by: Nugget on Apr 12, '04 11:39:07AM

The GNU tools aren't better, they're just different. For the record:

"ls -G" will give you color output.
"du -d" is du with depth reporting

and

"du -h" and "df -h" will give you end-user formatted numbers if that's your preference.

Installing the GNU stuff seems like overkill to me.



[ Reply to This | # ]
Just for the record...
Authored by: Gigacorpse on Apr 12, '04 11:58:37AM

I agree with you, although I do prefer the GNU date command options over the one Apple provides.



[ Reply to This | # ]
Just for the record...
Authored by: marcusmarrow on Apr 12, '04 11:57:40PM

A nice feature of the GNU ls which I can't replicate on my Mac is
to ignore backup files (files ending in ~).
With the GNU version, 'ls -B' did the job.



[ Reply to This | # ]
Just for the record...
Authored by: jptxs on Aug 25, '04 03:38:30PM

so if I choose not to go with the gnu tools, is there a way to have my terminal bahave like vt100 in terms of scrolling (not clear the screen after man and vi etc.) but still get my colors?



[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: JohnnyMnemonic on Apr 12, '04 12:03:02PM

"fink install osxutils" is another option.



[ Reply to This | # ]
RTFM
Authored by: snooze on Apr 12, '04 12:11:05PM

This hint really isn't that accurate. While the command options might be a little different, Panther allows color with ls. And I don't see anything absurd about the numbers du and df are reporting (unless you mean that reporting in 512-byte blocks is absurd). For color ls, just put the following in your .profile (assuming you are using bash):

export CLICOLOR=1

Also, by default df and du show things in 512-byte blocks (this isn't anything specific to Panther, many unixes do this by default). To have it show in 1K blocks use -k. Or put it in your .profile (assuming you are using bash):

alias df='df -k'
alias du='df -k'

This is all documented in the man pages for those commands.



[ Reply to This | # ]
RTFM
Authored by: robeen on Apr 12, '04 03:29:23PM

The ls -G is fine for terminal - but it does not work for me using the X11 xterm...which I mainly use.

The coreutils ls works in both.

If you can get the standard ls to work in xterm, maybe someone could post how to do so! Thanks -

Rob



[ Reply to This | # ]
RTFM
Authored by: Nugget on Apr 12, '04 04:17:26PM

This is an artifact of your $TERM environment variable. The default is "xterm" which doesn't indicate a color-capable device.

Try setting TERM to xterm-color and it will work fine.

export TERM=xterm-color (bash)
setenv TERM xterm-color (tcsh)



[ Reply to This | # ]
RTFM
Authored by: otomo on Apr 15, '04 12:50:36AM
From the manpage man ls:
CLICOLOR Use ANSI color sequences to distinguish file types. See LSCOLORS below. In addition to the file types mentioned in the -F option some extra attributes (setuid bit set, etc.) are also displayed. The colorization is dependent on a terminal type with the proper termcap(5) capabili- ties. The default ``cons25'' console has the proper capabilities, but to display the colors in an xterm(1), for example, the TERM variable must be set to ``xterm-color''. Other terminal types may require simi- lar adjustments. Colorization is silently disabled if the output isn't directed to a terminal unless the CLICOLOR_FORCE variable is defined.

CLICOLOR_FORCE Color sequences are normally disabled if the output isn't directed to a terminal. This can be overridden by set- ting this flag. The TERM variable still needs to refer- ence a color capable terminal however otherwise it is not possible to determine which color sequences to use.
So set CLICOLOR_FORCE to 1 if you feel really sure about what you are doing. Don't forget to set TERM to something meaningful!

Good luck!

And personally I prefer to install almost everything in my user account, then I modify my PATH as needed. This way if anything happens to my install, a simple restore of files in my home directory is ALL that is needed to bring myself back to where I am now. (well outside of a reboot and installation of some applications) As a longtime FreeBSD user, I prefer the BSD utils, but your preference.

[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: shogunjp on Apr 12, '04 12:46:36PM
If you install coreutils from source you may have to remove the uname command. On my powerbook G4 I found that the uname -p (that coreutils installs) returns an incorrect ``unknown'' instead of ``powerpc'' that /usr/bin/uname -p will return. If uname -p returns the wrong value than some ./configure files will not work!

[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: Adeimantus on Apr 12, '04 09:03:55PM
Thanks for mentioning that! Over a week or two, I'd compiled & installed quite a few programs using the normal "configure", "make all", "sudo make install" commands (including, IIRC, updating my coreutils install from 5.2.0 to 5.2.1), all outside of fink. Then one day, fink said it needed to be selfupdated, but would error out each time I tried to run "fink selfupdate", saying something like "unsupported system type: 'unknown'".

I just tried sudo chmod -x /usr/local/bin/uname, then ran fink selfupdate, and it worked! Woohoo!

[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: jeffulri on Apr 12, '04 09:12:12PM

It's always fun to see UNIX gearheads try to teach us MAC geeks how to do something fun. The down side is, that Mac OS X does NOT function like other UNIXes. .profile for bash will do nothing. The correct file is .bash_profile in user/home (cd ~). PLEASE don't confuse us poor folks (Wink).



[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: FenrisUlf on Apr 13, '04 12:59:12AM

actually, .profile works fine. I use it in my home directory without incident. MacOSX works remarkably similar (in some cases exactly) like a BSD variant.

---
---
Who are you that walk across the graves of giants at this late hour?



[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: FenrisUlf on Apr 13, '04 01:14:46AM

...Having said that... :) .bash_profile is read before .profile.... so if you have both, .bash_profile gets the nod if Bash finds it there.

And it doesn't continue to .profile after finding .bash_profile either. :) It's a "first come, only served" situation.

Sorry for the double posting. :D I forgot to mention that in the last one.

---
---
Who are you that walk across the graves of giants at this late hour?



[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: pjt33 on Apr 17, '04 10:10:44AM

The way bash handles initialisation is the same under OS X and Linux. Read man bash, in particular the section headed INVOCATION, to see which initialisation scripts are used in which circumstances.



[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: timhaigh on Apr 13, '04 12:41:07PM

I don't believe such a unix savvy hint claims the standard ls in 10.3 does not come with color.

The first thing I liked about the terminal in panther was I did not have to install any extra file utils in panther as the panther 'ls' does come with colours. I just aliased ls -G to ls.

I just added my usual aliases to my ~/.profile

#Aliases
alias ll='ls -la'
alias ls='ls -G' # this gives you color ls '
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -i'



[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: astack on Apr 13, '04 08:03:57PM

aliasing something to a system command is a no-no. If you're using tcsh, instead set a line in your .cshrc to say "setenv CLICOLOR". This informs ls to use color by default.

Cheers!



[ Reply to This | # ]
File Extension colors WITH Panther version of ls?
Authored by: joeschram on Apr 14, '04 06:07:42PM
All good comments here. I have a curveball...is there any way to enable the custom file extension coloring on a stock Panther install without installing the GNU version of ls? I've added the paragraph described above into my .bash_profile file and quit Terminal.app, but the new colors will not appear. The pertinent section of my .bash_profile file appears below (line breaks added so careful with the cut 'n paste):

[export TERM=xterm-color
export CLICOLOR=1

LS_COLORS='no=00;32:fi=00:di=00;34:ln=01;36:pi=04;33:so=01;35:bd=33;04:cd=33;04:or=31;01:ex=00;32:
*.rtf=00;33:*.txt=00;33:*.html=00;33:*.htm=00;33:*.doc=00;33:*.indd=00;36:*.qxd=00;36:*.ai=00;36:
*.eps=00;36:*.pdf=00;36:*.ps=00;36:*.sx=00;31:*.bin=00;31:*.tar=00;31:*.tgz=00;31:*.arj=00;31:
*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.deb=00;31:*.dmg=00;31:
*.iso=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.psd=00;35:*.png=00;35:
*.pict=00;35:*.mp4=00;37:*.mpg=00;37:*.avi=00;37:*.avi=00;37:*.mov=00;37:*.m4a=00;37:*.m4p=00;37:*.mp3=00;37:'

export LS_COLORS;
export LSCOLORS=dxfxcxdxbxegedabagacad]

Any ideas folks?

[ Reply to This | # ]
File Extension colors WITH Panther version of ls?
Authored by: pjt33 on Apr 17, '04 10:13:30AM

The version of ls which comes with Panther supports some colouring - see man ls for details. It doesn't support the level of customisation provided by GNU ls.



[ Reply to This | # ]
Install better ls, du, and df tools in 10.3
Authored by: lud.wig on Apr 29, '04 02:31:00PM
Another issue with the standard 10.3 ls is that it doesn't seem to respect the TZ environment variable.

[ Reply to This | # ]