TL;DW

# find with grep
# + concatinates results and runs the command once, faster
find . -name "*.txt" -exec grep -l "somename" {} +

# run a command for each result individually
find . -name "*.txt" -exec basename {} \; |  column

# case insensitive
find -iname "SoMeNaMe.TxT

# file or dir
find -type f
find -type d

# define file owner
find -user Bob

# by permission
find -perm 777

# find by size
find -size +1G
  • unalivejoy@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    6 months ago

    If you have a very large directory, find will check each individual file, even when -path doesn’t match, which makes it take longer to complete. Combine -o and -prune to omit them entirely.

    find . -path '**/node_modules/**' -prune -o -type f -name '*.js' -exec grep 'import' {} +