如果您想对文件中的各行进行逆序排序,该怎么做呢?这就要用到 tac 命令。(请注意,tac 由 cat 逆序拼写而成。)该命令对所列出的文件中的各行或各段进行逆序排序。
该命令不能逆序排序各文件的顺序 — 这个任务您得自己做,以逆向顺序在 tac 命令后列出各文件即可。作为说明 tac 的工作原理的示例,对一些文件使用 ls -l | tail 和 ls -l | tail | tac,比较其结果。
[sam@chenwy split]$ ls -l |tail 总用量 32 -rw-r--r-- 1 sam sam 1649 12月 4 11:13 passwd -rw-rw-r-- 1 sam sam 84 12月 4 11:19 split1 -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xaa -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xab -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xac -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xad -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xae -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xaf 正序
[sam@chenwy split]$ ls -l |tail | tac -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xaf -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xae -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xad -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xac -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xab -rw-rw-r-- 1 sam sam 14 12月 4 11:25 xaa -rw-rw-r-- 1 sam sam 84 12月 4 11:19 split1 -rw-r--r-- 1 sam sam 1649 12月 4 11:13 passwd 倒序
[sam@chenwy split]$ tac split1 this is line6 this is line5 this is line4 this is line3 this is line2 this is line1 对文件操作 |