CLI Piping
Commands
grep = print lines matching a pattern less = view the contents of a text file wc = print the number of newlines, words, and bytes in files cat = concatenate files and print on the standard output find = search for files in a directory hierarchy sort = sort lines of text files uniq = condense duplicate lines
awk = pattern scanning and text processing language lsof = list open files xargs = build and execute command lines from standard input
The Pipe Character
The pipe is the vertical bar, '|', it allows you to send the output from one command, as input to a second command. It allows you to combine two or more commands to process data using combinations of commands. It is very useful, but requires you to have a strong understanding of the commands that you're going to combine. As you use the command line more, you'll become more familiar with the commands and you'll start to understand which commands make sense to pipe together and which ones don't. Each side of the pipe is a an individual statement, with a command, possible options and possibly some other information that the command needs.
Examples
Count the number of files in the ~/examples directory
ls ~/examples | wc -w
'ls ~/examples' returns
adv_cli bash_script basic_commands c_example media_example
'wc -w' counts the number of words (words are sets of characters surrounded by whitespace. So, when you combine the two you are counting the number of files that were listed.
Example 2
Quiz
- Run 'dmesg', pipe it to 'sort' and then to 'uniq'
- Question 2