Narzędzia użytkownika

Narzędzia witryny


Pasek boczny

so:pipes_filters:head_tail

user@host ~ $ cat nums.txt
one
two
three
four
five
six
seven
eight
nine
ten
user@host ~ $ head -n2 nums.txt
one
two
user@host ~ $ head -c5 nums.txt           # ┌ the 5 bytes are: "one\nt"; notice no trailing newline
one                                       # └ that clutters next prompt with part of the output
tuser@host ~ $head -n -9 nums.txt         # this skips last 9 lines in file
one
user@host ~ $ tail -n1 nums.txt
ten
user@host ~ $ tail -n+9 nums.txt          # ┌ this skips 8 first lines
nine                                      # └ (starts printing from 9th line)
ten
user@host ~ $ tail -c7 nums.txt           # the 7 bytes are: 'ne\nten\n'
ne
ten
user@host ~ $ ps
  PID TTY          TIME CMD
 7243 pts/5    00:00:00 bash
 7332 pts/5    00:00:00 ps
user@host ~ $ ps | tail -n+2              # real-world example: getting rid of a header
 7243 pts/5    00:00:00 bash
 7334 pts/5    00:00:00 ps
 7335 pts/5    00:00:00 tail
user@host ~ $ tail -n1 /var/log/messages  # real-world example: displaying most recent entries in a log
Jan  1 00:00:00 host kernel: OOM killer enabled.

so/pipes_filters/head_tail.txt · ostatnio zmienione: 2023/03/31 12:59 przez jkonczak