25
submitted 3 weeks ago* (last edited 3 weeks ago) by zarkanian@sh.itjust.works to c/linux@lemmy.ml

Today, I was doing some command-line stuff and then this happened:

ls --help|less
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
ESC]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#ls-aESC\ESC[1m-a, --allESC[0mESC]8;;ESC\
do not ignore entries starting with .
ESC]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#ls-AESC\ESC[1m-A, --almost-allESC[0mESC]8;;ESC\
do not list implied . and ..
ESC]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#ls--authorESC\ESC[1m--authorESC[0mESC]8;;ESC\

It's rendering ls --help with control characters. When I do ls --help|less --raw-control-chars it doesn't show the control characters, and it looks all neat and pretty. Isn't this the opposite of how it's supposed to work?!

Is --raw-control-chars a toggle and some config is causing less to show control characters when I invoke it with no options? If so, where can I find this config and stop this?

This has absolutely no bearing on my work and my life in general except for the fact that I'll go absolutely batshit trying to figure this out, because that's how my brain is. So far, all of my web searches just confirm that less shouldn't be working this way, but they don't give me any way to fix it. Please help me, Lemmy!!!

top 17 comments
sorted by: hot top new old
[-] CallMeAl@piefed.zip 14 points 3 weeks ago* (last edited 3 weeks ago)

Per the Gnu Coreutils NEWS file:

  All commands now markup option names in --help and man pages,  
  with bold attributes, and hyperlinks into the online manual on gnu.org.  
  The links can be configured with the --enable-manual-url configure option,  
  and the bold highlighting with --disable-bold-man-page-references.  
  At runtime all markup can be disabled with the TERM=dumb env var value.  

This has nothing to do with less (or bash or fish). It is a new behavior as of Coreutils 9.10. It is to preserve the hyperlinks in the help output of ls, cp, rm, mv, etc. In default mode, less catches these control codes and escapes them so you see the visual escape codes. If you use less --raw-control-chars then less is NOT escaping the control characters (just passing them through) and they get interpreted by the terminal as screen formatting codes.

Debian 13, which ships Coreutils 9.7 does not have the change and cannot reproduce the behavior.

[-] syklemil@discuss.tchncs.de 2 points 3 weeks ago

You may want to tag your triple-backtick with something like text or plain so you don't get auto-inferred syntax highlighting. E.g:

 All commands now markup option names in --help and man pages, 
[-] CallMeAl@piefed.zip 2 points 3 weeks ago

good one, thanks!

[-] TrollAccount69@lemmy.ml 7 points 3 weeks ago

Sounds like it was more trouble than it was worth!

[-] quarrel4you@piefed.social 5 points 3 weeks ago

One option is to use less -R to see the pretty colors.
The boring option is to use ls --color=never and be sad.

[-] tangeli@piefed.social 5 points 3 weeks ago* (last edited 3 weeks ago)

I would say your ls shouldn't be working that way: when it detects that it's standard output isn't a terminal, it shouldn't be outputting the control codes. Which makes me wonder what version of ls you are running.

edit: what is the output from alias ls and what happens if you run \ls --help | less?

[-] zarkanian@sh.itjust.works 1 points 3 weeks ago

I'm using the fish shell. I checked, and there are no aliases for ls or less. \ls --help | less gives me the same result as ls --help | less.

[-] tangeli@piefed.social 1 points 3 weeks ago

That's surprising. I have an older version of coreutils (9.7 from Debian 13) that doesn't produce the links and formatting. I'm running bash and the behaviour you're experiencing isn't reproduced.

Aliases aside, I wouldn't expect the shell to be the cause. None the less, I installed version 4.0.2 of the fish shell and ran the same command in it and didn't see any control characters. But that's not really surprising - my old version of ls doesn't produce them. So I ran ls | less because even with my version ls colour highlights files by type, but in the pipeline to less, there were no codes.

If I run ls --color=always | less then I do see codes in the less output.

You might check your environment variables to see if CLICOLOR_FORCE is set.

Otherwise, I am out of ideas.

[-] Dultas@lemmy.world 1 points 3 weeks ago

What terminal are you using?

[-] syklemil@discuss.tchncs.de 4 points 3 weeks ago

When I do ls --help|less --raw-control-chars it doesn't show the control characters, and it looks all neat and pretty. Isn't this the opposite of how it's supposed to work?!

You've gotten a longer reply to this, but just to make it clear: No, that's how it's supposed to work.

  • By default less mangles control characters so they can't do anything to your display (or bell)
  • With -R, less will pass some control characters through raw and unmangled; enough to give you stuff like pretty colours
  • With -r, less won't mangle any control characters, which, if you're doing something stupid like trying to read a binary file, can leave your terminal prompt fucked up and in need of a reset.
[-] thingsiplay@lemmy.ml 1 points 3 weeks ago* (last edited 3 weeks ago)

/usr/bin/ls --color=never --help | /usr/bin/less and /usr/bin/ls --color=never --help > ~/Desktop/lshelp.txt produces and contains the same characters, BTW. This happens in Bash and Zsh, using Kitty and Konsole terminals. So its not an issue with less, the shell or terminal. Meaning it might be an issue with ls itself. I have "ls (GNU coreutils) 9.11" from ls --version.

Ah ls has an option for this: -q, --hide-control-chars But ls -q --color=never --help | less seem not to hide anything, maybe because --help is in use. I can put strings in between, it would only hide control characters, not the normal sequence for other stuff \ls -q --color=none --help | strings | less

Looks like an issue with ls. I feel helpless.

[-] syklemil@discuss.tchncs.de 2 points 3 weeks ago

-q controls output for filenames. From ls.c:

/* True means output nongraphic chars in file names as '?'.
   (-q, --hide-control-chars)
   qmark_funny_chars and the quoting style (-Q, --quoting-style=WORD) are
   independent.  The algorithm is: first, obey the quoting style to get a
   string representing the file name;  then, if qmark_funny_chars is set,
   replace all nonprintable chars in that string with '?'.  It's necessary
   to replace nonprintable chars even in quoted strings, because we don't
   want to mess up the terminal if control chars get sent to it, and some
   quoting methods pass through control chars as-is.  */
static bool qmark_funny_chars;
[-] elmicha@feddit.org 1 points 3 weeks ago

What's the value of $LESSOPEN? These URLs in a manual page look strange.

[-] solrize@lemmy.ml 1 points 3 weeks ago

Yeah use less -r. You can set that in your environment

export LESS="-EX -r"

is what I use.

[-] darklamer@feddit.org 4 points 3 weeks ago* (last edited 3 weeks ago)

Capital -R is for most use-cases a safer and better choice than plain -r.

this post was submitted on 22 Sep 2026
25 points (87.9% liked)

Linux

68069 readers
800 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 7 years ago
MODERATORS