Skip to content

Latest commit

 

History

History
68 lines (40 loc) · 1.22 KB

find.md

File metadata and controls

68 lines (40 loc) · 1.22 KB

find

👋 Errors, improvements or other cool stuff? Let me know! 😀

Exec

Format: -exec <command> <terminator>

  • {}: Is replaced by the current file name being processed. It doesn't have to be quoted ("{}").
  • \;: As ; has a meaning for the shell, it must be escaped for find to get it.

\; vs. +:

  • With ;, the command is executed on each matched item.

    Command: find . -type f -exec echo {} \; | wc -l
    Similar to: echo 1; echo 2; echo 3
    Result: 3

  • With +, the command is executed once with the list of all the matched items.

    Command: find . -type f -exec echo {} + | wc -l
    Similar to: echo 1 2 3
    Result: 1

Regex

find . -regextype posix-extended -regex "<regex>"

Find & delete

find . -name ".DS_Store" -delete
find . -type d -name "foo" -exec rm -fr {} +

Find & delete in max 2 sub-directories

find . -maxdepth 2 -name ".git*" -exec rm -rf {} \;

Another find & delete

find . -name "Icon?" -print0 | xargs -0 rm

Find broken symlinks

find -L . -type l

Find & replace in place

find . -type f -name "*.py" -exec sed -i 's/find/replace/g' {} \;