---
title: "linux查看文件内容命令"
author: "benniaolk"
date: "2013-10-16T10:20:37Z"
tags: []
categories: ["操作系统"]
slug: "linux"
draft: false
lastmod: "2013-10-16T10:20:37Z"
id: 1958704
url: "https://dreava.iteye.com/blog/1958704"
---

cat   由第一行开始显示文件内容  
tac   从最后一行开始显示  
nl    显示同时输出行号  
more  一页一页的显示内容  
less  与more类似，但其优点是，可以往前翻页  
head  只看头几行  
tail  只看未尾几行  
od    以二进制的方式读取文件内容

 

cat \[-n]  
\-n连行号一起输出到屏幕上 与nl相似

 

more \[文件名]  
more test.txt将test.txt一页一页的显示出来  
ls -al | more将ls显示的内容一页页显示出来

 

less \[文件名]  
less的用法比more更有弹性，使用less可以用pageup、pagedown翻看   
less test.txt  
/word   
在test.txt中搜寻word这个字符串   
:q 退出less

 

head \[-n number] \[文件名]  
\-n显示number行  
head -n 20 test.txt   
显示test.txt前20行

 

tail \[-n number] \[文件名]  
\-n显示number行  
tail -n 20 test.txt  
显示test.txt后20行

 

head -n 20 test.txt | tail -n 10  
取11-20行

hexdump