Sample Header Ad - 728x90

Unix & Linux Stack Exchange

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

Latest Questions

326 votes
25 answers
281183 views
How to have tail -f show colored output
I'd like to be able to tail the output of a server log file that has messages like: INFO SEVERE etc, and if it's `SEVERE`, show the line in red; if it's `INFO`, in green. What kind of alias can I setup for a `tail` command that would help me do this?
I'd like to be able to tail the output of a server log file that has messages like: INFO SEVERE etc, and if it's SEVERE, show the line in red; if it's INFO, in green. What kind of alias can I setup for a tail command that would help me do this?
Amir Afghani (7373 rep)
Mar 1, 2011, 07:13 PM • Last activity: May 9, 2025, 02:50 PM
172 votes
13 answers
85517 views
Convince grep to output all lines, not just those with matches
Say I have the following file: $ cat test test line 1 test line 2 line without the search word another line without it test line 3 with two test words test line 4 By default, `grep` returns each line that contains the search term: $ grep test test test line 1 test line 2 test line 3 with two test wo...
Say I have the following file: $ cat test test line 1 test line 2 line without the search word another line without it test line 3 with two test words test line 4 By default, grep returns each line that contains the search term: $ grep test test test line 1 test line 2 test line 3 with two test words test line 4 Passing the --color parameter to grep will make it highlight the portion of the line that matches the search expression, but it still only returns lines that contain the expression. Is there a way to get grep to output every line in the source file, but highlight the matches? My current terrible hack to accomplish this (at least on files that don't have 10000+ consecutive lines with no matches) is: $ grep -B 9999 -A 9999 test test ![Screenshot of the two commands](https://i.sstatic.net/8auYL.png) If grep can't accomplish this, is there another command-line tool that offers the same functionality? I've fiddled with [ack](https://beyondgrep.com/) , but it doesn't seem to have an option for it either.
Michael Mrozek (95505 rep)
Aug 12, 2010, 02:39 AM • Last activity: Mar 1, 2025, 03:11 AM
2 votes
1 answers
7161 views
Linux terminal: Keyword highlighting similar to MobaXTerm without piping
When I SSH into a Linux machine from Windows using MobaXTerm, I get the benefit of syntax highlighting (https://mobaxterm.mobatek.net/features.html --> see `Syntax highlighting in terminal`). It automatically highlights keywords like `error`, `pass`, `failed`, `missing`, etc. I find this extremely u...
When I SSH into a Linux machine from Windows using MobaXTerm, I get the benefit of syntax highlighting (https://mobaxterm.mobatek.net/features.html --> see Syntax highlighting in terminal). It automatically highlights keywords like error, pass, failed, missing, etc. I find this extremely useful when executing scripts that spew out a lot of debugging text -- the highlighting has helped me to notice errors that I have missed for several months due to the verbosity. I know that programs like VIM have syntax highlighting, but it's at a program level, and is language (or file-type) specific. I'm looking for the same highlighting as MobaXTerm, but at a Linux terminal level. Currently, I have to switch to Windows and SSH to the Linux machine just that have that feature, which is a chore. It would be nice if there is a plugin for the terminal. https://unix.stackexchange.com/questions/267361/syntax-highlighting-in-the-terminal suggests few solutions, but requires the output to be piped to an external program.
Ryuu (131 rep)
Jan 5, 2019, 04:51 AM • Last activity: Feb 24, 2025, 03:46 AM
19 votes
3 answers
3504 views
Current date in cal is not highlighted in recent Debian
As answered in https://unix.stackexchange.com/questions/11081/ > the current date in output form cal is automatically highlighted (reverse colors) if the output goes to terminal. That's what I had always been getting. However, with my current Debian GNU/Linux, it is not the case any more, and I'm wo...
As answered in https://unix.stackexchange.com/questions/11081/ > the current date in output form cal is automatically highlighted (reverse colors) if the output goes to terminal. That's what I had always been getting. However, with my current Debian GNU/Linux, it is not the case any more, and I'm wondering what the fix is. enter image description here
$ echo $TERM
xterm

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux bullseye/sid
Release:        testing
Codename:       bullseye
xpt (1858 rep)
Aug 11, 2021, 09:07 PM • Last activity: May 6, 2024, 02:18 AM
6 votes
2 answers
881 views
Why does 'cal' use weird 08 / ^H / \b terminal code for highlighting and how does that work?
When you run cal on Linux, the output for the current month will reverse video highlight the current day. When I send that output to hexdump -c, I get some interesting results: 0000000 N o v e m b e r 2 0 1 6 0000010 \n S u M o T u 0000020 W e T h F r S a \n 0000030 1 2 _ \b _ \b 3 0000040 4 5 \n 6...
When you run cal on Linux, the output for the current month will reverse video highlight the current day. When I send that output to hexdump -c, I get some interesting results: 0000000 N o v e m b e r 2 0 1 6 0000010 \n S u M o T u 0000020 W e T h F r S a \n 0000030 1 2 _ \b _ \b 3 0000040 4 5 \n 6 7 0000050 8 9 1 0 1 1 1 2 \n 0000060 1 3 1 4 1 5 1 6 1 7 1 0000070 8 1 9 \n 2 0 2 1 2 2 0000080 2 3 2 4 2 5 2 6 \n 2 7 0000090 2 8 2 9 3 0 00000a0 \n 00000b0 \n 00000bc As you can see, there is an invisible sequence being printed of _\b _\b before the '3' that is highlighted for today. _ being underscore (5F in ascii hex) and \b being Ctrl-H or 08 in ASCII hex. What is this? I know there are a lot of obscure terminal codes, but I would expect it to use something more standard like \e[7m. What is even stranger is that I can't reproduce the same behavior of cal by printing out the same characters using standard printf functions like one of these commands: /usr/bin/printf "1 2 _\b _\b3 4 5\n" /usr/bin/printf "1 2 _^H _^H3 4 5\n" Where ^H is made by pressing Ctrl-V Ctrl-H. But neither of these produce the same inverse video output that cal does. I even tried writing a little C program to do it too. I've also tried with echo -e. The interesting thing is that while it doesn't reverse the video in the terminal, if I pipe the output from less -R, it changes its color to yellow and underlines it. On other terminals I tried it just underlines it. It almost seems like overstriking, but if I use a character other than _ it doesn't work, which makes me think that _\b is a single code sequence. And how does the video for that character then get inversed? Any insight into this? The man page says that the output of cal is supposed to be a bit for bit compatible version to the original Unix cal command. So I can only assume this is some ancient code.
deltaray (1477 rep)
Nov 3, 2016, 06:32 PM • Last activity: Mar 25, 2024, 10:30 AM
0 votes
1 answers
197 views
How to identify PDF pages that contain highlighted text via command-line
Assume a pdf document that contains text highlights on pages 1, 3 and 14. Is there a Linux command-line tool (or a set of tools whose output can be piped to each other) that can report the page numbers of those pages that contain highlighted text? Something like: $ sought_tool --list-pages-with-high...
Assume a pdf document that contains text highlights on pages 1, 3 and 14. Is there a Linux command-line tool (or a set of tools whose output can be piped to each other) that can report the page numbers of those pages that contain highlighted text? Something like: $ sought_tool --list-pages-with-highlights doc.pdf 1 3 14
Michael Gruenstaeudl (115 rep)
Nov 14, 2022, 08:55 PM • Last activity: Nov 15, 2022, 01:10 PM
1 votes
2 answers
464 views
Random freezes, pointer moves, no response to clicks
Why is my laptop freezing? Screen randomly freezes, I can move pointer but no response to clicking. Cannot alt-tab through windows. This happens in firefox and chromium. Ran memtester, all ok. Set FF to erase data, memory when closing, cleared memory & data, increased files open (ulimit -u) to 4096...
Why is my laptop freezing?
Screen randomly freezes, I can move pointer but no response to clicking. Cannot alt-tab through windows. This happens in firefox and chromium. Ran memtester, all ok. Set FF to erase data, memory when closing, cleared memory & data, increased files open (ulimit -u) to 4096 when I saw the error message: too many files open - still freezes. (It just now froze as I was typing this message!) It can freeze after one minute or 30 minutes. Must hold power button to force off. Same happens in Ubuntu and Mint. System Monitor shows that FF never uses more than 1.5% of cpu and there are no other processes using more cpu time. One clue is that shortly before it freezes moving the mouse will start highlighting every line it passes and will only un-highlight by pulling the cursor back, and cannot stop any further highlighting. Must force reboot to get back control.
Firefox 106.0.1
Chromium 106.0.5249.119

Laptop Make: Model > Framework: Laptop AB
OS: Pop!_OS 22.04 LTS x86_64
DE: GNOME 42.3.1
Kernel: 6.0.2-76060002-generic
Shell: bash 5.1.16
WM: Mutter
CPU: 11th Gen Intel i7-1165G7 (8) @ 4.700GHz
CPU Usage: 11%
Disk (/): 15G / 220G (8%)
GPU: Intel TigerLake-LP GT2 [Iris Xe Graphics]
GPU Driver: i915
Memory: 3008MiB / 15785MiB (19%)
Resolution: 2256x1504
QRP (31 rep)
Oct 25, 2022, 09:36 AM • Last activity: Nov 1, 2022, 12:26 AM
2 votes
1 answers
891 views
Tmux vi copy mode selection - character under cursor is not highlighted
If I switch to copy mode in tmux (vi mode), and begin selecting text using `v`, the character that is directly under the cursor is never highlighted properly even though it is selected (i.e. if I copy the selection, that character shows up in the pasted text). I want tmux to properly highlight all s...
If I switch to copy mode in tmux (vi mode), and begin selecting text using v, the character that is directly under the cursor is never highlighted properly even though it is selected (i.e. if I copy the selection, that character shows up in the pasted text). I want tmux to properly highlight all selected characters, including the one under the cursor just like in vim. How can I do that? I tested it also without vi mode and with an empty .tmux.config file, and the same thing happens. So I don't think it has to do with my configuration. Interestingly, the same exact behavior also happens in zsh when selecting text in zsh Vi mode.
WalksB (165 rep)
Jul 11, 2022, 03:58 AM • Last activity: Jul 12, 2022, 05:27 AM
-1 votes
2 answers
298 views
How to enable the highlighting of the file "/etc/login.defs" on Ubuntu?
When I open the file `/etc/login.defs` on a RHEL 8.3 system, it looks like this: [![enter image description here][1]][1] As you can see, it highlights the content. But when I open the same file in a Ubuntu 20.04 system, there is no highlighting. [![enter image description here][2]][2] I tried vim co...
When I open the file /etc/login.defs on a RHEL 8.3 system, it looks like this: enter image description here As you can see, it highlights the content. But when I open the same file in a Ubuntu 20.04 system, there is no highlighting. enter image description here I tried vim commands like :syntax on, but of no avail. How can I enable the highlighting of this file? Where is the setting that controls this?
Fajela Tajkiya (1065 rep)
Apr 30, 2022, 04:49 PM • Last activity: May 16, 2022, 03:18 PM
1 votes
1 answers
1723 views
less a file with JSON rows - how to highlight/colorize the rows?
I have log files with json rows inside - less displays it as just plain text Can I colorize the output with less abilities? As well as I didn't find any less-compatible third party tool with json highlighting Example of such file {"date":"2021-10-21 16:09:54", "perf":{"action":"getTimelineByClient",...
I have log files with json rows inside - less displays it as just plain text Can I colorize the output with less abilities? As well as I didn't find any less-compatible third party tool with json highlighting Example of such file {"date":"2021-10-21 16:09:54", "perf":{"action":"getTimelineByClient", "time":46.2}} {"date":"2021-10-22 16:09:54", "perf":{"action":"getTimelineByClient", "time":46.2}} {"date":"2021-10-23 16:09:54", "perf":{"action":"getTimelineByClient", "time":46.2}} Edit @glennjackman kindly pointed to https://github.com/sharkdp/bat - great tool, not fit for my needs, but maybe will be helpful for the other. bat firstly parses the file and afterwards tries to show it. 120k of short json rows were pretty heavy for my machine
Doc999tor (111 rep)
Oct 24, 2021, 02:16 PM • Last activity: Oct 26, 2021, 12:56 AM
9 votes
7 answers
10842 views
Highlight the current date in cal
I would like to highlight today's date in the output of the `cal` command. What is the best way? This is what I have so far: cal -m | grep -C6 --color "$(date +%e)" but it doesn't work for all cases e.g, when the date has a single digit. I also want the highlighting to work when I display the calend...
I would like to highlight today's date in the output of the cal command. What is the best way? This is what I have so far: cal -m | grep -C6 --color "$(date +%e)" but it doesn't work for all cases e.g, when the date has a single digit. I also want the highlighting to work when I display the calendar for a year.
dogbane (30655 rep)
Apr 11, 2011, 01:23 PM • Last activity: Oct 21, 2021, 02:06 PM
14 votes
7 answers
16830 views
`highlight` command
Is there a command which can be used to easily highlight (with colors, bold text or inverted back-/foreground) specific strings in stdin while passing the entire string to stdout? I'm thinking of [building it][1], but I'd rather just use it if it already exists. Some desirable features: 1. Separate...
Is there a command which can be used to easily highlight (with colors, bold text or inverted back-/foreground) specific strings in stdin while passing the entire string to stdout? I'm thinking of building it , but I'd rather just use it if it already exists. Some desirable features: 1. Separate highlight strings are highlighted differently, in an automatic way. For example, the first string will be highlighted in red, the second in green, the third in blue *without manual configuration*. 1. Detects color support and falls back to bold/inverted/other highlighting methods where those are available. 1. Allow for matching of regular expressions and literal strings. 1. Preferably does something smart if the matches overlap, such as "foobar" and "barbar". 1. Nothing is modified between stdin and stdout except for the addition of color codes.
l0b0 (53368 rep)
Mar 16, 2011, 01:38 PM • Last activity: Jun 2, 2021, 08:05 AM
53 votes
5 answers
16853 views
How can I display syntax highlighting on a file?
Is there a variant of `cat` that outputs syntax-highlighted lines of code when used on a source file? An idea: maybe `vi[m]` or another editor can be asked to dump the syntax-highlighted contents of said files to `stdout` and exit immediately?
Is there a variant of cat that outputs syntax-highlighted lines of code when used on a source file? An idea: maybe vi[m] or another editor can be asked to dump the syntax-highlighted contents of said files to stdout and exit immediately?
Paolo (1605 rep)
Aug 26, 2011, 02:32 AM • Last activity: Mar 22, 2021, 03:20 AM
5 votes
1 answers
2326 views
Retain selection highlight after copying text to clipboard in tmux
I'm using macOS and `tmux 3.1c`. When copying a text via mouse selection, the highlight will be auto-cleared after copying the text to clipboard, this will make it difficult to keep track the last line you copied when you go back to it: [![enter image description here][1]][1] [1]: https://i.sstatic....
I'm using macOS and tmux 3.1c. When copying a text via mouse selection, the highlight will be auto-cleared after copying the text to clipboard, this will make it difficult to keep track the last line you copied when you go back to it: enter image description here Is there a way to prevent/disable the auto-clearing of selection after copying? I know about pressing Shift, then selecting the text, and then hitting Cmd + C to copy it to the clipboard, which preserves the selection. But this is relatively inefficient workflow. This is the same behavior with Alacritty/iTerm. In iTerm, **without tmux**, selecting a text will auto-copy it in the clipboard, but the selection will not be auto-cleared.
Ranel Padon (153 rep)
Mar 15, 2021, 12:40 AM • Last activity: Mar 15, 2021, 01:02 PM
1 votes
1 answers
278 views
Kubuntu - Strange Copy-Paste behaviour after upgrade to 20.04
I recently upgraded from 18.04 to 20.04 with Kubuntu. I had to delete Python2 to do it, but it worked. However, since the update, something strange is occuring with the copy paste function. A piece of copied text can be pasted into an empty place; however, if the text is being pasted in replacement...
I recently upgraded from 18.04 to 20.04 with Kubuntu. I had to delete Python2 to do it, but it worked. However, since the update, something strange is occuring with the copy paste function. A piece of copied text can be pasted into an empty place; however, if the text is being pasted in replacement of other text, however, it instead copies the text being highlighted! For example, say I copy hello. If I paste it into an empty text field, I get hello. However, if I copy world, then highlight hello and try to paste it there, it will instead copy the text hello instead, meaning that every paste after that will just be hello! What could be causing this strange behaviour? The keyboard shortcuts look correct...
jos (111 rep)
Feb 26, 2021, 05:35 AM • Last activity: Feb 26, 2021, 05:43 AM
1 votes
1 answers
147 views
Custom colors for ls are correctly applied for some categories, but ignored for others
With the help of `dircolors`, I changed `ls` colors. My `.dircolors` file is ``` FILE 00;97 DIR 00;96 LINK 00;95 MULTIHARDLINK 00;34 ORPHAN 91;01 # symlink to nonexistent file MISSING 00;00 EXEC 91;00 # this is for files with execute permission ``` After `dircolors .dircolors >> .bashrc`, `ls` corre...
With the help of dircolors, I changed ls colors. My .dircolors file is
FILE                   00;97
DIR                    00;96
LINK                   00;95
MULTIHARDLINK          00;34
ORPHAN                 91;01  # symlink to nonexistent file
MISSING                00;00 
EXEC                   91;00  # this is for files with execute permission
After dircolors .dircolors >> .bashrc, ls correctly colors its output according to the definitions set, **except for the executable files**. These are colored with the default terminal foreground color instead of red (91;00). For example,
xterm -fg yellow # Executables become yellow on ls
xterm -fg green  # Executables become green on ls
and that is irrespective of the terminal (Xterm, Terminator, virtual console...). I have also tried the dircolors file with only the EXEC line, producing the line
export LS_COLORS='ex=91;00:'
in my .bashrc, but still no color on executables. What am I doing wrong in coloring the executable files?
Quasímodo (19361 rep)
Aug 3, 2020, 11:41 AM • Last activity: Jan 6, 2021, 01:29 PM
0 votes
2 answers
2495 views
Bash script command to search and highlight text in terminal buffer
I need to simulate selecting (highlighting) text that is in the terminal buffer. It's long past stdout so all the grep/awk/sed/redirection stuff is not relevant AFAIK. Plus I don't want it highlighted during formatting of stdout. I need it to go to stdout unhighlighted, then highlight it. Simulating...
I need to simulate selecting (highlighting) text that is in the terminal buffer. It's long past stdout so all the grep/awk/sed/redirection stuff is not relevant AFAIK. Plus I don't want it highlighted during formatting of stdout. I need it to go to stdout unhighlighted, then highlight it. Simulating selection. Here is the scenario... A Bash script calls "ls -1" and outputs the following to stdout and then the terminal buffer? $ ls -1 a.txt b.txt c.txt Now I need a command I can put in a Bash script that will find and highlight "b.txt". Like: $ termsearch b.txt a.txt [b.txt] c.txt Where "termsearch" is a made up command I think I need and it converts b.txt to black text with white background (highlighted) and the rest of the text is white on black background. I think the problem is that you can't really edit the buffer and change text style like this. I can use screen interactively to find "b.txt", but it doesn't highlight (the main goal) and I don't know if it's possible to script screen commands anyway. So I've given up on screen. The script command just dumps stdout to a file, but I don't want to search a file. I need to search the terminal buffer and highlight the results on screen without more stdout. What I want is already out, it just needs to be highlighted. I'm thinking ncurses is the way to go, but I have never coded with it and it looks complicated. So before I dive in, I'm asking if anyone can think of another way to do this and validate that ncurses can even do what I want.
user261502 (1 rep)
Nov 21, 2017, 01:34 AM • Last activity: Dec 1, 2020, 07:15 AM
4 votes
3 answers
6116 views
In SciTE (Scintilla), how can I create Syntax-Highlighting for my own custom language?
I want to create a custom Language, with its own custom Syntax Highlighting. Notepad++, a Windows-only SciTE/Scintilla based text editor, allowed me to create a custom "Language", and now, in Linux, I want to reproduce the same thing. I need(?) to use **SciTE/Scintilla** because (as far as I know) i...
I want to create a custom Language, with its own custom Syntax Highlighting. Notepad++, a Windows-only SciTE/Scintilla based text editor, allowed me to create a custom "Language", and now, in Linux, I want to reproduce the same thing. I need(?) to use **SciTE/Scintilla** because (as far as I know) it is the only plain-text editor which can display ***different size*** fonts in the ***same*** text-file (e.g., default-font= 12pt, comment-font=24pt). I used the **comments** font to display a complex script (alphabet) in a larger font. Please let me know if there is any other **plain-text** editor which does this. I assume this is a feature of SciTE/Scintilla (and not of Notepad++). Some of the magic is possibly (probably?) done in files such as: /usr/share/scite/.properties Notepad++ has a GUI interface to set up a new language or syntax, but I could use some direction on exactly how to go about it in SciTE. Thanks...
Peter.O (33644 rep)
Oct 19, 2010, 11:13 AM • Last activity: Jun 4, 2020, 07:46 AM
1 votes
1 answers
276 views
How to highlight a screen session of an ssh connection?
Others have asked ([How to scroll inside a screen session of an ssh connection?](https://unix.stackexchange.com/a/454399/400310)) on how to scroll within a screen session. However, while I can highlight what is shown in front of me, I can't figure out how to highlight and scroll (i.e., to copy more...
Others have asked ([How to scroll inside a screen session of an ssh connection?](https://unix.stackexchange.com/a/454399/400310)) on how to scroll within a screen session. However, while I can highlight what is shown in front of me, I can't figure out how to highlight and scroll (i.e., to copy more of the output). Highlighting with my mouse does not let me scroll via page up/down or other means I've tried.
Elie (123 rep)
Mar 15, 2020, 02:29 PM • Last activity: Mar 15, 2020, 03:02 PM
3 votes
2 answers
1613 views
Access highlighted text from script?
Is it possible to access highlighted text via a shell script? I want to make a keyboard shortcut to use 'espeak' to read highlighted text.
Is it possible to access highlighted text via a shell script? I want to make a keyboard shortcut to use 'espeak' to read highlighted text.
Philip Kirkbride (10746 rep)
Oct 25, 2016, 12:38 AM • Last activity: Oct 19, 2019, 06:13 PM
Showing page 1 of 20 total questions