鍍金池/ 教程/ Linux/ head命令
which命令
ss命令
cp命令使用示例
ps命令
find命令
grep命令
scp命令
rmdir命令
df命令示例
less命令
du命令示例
chown命令示例
route命令
ping命令
more命令
mv命令
ln命令
mkdir命令
rm命令
find命令常用參數(shù)示例
cat命令
find命令-xargs參數(shù)
touch命令
traceroute命令
gzip命令示例
date命令
ls命令
vmstat命令
lsof命令
diff命令
head命令
watch命令
ifconfig命令
cd命令
tail命令
iostat命令
chgrp命令示例
free命令
find命令-exec參數(shù)
tar命令打包解壓示例
cal命令
at命令
netstat命令
wc命令
chmod命令示例
pwd命令
top命令詳解示例
crontab命令(Linux定時(shí)任務(wù))
whereis命令
Linux命令大全教程
nl命令
rcp命令
locate命令

head命令

headtail 就像它的名字一樣的淺顯易懂,它是用來顯示開頭或結(jié)尾某個(gè)數(shù)量的文字區(qū)塊,head 用來顯示文件的開頭至標(biāo)準(zhǔn)輸出中,而 tail 想當(dāng)然爾就是看文件的結(jié)尾。

1.命令格式

head [參數(shù)]... [文件]...

2.命令功能

head 用來顯示檔案的開頭至標(biāo)準(zhǔn)輸出中,默認(rèn)head命令打印其相應(yīng)文件的開頭10行。

3.命令參數(shù)

  • -q 隱藏文件名
  • -v 顯示文件名
  • -c<字節(jié)> 顯示字節(jié)數(shù)
  • -n<行數(shù)> 顯示的行數(shù)

4.使用實(shí)例

實(shí)例1:顯示文件的前n行

命令:

head -n 5 log.log

演示操作及輸出:

[yiibai@localhost test]$ cat log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

this is line5.

this is line 6.
this is line 7.
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
this is line 19.
this is line 20.
this is line 21.
this is line 22.

-----------------end
[yiibai@localhost test]$ head -n 5 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

[yiibai@localhost test]$

實(shí)例2:顯示文件前n個(gè)字節(jié)

命令:

head -c 20 log.log

演示操作及輸出:

[yiibai@localhost test]$ head -c 20 log.log
this is line 1.
this[yiibai@localhost test]$

實(shí)例3:文件的除了最后n個(gè)字節(jié)以外的內(nèi)容

命令:

head -c -32 log.log

演示操作及輸出:

[yiibai@localhost test]$ head -c -32 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

this is line5.

this is line 6.
this is line 7.
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
this is line 19.
this is line 20.
this is line 21.
[yiibai@localhost test]$

實(shí)例4:輸出文件除了最后n行的全部內(nèi)容

命令:

head -n -6 log.log
```shell
演示操作及輸出:
```shell
[yiibai@localhost test]$ head -n -6 log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

this is line5.

this is line 6.
this is line 7.
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
[yiibai@localhost test]$

上一篇:df命令示例下一篇:more命令