--- title: less โ€” Read large files safely date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: Pager that reads and searches large files one screen at a time. Essential for checking logs and configuration on servers. tags: program, File and disk management, less --- **๐Ÿ’ฌ "less command"** less reads and displays only as much as needed **without loading the entire file into memory**. You can open multi-GB logs. cat outputs the entire file, so it is risky for large files. In practice, use less. - **Concept**: a pager that lets you view a file screen by screen. - **Navigation**: Space/PageDown next page, b previous page, g beginning, G end - **Search**: /search-term next match, ?search-term previous match, n/N repeat - **Exit**: press q to exit. ## Commonly used options | Option | Description | | --- | --- | | -N | Display line numbers | | +F | Follow in real time like tail -f | | -S | Scroll horizontally instead of wrapping long lines | | +G | Jump to the end of the file as soon as it opens | ## Three essential command combinations - `less +F /var/log/nginx/access.log` โ€” Real-time log following (q to quit after stopping) - `less -N -S /etc/nginx/nginx.conf` โ€” Read configuration with line numbers and horizontal scrolling - `less +G /var/log/app.log` โ€” Start from the latest logs **๐Ÿ’ฌ "Show me how to work with multiple files at once"** Here are common situations on production servers, organized step by step. ### Step 1 ยท Real-time log following Follow the logs and watch for anomalies. ``` less +F /var/log/nginx/access.log ``` ### Step 2 ยท Narrow down with search Stop following with Ctrl+C and search with /. ``` / 500 ``` ### Step 3 ยท Inspect the relevant section Look at the surrounding context to pinpoint the request that caused it. ``` n ``` ## In practice, use it like this ### 1. Tracing 500 errors **Situation** โ€” 5xx responses occur intermittently. ``` less +F /var/log/nginx/access.log ``` **Result** โ€” Requests flow in real time, and after Ctrl+C you can use / 500 to view only those requests. **Key point** โ€” Follow โ†’ stop โ†’ search โ†’ inspect context is the basic flow of log analysis. ### 2. Skimming a large configuration file **Situation** โ€” Find a specific server block in an nginx configuration with thousands of lines. ``` less -N /etc/nginx/nginx.conf ``` **Result** โ€” View line numbers and search with / server_name to find the block. **Key point** โ€” less is safe for read-only inspection without the risk of accidentally modifying the file with vi. ## Things to keep in mind - During real-time following (+F), editing keys do not work. Stop following with Ctrl+C. - less is read-only, so you will not accidentally modify files (safer than vi). - Outputting a multi-GB file with cat can freeze the terminal and increase server load. ## Actual execution screen This is the result of following logs in real time and checking 5xx responses. ![less command execution result: real-time log following](https://games.aidebatehub.com/assets/less-demo.png) Live production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/less.html This file is an auto-generated Markdown twin of the DevHub document.