Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use Git Bash as my terminal on Windows. When I ls in my Home directory, I see some NTUSER.DAT entries, which I assume are system files. They don't appear when I run dir in the default Windows Prompt.

What can I do so the ls command ignore these entries in the Git Bash as well?


share|improve this question

After some digging, I found a way around it. I put the script below in my .bashrc file, so these settings load automatically with Git Bash. This piece of code was based on a dotfiles project.

LS_COMMON="$LS_COMMON --color=auto"
LS_COMMON="$LS_COMMON -I NTUSER.DAT\* -I ntuser.dat\*"

test -n "$LS_COMMON" &&
alias ls="command ls $LS_COMMON"
alias ll="ls -l"
alias la="ls -a"
alias lal="ll -a"
share|improve this answer
Thanks a lot, I didn't even know what I was missing! Could you explain the test -n line? – Lea Aug 2 '15 at 6:46
It's testing whether the $LS_COMMON variable exists. If it exists, the next statement is going to be executed, i.e. alias ls="command ls $LS_COMMON" is going to be created. Note that I based that snippet off the dotfiles that I liked in my original answer. At the time I didn't pay attention at what that line did, as I was just worried about getting it to work. Now that I come to think of, that might not be necessary at all, as the $LS_COMMON variable is defined just above. I'll leave the answer unaltered, as it's a little bit hard for me to test if it works (don't use Windows anymore). – thalesmello Aug 11 '15 at 14:31
Ah I see. Thanks! I just tested it and it works fine for me without test -n "$LS_COMMON" && using the newest version of git bash and fresh install of windows 10. But I guess I'll leave it in. – Lea Aug 11 '15 at 21:14

I added some folder patterns to the great (!) solution of thalesmello. Those folders were disturbing me on Windows 7. Now, my home-folder in git bash is completely empty. This is it!

# refers to
# --color : On Windows7 this produces permission errors, e.g. for Music folder:
# LS_COMMON="$LS_COMMON --color=auto"
LS_COMMON="$LS_COMMON -I NTUSER.DAT\* -I ntuser.dat\*"
LS_COMMON="$LS_COMMON -I Pictures\*"
LS_COMMON="$LS_COMMON -I Start\ Menu\*"
LS_COMMON="$LS_COMMON -I Application\ Data\*"
LS_COMMON="$LS_COMMON -I Local\ Settings\*"
LS_COMMON="$LS_COMMON -I ntuser.ini"
LS_COMMON="$LS_COMMON -I ntuser.pol"
LS_COMMON="$LS_COMMON -I Favorites\*"
LS_COMMON="$LS_COMMON -I Searches\*"
alias ls="command ls $LS_COMMON"
alias ll="ls -l"
alias la="ls -al"
share|improve this answer

Thanks to previous answers, a Windows 8.1 version:

Add your alias: alias ls=ls_filter.bat $*.
Save the following as ls_filter.bat somewhere along your %PATH%:

@REM Runs ls with a filter to exclude some Windows folders, but only when run from the user's home folder.
@if "%CD%" == "%USERPROFILE%" (
    ls --color^
        -I "AppData" -I "Contacts" -I "Favorites" -I "Links"^
        -I "Music" -I "My Documents" -I "Pictures" -I "Videos" -I "Saved Games" -I "Start Menu" -I "OneDrive"^
        -I "NTUSER.*" -I "ntuser.*" -I "thumbs.db" -I "Thumbs.db" -I "desktop.ini"^
        -I "Application Data" -I "Cookies" -I "NetHood" -I "PrintHood" -I "Local Settings"^
        -I "Recent" -I "Searches" -I "SendTo" -I "Templates" %*
) else (
    ls --color -I "NTUSER.*" -I "ntuser.*" -I "thumbs.db" -I "Thumbs.db" -I "desktop.ini" %*

This makes it so the filter only applies when you're in your home directory. When in other directories, folders like Music and Videos won't be filtered out.

All of these filters make ls a little slow for me (I'm using Cmder), so I've substituted my ls for a faster version which takes the same arguments.

share|improve this answer

You must log in to answer this question.

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