DEV Community

Cover image for Living in the Shell #9; find (File/Directory Search) (Part 1)
Babak K. Shandiz
Babak K. Shandiz

Posted on β€’ Originally published at babakks.github.io on

2 2

Living in the Shell #9; find (File/Directory Search) (Part 1)

find πŸ”

Finds files matching given criteria.

Find by name -name/-iname

find /home/babak -name "*bash*"
Enter fullscreen mode Exit fullscreen mode
  • Finds all files/directories matching *bash* descended from /home/babak.
  • Use -iname for case-insensitive search.

Find by matching on path -path/-ipath

find ~ -path "*/config/*"
Enter fullscreen mode Exit fullscreen mode
  • Finds all files/directories that their path string include "/config/".
  • Use -ipath for case-insensitive search.

Find by RE pattern -regex/-iregex

find ~ -regextype egrep -regex '.*/(conf|config)$'
Enter fullscreen mode Exit fullscreen mode
  • Finds all files/directories that their path end with "config" or "conf".
  • Use -iregex for case-insensitive search.
  • Use -regextype egrep if you prefer grep extended RE format.

Find files (exclude directories) -type f

find ~ -type f -name "*bash*"
Enter fullscreen mode Exit fullscreen mode

Find directories -type d

find ~ -type d -name "Do*"
Enter fullscreen mode Exit fullscreen mode

Limit recursion depth -maxdepth/-mindepth

find ~ -maxdepth 2 -type f -name "*.txt"
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay