LINUX

LINUX HEAD指令

介紹

head指令用來檢視檔案的前十行。

語法

head [options] [files]
Code language: Bash (bash)

常用的options

-n N Print the first N lines instead of 10. -N Same as -n N. -c N Print the first N bytes of the file. -q Quiet mode: when processing more than one file, don't print a banner above each file. Normally, head prints a banner containing the filename.
Code language: plaintext (plaintext)

範例

你可以檢視檔案的前十行,或預覽檔案:

⤍ head myfile
Code language: Bash (bash)

搭配萬用字元,你可以預覽所有myfile開頭的檔案:

⤍ head myfile*
Code language: Bash (bash)

當資料非常多時,可以搭配管線less指令讓閱讀更方便:

⤍ head myfile* | less
Code language: Bash (bash)

搭配ls指令,你可以查看最近10筆修改的檔名:

⤍ ls -at | head ⤍ ls -alt | head
Code language: Basic (basic)

發佈留言