Thursday, June 11, 2026

Change permissions with find command example.

 Basic Example: Find and chmod
To find and delete all .log files in the current directory and its subdirectories, use this command: [1, 2, 3]
bash
find .  -exec chmod 777 {} \;
Use code with caution.
Understanding the Syntax Breakdown
  • find .: Starts the search in the current directory.
  • options follow
  • -type f: Restricts the search specifically to files, ignoring folders.
  • -name "*.log": Matches files with a .log extension.
  • -exec: Tells find to run a command on every match.
  • chmod 777: The external command you want to run.
  • {}: A placeholder that find dynamically replaces with the filename of each match.
  • \;: Terminates the -exec sequence. The backslash escapes the semicolon so your shell does not process it first.

No comments:

Post a Comment