Some flags are not complete on their own. They need a value: a word that comes right after the flag.
head and tail
head writes the first lines of a file. tail writes the last lines. With no flag, they write 10 lines.
The flag -n sets the number of lines. Its value is the number:
headcommand-nflag3value of -ndeploy.logargument (the file)
text
learner@tidepool:~$ head -n 3 deploy.log
09:00 deploy started for billing
09:01 pulling release 4.8.1
09:02 running database migration
learner@tidepool:~$ tail -n 1 deploy.log
09:07 rollback finishedIn the last lesson, -n told cat to number the lines. For head and tail, -n takes the number of lines to write. Each program decides what its flags mean.
Three ways to write the value
| Form | Example |
|---|---|
| Short flag, space, value | head -n 3 deploy.log |
| Short flag, value, no space | head -n3 deploy.log |
Long flag, =, value | head --lines=3 deploy.log |
When the value is missing
The program takes the next word as the value. If you forget the number, the next word is the file name:
text
learner@tidepool:~$ head -n deploy.log
head: invalid number of lineshead read deploy.log as the number of lines. A file name is not a number.