linux find file in directory code example

Example 1: linux find any file linux

#find a file and print with path
find . -print | grep -i *.txt

Example 2: find by name linux

# dot is curr dir 
find . -name "*.txt"

Example 3: find file

Extremely useful command!!
In Mac and Linux: Define directory where to search as "." for current directory
and then specify the name or regex of file or folder to find.

find . -name "foo*"  

In Windows: Define "/s" for a recursively search and name or regex of file or
folgder to search

dir /s "foo*"

Example 4: how to search in a directory files in linux

# this will search all subdirectories for text (no case sensitivity)
grep -inR "your text" .
# Node: this command will search for text INSIDE Files, not file names

Example 5: bash find file in directory

$ ls -R | grep -i "pattern"

Example 6: linux find file

# syntax 
# find *</path/to/dir> '(' *<Filter-1> *<and/or-operator> *<filter-2> ')'

# example 
find . '(' -name "Test*.pm" -a ! -name 'Useless*' ')'