Keeping up with class: From here on, commands will sometimes be more complicated A lot of times, some minor point is missed Don't feel bad, happens all the time Then it causes a command to be not quite understood Which prevents learning whatever it was supposed to teach you Then it turns into a bigger problem So if a command doesn't make sense, ask me to explain it again A couple things that will help you be fast: tab completion up arrow to cycle through old commands ctrl+r to search for old commands press it again to find the next result Enter if you find it A general note on special characters: Shell processing may change them! 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 Commands typically work like this. Spaces are separators! Like in English Commands never contain a space Files usually do not - Some people like to put them in filenames - Programmers usually don't If you need an actual space in a filename, there are two options: - Use quotes, "bad filename" - Use \, the escape character, bad\ filename Where to specify in the command line: Generally speaking, flags can be specified in any order 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 include -h, -v, --help, or --verbose Not all, but it is very common If commands have a mandetory 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 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 Homework 2, and the class of problems that grep solves The source tree is at /usr/src/linux-source Let's find comments about Linus Torvalds How many files does he hold the copyright for? How many files have a space in the name? How many files are in the c language? - They'll end in .c - We need $ - ^ is the other end The dictionary is in /usr/share/dict What words have "note" in them? Intro to expressions: . means any character 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 homework 2 - Feel free to use a better method if you like An expression with grep: - Regular expressions can handle this. We'll learn a piece today - Demo anyway with .* - 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. Probably can solve the homework 2 without them, but they might help At this point, see a command as an assembly line