I’ve been searching for commands that would print the list of filenames that contain a specific string, regardless if the string is part of a bigger string.
So for instance, say there’s a directory with files "DABC.txt"
, "ABC.txt"
, "ABC"
, and "CDA.txt"
. Then if I want to search for all filenames that contain the word “ABC”, the command I’m looking for should print out "DABC.txt"
, "ABC.txt"
, and "ABC"
.
I thought find -name
would work here, but it only prints out filenames with an exact string that matches the keyword; it does not print out filenames that contain the keyword as a part of a string of the filename, not the whole string by itself. (Like "DABC.txt"
)
Would there be an alternative for this? Thanks in advance.
Advertisement
Answer
its pretty simple
list files using ls
ls -lrt *ABC*
list directory using ls
ls -ld *ABC*
using ls and grep
ls -l | grep -i "ABC"
using find command
find . -name '*abc*'
using case insensitive search in find
find . -iname '*abc*'