Linux重要命令 head

2021-09-25 09:50:04 字數 1498 閱讀 6032

head 與 tail 就像它的名字一樣的淺顯易懂,它是用來顯示開頭或結尾某個數量的文字區塊,head 用來顯示檔案的開頭至標準輸出中,而 tail 想當然爾就是看檔案的結尾。 

1.命令格式:

head [引數]... [檔案]...  

2.命令功能:

head 用來顯示檔案的開頭至標準輸出中,預設head命令列印其相應檔案的開頭10行。 

3.命令引數:

-q 隱藏檔名

-v 顯示檔名

-c《位元組》 顯示位元組數

-n《行數》 顯示的行數

4.使用例項:

例項1:顯示檔案的前n行

命令:head -n 5 log2014.log或者head -5 log2014.log

輸出:[root@localhost test]# cat log2014.log 

2014-01

2014-02

2014-03

2014-04

2014-05

2014-06

2014-07

2014-08

2014-09

2014-10

2014-11

2014-12

[root@localhost test]# head -n 5 log2014.log 

2014-01

2014-02

2014-03

2014-04

2014-05[root@localhost test]#

例項2:顯示檔案前n個位元組

命令:head -c 20 log2014.log

輸出:[root@localhost test]# head -c 20 log2014.log

2014-01

2014-02

[root@localhost test]#

例項3:檔案的除了最後n個位元組以外的內容 

命令:head -c -32 log2014.log

輸出:[root@localhost test]# head -c -32 log2014.log

2014-01

2014-02

2014-03

2014-04

2014-05

2014-06

2014-07

2014-08

2014-09

2014-10

2014-11

2014-12[root@localhost test]#

例項4:輸出檔案除了最後n行的全部內容

命令:head -n -6 log2014.log

輸出:[root@localhost test]# head -n -6 log2014.log

2014-01

2014-02

2014-03

2014-04

2014-05

2014-06

2014-07[root@localhost test]#

linux重要命令

釋義 命令引數 示例 列目錄ls a 包括隱藏檔案 l 看詳細資訊 f 在檔案後面顯示表示檔案型別的符號 重定向 ls xx.txt管道 cmd1 cmd2 左面的輸出會作為右邊的輸入 許可權chmod chomd 777 file 切目錄cd 注意大小寫敏感 增 刪目錄 mkdir rmdir r...

linux 重要命令

檢視當前程序運 況 ps aux grep php very good ps aux grep nginx 刪除軟體命令 sudo apt get remove purge nginx 刪除nginx purge表示連配置檔案一起刪除 sudo apt get autoremove purge ng...

Linux 基礎重要命令

1.建立乙個目錄 data mkdir data 命令總結 1 mkdir 建立目錄的命令,mkdir directorys 2 ls ld directory 顯示目錄或者檔案 ls的全稱是list 3 cd 切換目錄層次 change directory 4 pwd 列印當前工作目錄 pwd的全...