head And tail

tail

  • By default, write last ten lines to stdout

    $ tail /etc/passwd
    abrt:x:173:173::/etc/abrt:/sbin/nologin
    flatpak:x:986:983:User for flatpak system helper:/:/sbin/nologin
    gdm:x:42:42:GNOME Display Manager:/var/lib/gdm:/sbin/nologin
    gnome-initial-setup:x:985:982::/run/gnome-initial-setup/:/sbin/nologin
    vboxadd:x:984:1::/var/run/vboxadd:/sbin/nologin
    sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/sbin/nologin
    tcpdump:x:72:72::/:/sbin/nologin
    jfasch:x:1000:1000:Joerg Faschingbauer:/home/jfasch:/bin/bash
    systemd-coredump:x:978:978:systemd Core Dumper:/:/usr/sbin/nologin
    systemd-timesync:x:977:977:systemd Time Synchronization:/:/usr/sbin/nologin
    
  • Write all but first N lines: -n +N, --lines +N

    $ tail -n +43 /etc/passwd
    sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/sbin/nologin
    tcpdump:x:72:72::/:/sbin/nologin
    jfasch:x:1000:1000:Joerg Faschingbauer:/home/jfasch:/bin/bash
    systemd-coredump:x:978:978:systemd Core Dumper:/:/usr/sbin/nologin
    systemd-timesync:x:977:977:systemd Time Synchronization:/:/usr/sbin/nologin
    

head And tail In The Pipe

  • Lines 8-10 to stdout

    $ head -n 10 /etc/passwd|tail -n 3
    halt:x:7:0:halt:/sbin:/sbin/halt
    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    operator:x:11:0:operator:/root:/sbin/nologin
    

    Or, less efficient (thereby winning the Useless Use Of Cat Award),

    $ cat /etc/passwd|head -n 10|tail -n 3
    halt:x:7:0:halt:/sbin:/sbin/halt
    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    operator:x:11:0:operator:/root:/sbin/nologin