-4

How to use ls command for searching specific files in current directory. Let's say where file name contains "localhost".

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
user1934643
  • 165
  • 1
  • 10

1 Answers1

2

Take advantage of globbing. See glob(7) for details. So try

ls *localhost*

If you want to search recursively in a directory for some file, use find(1) (or, from some C program, the nftw(3) function).

Perhaps you want

find . -name '*localhost*' -exec ls {} +

Some shells, notably zsh, have recursive globbing. I am using zsh as my login shell, so I can type

ls **/*localhost*

BTW, you might be interested by xargs(1) (very useful when combined with find). Of course, take time reading documentation of ls(1).

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547