1

I want to find files which have abc in its name.

For example:

Dozain123.ctabcln_WbLogReq.log'

Dozain123.ctabcln_WbLogReq123.log

Dozain123.ctabcln_WbLogReq456.log

Dozain123.ctabcln_WbLogReq341.log

Which command should I use?

Baraujo85
  • 698

2 Answers2

3

If it's files in the current directory that you want to list:

ls ./*abc*

To loop over these files:

for fname in ./*abc*; do
    # do something with "$fname"
done

If you want to find them in the current directory or anywhere in some subdirectory (recursively):

find . -type f -name '*abc*' -print

(this assumes that all names that you want to find are names of regular files, i.e. not names of directories etc.)

If you want to do something with these names:

find . -type f -name '*abc*' -exec sh -c '
    for fname do
        # do something with "$fname" here
    done' sh {} +

Using the ** globbing pattern available in some shells (by default in zsh and with shopt -s globstar in bash) to do a recusive matching of filenames:

for fname in ./**/*abc*; do
    # do something with "$fname"
done

With the zsh shell, also making sure that we only match names of regular files (i.e. not directories etc.):

for fname in ./**/*abc*(.); do
    # do something with "$fname"
done

Related:

Kusalananda
  • 333,661
-1

if you want to find all abc name in file: $ grep -R abc ./Direction

or if you want to find file who contain abc: $ ls -1 | grep abc or $ ls abc ./Direction