0

Is there any option I can pass to ls to hide .un~ files from the output?

I want to be able to see all files (e.g. dotfiles) except .un~ files, so I need to run ls -A and add something to hide the .un~ files.

2 Answers 2

2

Homebrew does provide GNU ls through the coreutils package.

brew install coreutils

Then, you could alias your system ls to GNU ls, which Homebrew installs as gls instead in order to prevent overriding the usage of system binaries:

alias ls='/usr/local/bin/gls'

Alternatively, as outlined in brew info coreutils:

If you really need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc like:

PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"

Proceed with using GNU ls options if they better suit your needs, e.g.

ls -B

or similarly:

alias ls='/usr/local/bin/gls --hide=*~'
-2

ls -B

Hides backups, files ending in ~

4
  • Doesn't work on my MacBook Pro, I am still seeing the .un~ files
    – gws
    Jun 1, 2012 at 20:31
  • 1
    -1, this only applies to GNU ls, the -B option has a totally different meaning in OS X (or BSD ls for that matter).
    – slhck
    Jun 1, 2012 at 20:34
  • @gws The question is if you would be fine with changing ls, i.e. compiling and aliasing to GNU ls, thus deviating from what comes with OS X.
    – slhck
    Jun 1, 2012 at 20:41
  • @slhck I guess so, I typically use homebrew but it doesn't provide a GNU ls
    – gws
    Jun 1, 2012 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .