歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

每天一個Linux命令(14)head命令

head命令用於顯示文件的開頭的內容。在默認情況下,head命令顯示文件的頭10行內容。如果指定了多於一個文件,在每一段輸出前會給出文件名作為文件頭。

如果不指定文件,或者文件為"-",則從標准輸入讀取數據。[b] (1)用法:[/b]

用法: head [選項]... [文件]...[b] (2)功能:[/b]

將每個指定文件的頭10 行顯示到標准輸出。[b] (3)選項參數:[/b]

1)-q             隱藏文件名 2)-v             顯示文件名

3)-c<字節>          顯示字節數 4)-n<行數>          顯示的行數

[b] (4)實例:[/b] 1)[root@localhost Documents]# head head_text       默認顯示文件的前10行

[root@localhost Documents]# ll
總用量 12
-rw-r--r--. 1 root root 664 5月   9 07:59 head_text
-rw-r--r--. 1 root root  45 5月   9 08:15 less1
-rw-r--r--. 1 root root  57 5月   9 08:16 less2
[root@localhost Documents]# head head_text
I am studing orders of Linux!
I am trying to write as many as lines of text!

No matter how low you consider yourself,
there is always someone looking behind you,
hoping that they were that high!

Something you want keep all the time,always you will lose!
2)[root@localhost Documents]# head -5 head_text 與 [root@localhost Documents]# head -n 5 head_text    相同的功能:自定義顯示文件前5行

[root@localhost Documents]# head -5 head_text
I am studing orders of Linux!
I am trying to write as many as lines of text!

No matter how low you consider yourself,
[root@localhost Documents]# head -n 5 head_text
I am studing orders of Linux!
I am trying to write as many as lines of text!

No matter how low you consider yourself,
3)[root@localhost Documents]# head -c 20 head_text       指定自定義顯示前20個字節的內容

[root@localhost Documents]# head -c 20 head_text
I am studing orders [root@localhost Documents]# 
[root@localhost Documents]# head -c 60 head_text
I am studing orders of Linux!
I am trying to write as many a
4)[root@localhost Documents]# head -c -50 head_text       指定除末尾的50個字節外全部顯示

[root@localhost Documents]# head -c -50 head_text
I am studing orders of Linux!
I am trying to write as many as lines of text!

No matter how low you consider yourself,
there is always someone looking behind you,
hoping that they were that high!

Something you want keep all the time,always you will lose!

Never forget to say "thanks"!

Hppay today,also,prepared for happiness in the future!

Don't aim your success if you want it,just do what you love and believe and finally you will success!

Maybe you can be laze man like a pig,but you can't feel free as it!

I am a college school student!
I am planning to live and work in hangzhou or guangzhou!
I am from[root@localhost Documents]#
5)I am from[root@localhost Documents]# head -n -10 head_text         除最後10行外全部顯示

I am from[root@localhost Documents]# head -n -10 head_text
I am studing orders of Linux!
I am trying to write as many as lines of text!

No matter how low you consider yourself,
there is always someone looking behind you,
hoping that they were that high!

Something you want keep all the time,always you will lose!

Never forget to say "thanks"!

[root@localhost Documents]#
6)[root@localhost Documents]# head -v less1 less2         顯示多個文件,並且在顯示前打印出每個文件的文件名

[root@localhost Documents]# head -v  less1 less2
==> less1 <==
Lost means Get!

No losing No getting!

End!

==> less2 <==
If you want keep,you always lose!

Certainly It is!
End!
-v參數是默認的,即是不加也會如此:

[root@localhost Documents]# head less1 less2
==> less1 <==
Lost means Get!

No losing No getting!

End!

==> less2 <==
If you want keep,you always lose!

Certainly It is!
End!
7)[root@localhost Documents]# head -q -n 3 less1 less2 head_text -q參數用來指定顯示多個文件,不加文件名。同時也可以用-n 10指定只顯示前3行

[root@localhost Documents]# head -q -n 3 less1 less2 head_text
Lost means Get!

No losing No getting!
If you want keep,you always lose!

Certainly It is!
I am studing orders of Linux!
I am trying to write as many as lines of text!

[root@localhost Documents]#
8)[root@localhost Documents]# head --help

[root@localhost Documents]# head --help
用法:head [選項]... [文件]...
Print the first 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=[-]K         print the first K bytes of each file;
                             with the leading '-', print all but the last
                             K bytes of each file
  -n, --lines=[-]K         print the first K lines instead of the first 10;
                             with the leading '-', print all but the last
                             K lines of each file
  -q, --quiet, --silent    不顯示包含給定文件名的文件頭
  -v, --verbose        總是顯示包含給定文件名的文件頭
      --help        顯示此幫助信息並退出
      --version        顯示版本信息並退出

K 後面可以跟乘號:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, 對於T, P, E, Z, Y 同樣適用。

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
請向<http://translationproject.org/team/zh_CN.html> 報告head 的翻譯錯誤
要獲取完整文檔,請運行:info coreutils 'head invocation'
9)[root@localhost Documents]# head --version

[root@localhost Documents]# head --version
head (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
許可證:GPLv3+:GNU 通用公共許可證第3 版或更新版本<http://gnu.org/licenses/gpl.html>。
本軟件是自由軟件:您可以自由修改和重新發布它。
在法律范圍內沒有其他保證。

由David MacKenzie 和Jim Meyering 編寫。

Copyright © Linux教程網 All Rights Reserved