You probably use cat
everyday. Did you know that tac
existed ? It’s
the reverse of cat
! (no, really).
It allows to reverse the contents of a file or, if used with a pipe, the output of the initial command.
Let’s see how it works by sorting a directory listing by timestamp…
# ls -alt
total 4492
drwxrwsr-t 2 owner group 712704 Mar 23 10:32 .
-rw-r--r-- 1 owner group 225 Mar 21 16:26 tmp.yBFvwxTWgC
-rw-r--r-- 1 owner group 225 Mar 21 16:26 tmp.weUOWt24Ha
-rw-r--r-- 1 owner group 231 Mar 21 16:26 tmp.nDqVvbFNOH
-rw-r--r-- 1 owner group 231 Mar 21 16:25 tmp.jC74usWw7m
-rw-r--r-- 1 owner group 225 Mar 21 16:25 tmp.hmG0ubN3fi
-rw-r--r-- 1 owner group 231 Mar 21 16:24 tmp.eSp43v7Bex
-rw-r--r-- 1 owner group 225 Mar 21 16:24 tmp.Y0PMYvW97Y
-rw-r--r-- 1 owner group 231 Mar 21 16:24 tmp.Lm9ReiWMPB
-rw-r--r-- 1 owner group 225 Mar 21 16:24 tmp.KinADAW6dE
-rw-r--r-- 1 owner group 225 Mar 21 16:24 tmp.IoaOgAWepi
-rw-r--r-- 1 owner group 231 Mar 21 16:23 tmp.E3Ff0mADCk
-rw-r--r-- 1 owner group 231 Mar 21 16:23 tmp.AkK4RtYgNK
-rw-r--r-- 1 owner group 231 Mar 21 16:23 tmp.8KR94FmFv6
-rw-r--r-- 1 owner group 225 Mar 21 16:22 tmp.1LWEUTXM6T
-rw-r--r-- 1 owner group 372 Mar 21 14:26 tmp.tGG2v3KDvc
-rw-r--r-- 1 owner group 372 Mar 21 14:24 tmp.olh4dlPOtB
-rw-r--r-- 1 owner group 372 Mar 21 14:22 tmp.Xo3v7Wl9we
-rw-r--r-- 1 owner group 372 Mar 21 14:21 tmp.lcBaMhvDJz
-rw-r--r-- 1 owner group 372 Mar 21 14:21 tmp.6DFdOfMc9I
-rw-r--r-- 1 owner group 372 Mar 21 14:20 tmp.RcuR5gtRxb
-rw-r--r-- 1 owner group 372 Mar 21 14:20 tmp.KyOZoGVgtz
-rw-r--r-- 1 owner group 372 Mar 21 14:19 tmp.5rCrUpxnqh
-rw-r--r-- 1 owner group 211 Mar 21 11:19 tmp.djGjhwDDPx
# ls -alt |tac
-rw-r--r-- 1 owner group 211 Mar 21 11:19 tmp.djGjhwDDPx
-rw-r--r-- 1 owner group 372 Mar 21 14:19 tmp.5rCrUpxnqh
-rw-r--r-- 1 owner group 372 Mar 21 14:20 tmp.KyOZoGVgtz
-rw-r--r-- 1 owner group 372 Mar 21 14:20 tmp.RcuR5gtRxb
-rw-r--r-- 1 owner group 372 Mar 21 14:21 tmp.6DFdOfMc9I
-rw-r--r-- 1 owner group 372 Mar 21 14:21 tmp.lcBaMhvDJz
-rw-r--r-- 1 owner group 372 Mar 21 14:22 tmp.Xo3v7Wl9we
-rw-r--r-- 1 owner group 372 Mar 21 14:24 tmp.olh4dlPOtB
-rw-r--r-- 1 owner group 372 Mar 21 14:26 tmp.tGG2v3KDvc
-rw-r--r-- 1 owner group 225 Mar 21 16:22 tmp.1LWEUTXM6T
-rw-r--r-- 1 owner group 231 Mar 21 16:23 tmp.8KR94FmFv6
-rw-r--r-- 1 owner group 231 Mar 21 16:23 tmp.AkK4RtYgNK
-rw-r--r-- 1 owner group 231 Mar 21 16:23 tmp.E3Ff0mADCk
-rw-r--r-- 1 owner group 225 Mar 21 16:24 tmp.IoaOgAWepi
-rw-r--r-- 1 owner group 225 Mar 21 16:24 tmp.KinADAW6dE
-rw-r--r-- 1 owner group 231 Mar 21 16:24 tmp.Lm9ReiWMPB
-rw-r--r-- 1 owner group 225 Mar 21 16:24 tmp.Y0PMYvW97Y
-rw-r--r-- 1 owner group 231 Mar 21 16:24 tmp.eSp43v7Bex
-rw-r--r-- 1 owner group 225 Mar 21 16:25 tmp.hmG0ubN3fi
-rw-r--r-- 1 owner group 231 Mar 21 16:25 tmp.jC74usWw7m
-rw-r--r-- 1 owner group 231 Mar 21 16:26 tmp.nDqVvbFNOH
-rw-r--r-- 1 owner group 225 Mar 21 16:26 tmp.weUOWt24Ha
-rw-r--r-- 1 owner group 225 Mar 21 16:26 tmp.yBFvwxTWgC
drwxrwsr-t 2 owner group 712704 Mar 23 10:32 .
total 4492
A lot of binaries will allow you to sort output and reverse it - for the stuff that doesn’t, tac can come in handy.
Share this post