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
# define file group
find -group wheel
# by permission
find -perm 777
# find by size
find -size +1G
grep -r
exists and is even more faster and doesn’t require passing around file names.
grep -r --include='*.txt' 'somename' .
This does not need to be a 8 minute video. Read your tldw instead. Thanks, OP.
Better than the video thank you, I didn’t watch the video
Not the person above, but I know that written explanations of command line tools are always preferred by myself.
No, no, you just need to seek through the time and copy & paste the text in the video!
Just for the sake of completeness:
https://github.com/BurntSushi/ripgrep
https://github.com/ggreer/the_silver_searcher
It’s useful to be able to do this without additional tools (and there are more applications for the general command setup discussed in the video), but in practice, ease of use and performance often make a difference.
I kinda prefer xargs
to the -exec
option — just feels more UNIXy to me (do one one job well).
But as another comment said, for grep
I just use -r
and --include
. So clearly I’m not very consistent…