Search code examples
linuxaliases

ls aliases in .bash_aliases interfering with egrep output


I have the following lines in my .bash_aliases file:

# Prettify and streamline listings
alias ls='ls --color'
alias ll='ls -l'
alias la='ls -a'
alias lla='ls -al'
alias lF='ls -F'
alias laF='ls -laF'
alias llF='ls -lF'
alias llaF='ls -alF'

The aliases work fine but I run into trouble when piping to egrep to look for invisible files. For example, if I want to list all the invisible files in the directory, and I type la | egrep '^\.' I get no output. Even if I skip the alias and type ls -a | egrep '^\.' I still get no output. If I leave out the caret, it works, but of course in that case egrep lists all files with a period in the filename, not just those that begin with a period.

However, if I rename the .bash_aliases file and log in again, so that these aliases are not active, then ls -a | egrep '^\.' works just fine to list the invisible files. Very odd.

I am trying to figure out why this is happening and I'm drawing a blank. Any ideas? Thanks!


Solution

  • Try the following command and you will see some the reason:

    ls --color | cat -v
    

    You should use the alias ls='ls --color=auto' instead of ls='ls --color'.