--- title: head โ€” view the beginning of a file date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A command to quickly check only the first few lines of a file. Useful for inspecting headers, configuration, and CSV files. tags: program, server log recording and analysis, head --- **๐Ÿ’ฌ "head command"** head displays the **first N lines** of a file. It is useful for checking the header of a formatted file. Use it to quickly understand the structure before opening a large file. - **Concept**: Prints the beginning of a file (10 lines by default). - **Left argument**: Use -n number to specify the number of lines. - **Right argument**: The target file. - **Multiple files**: With multiple files, it shows the beginning of each file along with a per-file header. ## Commonly used options | Option | Description | | --- | --- | | -n | Prints the first N lines | | -q | Suppresses file name headers when processing multiple files | | -c | Prints the first N bytes instead of lines | ## 3 essential command combinations - `head -n 1 /var/log/nginx/access.log` โ€” Check the format with the first log line - `head -n 3 data.csv` โ€” Check the first 3 CSV header lines - `head -c 64 /opt/app/bin/app.bin | xxd | head` โ€” Check the binary signature **๐Ÿ’ฌ "Give me an example from a security audit perspective"** Here are common situations on a production server, organized in order. ### Step 1 ยท Check the format Understand the structure with the first few lines of the file. ``` head -n 2 /etc/nginx/nginx.conf ``` ### Step 2 ยท Compare samples Compare the beginning of several files. ``` head -n 2 /var/log/nginx/*.log ``` ### Step 3 ยท Check binary View byte-level output if necessary. ``` head -c 32 /opt/app/bin/app | xxd ``` ## How it is used in practice ### 1. Check CSV columns **Situation** โ€” You need to check the column order of an uploaded CSV first. ``` head -n 3 /srv/import/orders.csv ``` **Result** โ€” Check the column order and delimiter with the header and two sample lines. **Point** โ€” Checking the format with head before writing an import script reduces trial and error. ### 2. Check the first block of a config file **Situation** โ€” You want to quickly see only the first structure among several server blocks. ``` head -n 20 /etc/nginx/nginx.conf ``` **Result** โ€” Quickly understand the global settings and include structure. **Point** โ€” Use head to grasp the structure before opening the full file, then inspect in detail with less. ## Points to watch - The default is 10 lines, so unless you specify the number of lines, you may not get enough information. - If you set the number of lines too high, using head loses its purpose. - If a CSV has fields containing line breaks, simple line counting will be off. ## Actual output This is the result of checking the header and sample lines of a CSV file. ![head command output: CSV header and samples](https://games.aidebatehub.com/assets/head-demo.png) Production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/logs/head.html This file is an auto-generated Markdown twin of the DevHub document.