Linux commands are small, and each does one job well. The pipe, |, joins them: the output of the command on the left becomes the input of the command on the right.
ls photos | wc -lls photos prints one name per line. Instead of reaching the screen, those lines flow into wc -l (word count, counting lines), which prints a single number: how many files there are.
Building a pipeline
Pipelines are built one step at a time. Run the first command, look at what it prints, then add the next:
cat names.txtsort names.txtsort names.txt | head -n 3Commands that read their input and print a changed version are called filters. You already know some:
sortputs lines in order (-rreverses it,-nsorts by number),headandtailkeep the start or the end,wc -lcounts lines,grepkeeps matching lines (next lesson).
You can chain as many as you like: sort names.txt | tail -n 5 | sort -r.
A pipe passes output, not files. wc -l photos fails because photos is a directory; ls photos | wc -l counts what ls printed.