Jump to content

* * * * - 1 votes

Alias for colorized `ls` for GNU and BSD ls

  • Please log in to reply
No replies to this topic

#1 systems_glitch


    Dangerous free thinker

  • Moderating Team
  • 1,770 posts
  • Gender:Male

Posted 01 August 2013 - 10:29 AM

I recently committed my dotfiles to a git repo, and discovered that GNU ls and BSD ls use different switches to colorize output. Using the GNU switch with BSD ls results in ls not working until you unalias it! Here's a snippet from my .bashrc that takes care of it:

# alias `ls` for color mode
if ls --color=auto / >/dev/null 2>&1
alias ls='ls --color=auto' # GNU ls
alias ls='ls -G' # BSD ls

Basically, if the GNU switch works, use the GNU switch; otherwise, use the BSD switch.

  • AlexaEl likes this

BinRev is hosted by the great people at Lunarpages!