Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

3 votes
3 answers
739 views
Customizing source-highlight's color schemes?
The `source-highlight` package is installed on my system. It highlights files I view with less using `/usr/bin/lesspipe` and `LESSOPEN` environment variable. Now, I want to change the color scheme this mechanism uses for some/all filetypes. I have root on the machine. How do I do this? Note: It's a...
The source-highlight package is installed on my system. It highlights files I view with less using /usr/bin/lesspipe and LESSOPEN environment variable. Now, I want to change the color scheme this mechanism uses for some/all filetypes. I have root on the machine. How do I do this? Note: It's a Devuan 3 Beowulf (~= Debian 10 Buster) Linux distribution.
einpoklum (10753 rep)
Jan 4, 2020, 11:55 PM • Last activity: Aug 2, 2025, 10:39 PM
77 votes
18 answers
87224 views
Is there ever a reason to use `cat` when you've got `less`?
I used to use `cat` to view files. Then I learned that `less` is usually better, and is a must if the file is longer than a few dozen rows. My question: Is there ever a reason to use `cat` instead of `less`? Is there any situation where `cat` is a better solution?
I used to use cat to view files. Then I learned that less is usually better, and is a must if the file is longer than a few dozen rows. My question: Is there ever a reason to use cat instead of less? Is there any situation where cat is a better solution?
Ram Rachum (1895 rep)
Sep 27, 2011, 08:33 PM • Last activity: Jul 12, 2025, 11:09 AM
1 votes
1 answers
34 views
less +S rings bell on first screen?
As a result of the answer to [this question](https://stackoverflow.com/questions/72367806), I have begun setting `LESS=+S`. However, I have discovered that this causes `less` to ring the terminal bell on the first screen. This happens on the first screen only, not subsequent screens. I can inhibit t...
As a result of the answer to [this question](https://stackoverflow.com/questions/72367806) , I have begun setting LESS=+S. However, I have discovered that this causes less to ring the terminal bell on the first screen. This happens on the first screen only, not subsequent screens. I can inhibit the bell by using -Q, but that causes a "visible bell" on the first screen, instead. So clearly less is trying to warn me about something. I assumed the bell was part of the first prompt, but it's not. Running inside script(1) reveals that the bell character is coming out immediately before the first line of the first screen of output. I'm encountering this on several different systems, so I don't think it's version- or system-dependent. Does anyone know why this alert is occurring, or how to suppress or disable it? ---- Addendum: There's some history here: I'm using +S to enable horizontal wrapping in the specific case that git is using less as its pager. It's not clear how git is disabling horizontal wrapping, but it now appears — see the answer below — that globally setting LESS=+S is not necessarily the right way to reenable it.
Steve Summit (918 rep)
Jun 27, 2025, 02:22 PM • Last activity: Jun 27, 2025, 04:13 PM
4 votes
1 answers
606 views
Make man pages narrow and centered in the terminal
I have a wide monitor and the terminal opened at fullscreen. I want man pages to be narrowed to, say, 100 characters wide, and centered on the screen, like in emacs olivetti mode: https://github.com/rnkn/olivetti. How can I do that?
I have a wide monitor and the terminal opened at fullscreen. I want man pages to be narrowed to, say, 100 characters wide, and centered on the screen, like in emacs olivetti mode: https://github.com/rnkn/olivetti . How can I do that?
krvkir (213 rep)
Oct 27, 2018, 12:40 PM • Last activity: Jun 27, 2025, 02:15 PM
16 votes
3 answers
5435 views
Piping into less and editing: "cannot edit standard input" error. Workarounds?
I recently learned that if I page my files with `less`, I can press `v` and open the buffer in Emacs. This works as long as I have the environment variable `$EDITOR` set up correctly, which in my case I have it as: export EDITOR='env TERM=xterm-256color emacs -nw' The above gives me the ability to l...
I recently learned that if I page my files with less, I can press v and open the buffer in Emacs. This works as long as I have the environment variable $EDITOR set up correctly, which in my case I have it as: export EDITOR='env TERM=xterm-256color emacs -nw' The above gives me the ability to load emacs within the terminal that runs less. However, the trick above does not work when **piping** commands to less. When doing this, less complains with the following message: Cannot edit standard input (press RETURN) My question is, why does this happen? But most importantly, **is there any workaround to it**?
Amelio Vazquez-Reina (42851 rep)
Oct 25, 2011, 09:49 PM • Last activity: Jun 4, 2025, 08:17 AM
80 votes
5 answers
55057 views
less command and syntax highlighting
I need to use the `less` command with the syntax highlighting of the vim command for `python`, `C`, `bash` and other languages. How do I apply syntax highlighting colors according to `vim` colors for `less` command?
I need to use the less command with the syntax highlighting of the vim command for python, C, bash and other languages. How do I apply syntax highlighting colors according to vim colors for less command?
PersianGulf (11308 rep)
Sep 17, 2013, 06:17 AM • Last activity: May 29, 2025, 02:29 PM
17 votes
1 answers
8355 views
`docker logs foo | less` isn't searchable or scrollable but `docker logs foo 2>&1 | less` is
Using either `docker logs foo | less` or `docker logs foo 2>&1 | less` produces readable text, but only with the stderr redirect can one scroll or type `/somepattern` and obtain matches. Without it, searching gives "Nothing to search (press RETURN)" and a column of `~`'s. Given that stderr and stdou...
Using either docker logs foo | less or docker logs foo 2>&1 | less produces readable text, but only with the stderr redirect can one scroll or type /somepattern and obtain matches. Without it, searching gives "Nothing to search (press RETURN)" and a column of ~'s. Given that stderr and stdout aren't the same, why does less show them the same until I start doing something in less? This may be some weird multi-window vim thing that I just don't understand. Thoughts?
MagicWindow (311 rep)
Mar 29, 2016, 09:01 PM • Last activity: May 23, 2025, 08:37 AM
19 votes
7 answers
3646 views
pager program like less, able to repeat top N lines
Is there any way to make `less` program repeat first line (or first 2 lines) on every displayed page? Is there any other pager program which can do this? This would be a killer-app for database table browsing, think `mysql` or `psql` or `gqlplus`... See the screenshot. [![Console pager for psql outp...
Is there any way to make less program repeat first line (or first 2 lines) on every displayed page? Is there any other pager program which can do this? This would be a killer-app for database table browsing, think mysql or psql or gqlplus... See the screenshot. Console pager for psql output I want to repeat header line + horizontal ascii bar. Identically as the "Freeze Top N Rows" feature known from spreadsheet software.
filiprem (439 rep)
Dec 28, 2011, 11:26 AM • Last activity: May 16, 2025, 03:27 PM
109 votes
5 answers
20360 views
Is there any way to exit "less" without clearing the screen?
Relatively often, I find myself wanting to quit `less` but leave what I was viewing on the screen, to refer back to. Is there any way to do this? Workarounds? (My current workaround is to quit, then use `more`. So any workaround that's better than that is welcomed. The ideal would be something I can...
Relatively often, I find myself wanting to quit less but leave what I was viewing on the screen, to refer back to. Is there any way to do this? Workarounds? (My current workaround is to quit, then use more. So any workaround that's better than that is welcomed. The ideal would be something I can use once I'm already inside less, perhaps with a shell setting or some scripting.) My desktop is OSX, but I use RHEL and Ubuntu servers.
Steve Bennett (2303 rep)
May 14, 2012, 01:36 PM • Last activity: May 13, 2025, 03:01 PM
51 votes
5 answers
17779 views
Horizontal scrolling in smaller increments with less -S
I'm using `less` to parse HTTP access logs. I want to view everything neatly on single lines, so I'm using `-S`. The problem I have is that the first third of my terminal window is taken up with metadata that I don't care about. When I use my arrow keys to scroll right, I find that it scrolls past t...
I'm using less to parse HTTP access logs. I want to view everything neatly on single lines, so I'm using -S. The problem I have is that the first third of my terminal window is taken up with metadata that I don't care about. When I use my arrow keys to scroll right, I find that it scrolls past the start of the information that I do care about! I could just delete the start of each line, but I don't know if I may need that data in the future, and I'd rather not have to maintain separate files or run a script each time I want to view some logs. ### Example This line: > access.log00002:10.0.0.0 - USER_X [07/Nov/2013:16:50:50 +0000] "GET /some/long/URL" Would scroll to: ng/URL" ### Question Is there a way I can scroll in smaller increments, either by character or by word?
Mike (851 rep)
Nov 25, 2014, 04:32 PM • Last activity: Apr 8, 2025, 01:04 PM
0 votes
1 answers
89 views
Using "less" as a pager with conditional exit and input forwarding
How can I use less with the following requirements? 1. I want to use less and scroll up and down with the arrow keys. 2. If the entire output fits on the screen, less should automatically exit. 3. When I type something and press Enter , less should exit, and the input should be passed to read or to...
How can I use less with the following requirements? 1. I want to use less and scroll up and down with the arrow keys. 2. If the entire output fits on the screen, less should automatically exit. 3. When I type something and press Enter, less should exit, and the input should be passed to read or to a variable, so I can process it. 4. I don't want to use :q, Ctrl-C, or similar commands to exit. Example,I run lsblk | less and want to enter a device name like sdx, which should be passed to a variable for further processing. Is this possible? I would appreciate a solution.
MotorCheck (185 rep)
Mar 25, 2025, 07:56 PM • Last activity: Mar 26, 2025, 05:51 AM
38 votes
3 answers
35406 views
Where is less search pattern reference?
Where can I find reference for `less` regex search patterns? I want to search file with `less` using `\d` to find digits, but it does not seem to understand this wildcard. I tried to find a reference for `less` regex patterns, but could not find anything, not on man pages and not on the Internet.
Where can I find reference for less regex search patterns? I want to search file with less using \d to find digits, but it does not seem to understand this wildcard. I tried to find a reference for less regex patterns, but could not find anything, not on man pages and not on the Internet.
CodeSandwich (505 rep)
Jul 3, 2018, 02:25 PM • Last activity: Mar 4, 2025, 06:27 AM
51 votes
4 answers
22549 views
How do I pipe colored diff output to less?
I've been using git diff, which produces colored output. However, I now find I need to use ordinary diff for something, and it's producing a lot of output that is hard to read because of the lack of colors. How do I make diff produce a readable, colored output? Ideally while piping it to less, for e...
I've been using git diff, which produces colored output. However, I now find I need to use ordinary diff for something, and it's producing a lot of output that is hard to read because of the lack of colors. How do I make diff produce a readable, colored output? Ideally while piping it to less, for easy review of large files.
Benubird (6082 rep)
May 17, 2013, 04:26 PM • Last activity: Jan 9, 2025, 04:21 PM
0 votes
1 answers
51 views
Why does this display output: ls 1>/dev/null | less
If I do this: `ls 1>/dev/null` then as expected there is no output to the screen because it's been redirected to /dev/null However, if I do this `ls 1>/dev/null | less` I see the file listing of the current directory. How?!?
If I do this: ls 1>/dev/null then as expected there is no output to the screen because it's been redirected to /dev/null However, if I do this ls 1>/dev/null | less I see the file listing of the current directory. How?!?
Ben (327 rep)
Jan 8, 2025, 04:37 PM • Last activity: Jan 8, 2025, 04:51 PM
5 votes
1 answers
292 views
Cannot fg a zsh function including less
I have this zsh function: ``` f() { /usr/bin/find . -type f | less } ``` When I run this function, suspend with Ctrl+z, and then run fg, it displays `zsh: suspended (tty output) /usr/bin/find . -type f |` and I can't resume. Why is that? How can I resume? ``` arch% f zsh: suspended /usr/bin/find . -...
I have this zsh function:
f() {
/usr/bin/find . -type f | less
}
When I run this function, suspend with Ctrl+z, and then run fg, it displays zsh: suspended (tty output) /usr/bin/find . -type f | and I can't resume. Why is that? How can I resume?
arch% f
zsh: suspended /usr/bin/find . -type f |
arch% fg
 - continued /usr/bin/find . -type f |
zsh: suspended (tty output) /usr/bin/find . -type f |
zsh: suspended (tty output) /usr/bin/find . -type f |
arch%
If I run /usr/bin/find . -type f | less directly from the command line without making it a function, it will suspend and resume normally.
aosho235 (227 rep)
Dec 19, 2024, 03:43 AM • Last activity: Dec 20, 2024, 09:17 AM
1 votes
1 answers
431 views
In Less, how to jump horizontally between search matches on the same line?
On pressing n , Less skips all the search matches in the current line and moves to the next *line* with a match (even if the lines are wrapped). How can I make it move the cursor to all the matches in each line?
On pressing n, Less skips all the search matches in the current line and moves to the next *line* with a match (even if the lines are wrapped). How can I make it move the cursor to all the matches in each line?
Arch Stanton (355 rep)
Aug 4, 2021, 07:23 AM • Last activity: Nov 23, 2024, 11:17 AM
3 votes
1 answers
959 views
Search for occurrences of text in a long line in less
I am using `less` to view a file with many long lines. `less` automatically wraps these lines, but when I use `/` and `n` to search for something, it only shows the first occurrence of the text on a line. However, I want to see all occurences of the search result on the wrapped line.
I am using less to view a file with many long lines. less automatically wraps these lines, but when I use / and n to search for something, it only shows the first occurrence of the text on a line. However, I want to see all occurences of the search result on the wrapped line.
asmeurer (341 rep)
Mar 1, 2016, 09:58 PM • Last activity: Nov 23, 2024, 10:27 AM
0 votes
1 answers
87 views
Does "less" have "--retry" option like "tail"?
I'm using **less** to continuously trace Squid log file (as well as UFW log) with this command: less --follow-name -K +F /var/log/squid/access.log And at the time of rotation of Squid log **less** quits. I guess this happens because when an old file is renamed the new one is not created immediately...
I'm using **less** to continuously trace Squid log file (as well as UFW log) with this command: less --follow-name -K +F /var/log/squid/access.log And at the time of rotation of Squid log **less** quits. I guess this happens because when an old file is renamed the new one is not created immediately but with a delay, though in the case of UFW log file this doesn't happen and **less** successfully switches to the new file. So is there a method or option to make **less** wait for a new file to appear?
EliiO (3 rep)
Nov 17, 2024, 01:10 AM • Last activity: Nov 19, 2024, 09:32 AM
0 votes
0 answers
42 views
less - how to make it not split lines for lines that are too wide when it starts?
I have output that is _very_ wide (output from a sql query) and that, when I start `less`, is split into multiple lines, difficult to understand what is what... If I press on the right arrow, less will actually start showing single lines for each line of output and we _know_ that there is stuff to t...
I have output that is _very_ wide (output from a sql query) and that, when I start less, is split into multiple lines, difficult to understand what is what... If I press on the right arrow, less will actually start showing single lines for each line of output and we _know_ that there is stuff to the left and to the right and we can continue using the arrows to move around..... _however_ when I move to the very ferst columns, I get again multiline output so I am missing seeing the first few columns to the left with the single line output format. Is it possible to make less start so that it uses a single line right from the get go?
eftshift0 (707 rep)
Nov 8, 2024, 11:27 AM
8 votes
1 answers
882 views
Customize the man command's status prompt to show percentage read
I like the man command's status prompt to be customized. The default as picked from its own man page is like this, `Manual page name(sec) line x` But, having it show me the percentage of contents read is my preference. So I set the environment variable that controls the prompt, `MANLESS` as, `export...
I like the man command's status prompt to be customized. The default as picked from its own man page is like this, Manual page name(sec) line x But, having it show me the percentage of contents read is my preference. So I set the environment variable that controls the prompt, MANLESS as, export MANLESS='?pt%pt \%: ' The prompt is empty. I put -P in the front as, export MANLESS='-P?pt%pt \%: ' No progress, now the prompt only contains -P. So, I directly set it for every invocation using the -r option, man -r '?pt%pt \%: ' less That too didn't help. But, this same prompt when set to LESS env. variable as export LESS="-P?pt%pt \%" Every direct invocation of less is showing the desired prompt as x %. It is only when less pager is called through man, it does not work.
Saravana (193 rep)
Oct 13, 2024, 04:42 PM • Last activity: Oct 14, 2024, 05:00 PM
Showing page 1 of 20 total questions