Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 747 Bytes

'find'_file_or_content.md

File metadata and controls

39 lines (32 loc) · 747 Bytes

Find file by name

find . -name 'filename*' # . = current directory
find /path -name 'filename*'
find /path -name 'filename*' -exec command {} \; # {} = found item

Find by type

# all files
find /path -type f
# all directories
find /path -type d

Find content in files

# show file:content
grep -rni 'pattern' /path
#    -r recursive
#    -n show line number
#    -l show filename instead
#    -i case insensitive

# or
grep -ir 'pattern' /path
grep -ir --include=*.{ext,ext1} 'pattern' /path

# 'l' - list of files
grep -irl 'pattern' /path
grep -irl --include=*.{ext,ext1} 'pattern' /path

Find latest modified

find . -type f -printf '%TF %TT %p\n' | sort | tail -1   # '-1' = show 1 file