Every time I use grep
and find
I'm stumbling through, which order I should type the commands: When I should write the path and when I should write the flags, if it needs double quotations or not, etc. etc.
I've Googled it many more times than I'm proud of.
For grep
# Searching all files in the directory (recursively)
grep -rni "string" *
Disecting it
command flags parameter path
grep -rni "string" *
For find
# Searching for a file by name
find . -type f -name "file-name*"
Disecting it
command path flag parameter flag parameter
find . -type f -name "file-name*"
Are there a good way of remembering, when the path should come and when the flags should come etc. (without simply Googling it every time)?
Solution attempt 1: man pages
I love the man-pages, but maybe I'm using them incorrectly. They are detailed (which is good), but if I want to get a quick example with, how to use the given command, then I struggle with the man-pages.
If I write man find
, I can see this close to the top:
SYNOPSIS
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
Solution attempt 2: Save snippet-examples that I use a lot
I can also simply save snippets that I use a lot, so I quickly can load a working example.
But what do other people do here? Is this intuitive for everyone else?
find
is a bit of an odd case, its options and option ordering are like no other program. It's complicated and difficult to get used to but that's because the job it does is very complex with many variables. The args for most other programs generally follow the pattern of: options & option args, then source/input files/dirs, then (if applicable) a target/destination/output filename or dir. – cas Apr 29 '22 at 11:46;
,&
,(
,*
,[
, and so on. You use single-quotes when you don't want the shell to expand variable names etc, and you use double-quotes when you do want that. See – cas Apr 29 '22 at 11:51