0

Why the following doesn't include hidden files ?

ls -a *vim* 

that will return

 ls: cannot access '*vim*': No such file or directory

ls -a | grep vim 
.vim
.vimrc
  • 1
    Also, shell globs (filename pattern matches) are not the same as regexes in the usual sense. (As used by sed etc.) – ilkkachu Oct 6 '16 at 17:41
2

If you are explicitly looking for hidden files use a pattern that starts with dot,

ls .*vim*

Then there's no need for the -a flag.

5

It's the shell that finds the filenames matching the pattern, not ls itself. So you have to get the shell to include names starting with a dot, either using shopt -s dotglob before the ls command, or by specifically including the dot in the pattern: .*vim*. Though note that if the pattern matches directories, ls will list their contents (and this is where -a will matter, since now it's ls listing the files). To prevent that, use ls -d.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.