Tuesday, November 1, 2011

UNIX & GNU/Linux --- How to printout a text file in the reverse order: cat & tac

Sometimes, we can feel a kind of urge to print out a text file in the reverse order. (For example, dmesg log file). Maybe you want to try `tac', the reverse of `cat'. The below is an example:

=================================================

텍스트 파일을 stdout에 출력할 때 cat, more, tail 따위를 많이 쓰시지요.
가끔은 텍스트 파일을 (로그 파일같은 것은) 밑에서부터 거꾸로 읽고 싶은 욕구가 강하게 치밀지요.
이럴 때 한 번 써보세요: tac 아래 활용례 나갑니다.

=================================================


sajang@ubuntu64:~$ cat /var/log/dmesg | tail
[   22.567973] NET: Registered protocol family 31
[   22.567979] Bluetooth: HCI device and connection manager initialized
[   22.567984] Bluetooth: HCI socket layer initialized
[   22.567985] Bluetooth: L2CAP socket layer initialized
[   22.571909] Bluetooth: SCO socket layer initialized
[   22.583921] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   22.583922] Bluetooth: BNEP filters: protocol multicast
[   22.584569] Bluetooth: RFCOMM TTY layer initialized
[   22.584573] Bluetooth: RFCOMM socket layer initialized
[   22.584575] Bluetooth: RFCOMM ver 1.11
sajang@ubuntu64:~$ tac /var/log/dmesg | head
[   22.584575] Bluetooth: RFCOMM ver 1.11
[   22.584573] Bluetooth: RFCOMM socket layer initialized
[   22.584569] Bluetooth: RFCOMM TTY layer initialized
[   22.583922] Bluetooth: BNEP filters: protocol multicast
[   22.583921] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   22.571909] Bluetooth: SCO socket layer initialized
[   22.567985] Bluetooth: L2CAP socket layer initialized
[   22.567984] Bluetooth: HCI socket layer initialized
[   22.567979] Bluetooth: HCI device and connection manager initialized
[   22.567973] NET: Registered protocol family 31

No comments:

Post a Comment