Finding Something

Using tools to find files, keywords in the Linux Filesystem

For using regular expressions with the following commands, checkout the Regular Expressions Cheatsheet

GREP

Find keywords inside files

Finding Keywords inside files recursively and print the file names

grep -rl "<keyword>" <path>
# grep -rl "service" /root

Using regular expression

Some other useful CLI options for grep

Flag
Meaning

-i

Ignore case

-c

Print count of matching lines

-v

Return all lines which don't match the pattern

FIND

Find files on the file system and maybe modify permissions (in bulk) if needed.

#Syntax:
#find options starting/path expression

find / -name abc.txt 

Find files based on the time they were modified

-mtime

Find files recursively

-maxdepth -> At max how many subdirectories should it traverse

-mindepth -> Ignore the results before the depth specified.

-mount -> Find files on this FS only.

Set File Permissions in bulk

-exec -> Execute shell commands

Last updated