---
title: "我使用过的Linux命令之tac - 与cat相反的命令"
author: "codingstandards"
date: "2010-12-01T19:49:02Z"
tags: ["Bash", "Blog", "Linux", "MySQL", "Oracle"]
categories: ["操作系统"]
slug: "linux-tac-cat"
draft: false
lastmod: "2010-12-01T19:51:16Z"
id: 830800
url: "https://codingstandards.iteye.com/blog/830800"
---

# 我使用过的Linux命令之tac - 与cat相反的命令

本文链接：[http://codingstandards.iteye.com/blog/830800](/blog/830800)   （转载请注明出处）

## 用途说明

cat命令可以显示文件的内容，它反过来写就是tac，而tac恰巧也是一个Linux命令，它的功能就是把文件内容反过来显示，文件内容的最后一行先显示，第一行最后显示。Linux世界的人们好玩吧！

## 常用参数

## 使用示例

### 示例一

\[root@new55 ~]# cat 1.txt  
1  
2  
3  
4  
5  
\[root@new55 ~]# tac 1.txt  
5  
4  
3  
2  
1  
\[root@new55 ~]#

### 示例二

来自相关资料【1】的实例

tac -- 反过来串连?! cat 倒过来怎么拼 ? 对啦 !! 这就是 tac 的功能啰 ~ 它是把档案的顺序内容反过来串连用的，那么 ~ 它都用在什么状况下呢 ? 任何须要以后进先出的顺序重新排列组件的工作都用得上它 ! 以下面的指令来说，便是以自最后建立的到最先建立的顺序，列出三个最新建的使用者帐号：last 3 /etc/passwd records - in reverse

\[root@new55 ~]# tail -3 /etc/passwd | tac  
mysql:x:101:104:MySQL server:/var/lib/mysql:/bin/bash  
oracle:x:500:500::/opt/oracle:/bin/bash  
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin  
\[root@new55 ~]#

## 问题思考

## 相关资料

【1】跟我学电脑  [LinuxShell一些很少用到却很有用的指令](http://www.gwxdn.com/html/system/linux/2010/0501/9211.html)  

【2】Linux公社  [关于LINUX中的cat、tac、rev命令](http://www.linuxidc.com/Linux/2007-05/4065.htm)

【3】鸟哥的私房菜  [直接檢視檔案內容： cat, tac, nl](http://linux.vbird.org/linux_basic/0220filemanager.php#tac)

【4】本系列 [我使用过的Linux命令之cat - 连接文件或标准输入并打印](/blog/801090)  

 

返回 [我使用过的Linux命令系列总目录](/blog/786653)