Commands
  • About
  • Software Development
    • Glossary
    • System Design
      • CAP Theorem
      • Data Migration
      • EAV Model
      • ETL Process
      • Event Sourcing
      • Outbox Pattern
      • SOLID Principles
    • Standards
      • Character Encoding
      • Twirp
    • Elixir
      • IEx
      • Mix
      • Libraries
      • Code Snippets
    • Node.js
      • TypeScript
  • Commands
    • Bookmarks
    • AWS
      • Athena
      • ECS
    • Docker
      • Manage Images
      • Manage Containers
    • File System
      • Grep
      • Search Files
      • Miscellaneous
    • Git
      • Setup New Project
      • Manage Remotes
      • Release Project
    • GPG
    • Kafka
      • Quick Start
    • Kubernetes
    • OpenShift
      • Manage Roles and Bindings
    • PostgreSQL
    • SSL / TLS
      • Common OpenSSL Commands
      • Create Self-signed Certificate
      • Java Truststore and Keystore
    • SSH
      • Key Management
      • Port Forwarding
    • YUM
      • List Repositories
      • List Packages
    • Miscellaneous
      • Network
Powered by GitBook
On this page
  • Search By Metadata
  • Search By Content
  • Replace the Content in Multiple Files
  1. Commands
  2. File System

Search Files

PreviousGrepNextMiscellaneous

Last updated 3 years ago

Search By Metadata

find <PATH> [-name <PATTERN>] [-type <FILE_TYPE>] [-delete]

<FILE_TYPE>: regular file (f), directory (d), symlink (l), etc.

Execute Command After "find"

# Run the CMD on each result
# Example CMD: `dirname {}`

find ... -exec <CMD> \;
# OR
find ... -print0 | xargs -0 -n1 -I {} <CMD>

# Run the CMD on the whole result

find ... -exec <CMD> \+
# OR
find ... -print0 | xargs -0 -I {} <CMD>

Search By Content

grep -inr '<SEARCH_PATTERN>' <FILENAME_PATTERN>

-i: Case-insenstive -n: Display line number -r: Search the files recursively

Replace the Content in Multiple Files

sed -i 's/foo/bar/g' *

# or for BSD systems like MacOS
sed -i '.bak' 's/foo/bar/g' *

Reference: https://stackoverflow.com/a/11392505

Differences between find -exec and find | xargs