General point today: Talk in more depth about things we've been using Note on typing commands: Remember rhythm with special characters Keep hands loose, like a bubble under your hand Use tab as soon as you can (prevents typos, validates input so far) A general note on special characters: Shell processing may change them! echo * Command line grammar, example: grep -i note /usr/share/dict/american-english This will find all lines that contain the word "note" in either case inside the file /usr/share/dict/american-english Pieces and what they are, using examples from above: grep : The command to run -i : A flag, or option. These set options to commands. note : A parameter, or argument. Input to the command that is not a flag. For grep, this is the thing to search for /usr/share/dict/american-english Another parameter. For grep, this indicates the file to search How these appear in the manual Commands typically work like this. Where to specify in the command line: Generally speaking, flags can be specified in any order - Not all commands follow this Flags can usually be combined ( -i -r should be equivalent to -ir ) Some flags may require a parameter (-o outfile) - In that case, the parameter must follow the flag - Sometimes, no space is required (-lpthread) - Sometimes, it is used (-l pthread) There are short and long options - Short: -r -h - Long: --recursive --help - Generally, long options have two dashes Most commands support -h, -v, --help, or --verbose Not all, but it is very common If commands have a mandatory parameter, they will usually print out usage info without it Sometimes commands require that flags come before parameters Usually this is due to a variable number of parameters Can't always count on that, and not all commands with variable parameters require it A programming note: These appear as parameters to main in C/C++ - Example with argc and argv In Python, you can import argv Generally, if you are writing a command-line tool, you should support flags There are libraries to help with that! - Example: Python and argparse - For C: getopt and argp Lab 2, and the class of problems that grep solves How about finding out what frequency each core is running at? How often did I put the word "grep" in my notes last time? The dictionary is in /usr/share/dict What words have "note" in them? Intro to "regular" expressions: . means any character Note that there are a few different regular expression grammars How many words are at least 10 letters long? How many words have at least two letters before two e's? How many have a z followed by two letters followed by a p? - Yes, this would be useful for scrabble Isolating things: Let's get the ipv6 address from ifconfig with head and tail - The main weakness of this: Length matters! - It'll be ok for lab 2, most people did it this way An expression with grep: - Regular expressions can handle this. We'll learn a piece today - Generally, you can match most anything with these - Regular expressions take time and practice to master - There is more than one syntax for these We learned these characters for grep: . * ^ $ Go ahead and remember these. At this point, see a command as an assembly line