3

The problem

I don't want to see filenames quoted when they contain spaces.

Example

On OSX I see this when running ls:

> ls -l
total 0
drwxr-xr-x 2 mafro staff 68 Mar 16 09:02 'dir with spaces'
drwxr-xr-x 2 mafro staff 68 Mar 16 09:02 dir_with_spaces

On my Debian box it looks like this:

> ls -l
total 8
drwxr-xr-x 2 mafro mafro 4096 Mar 16 09:02 dir with spaces
drwxr-xr-x 2 mafro mafro 4096 Mar 16 09:02 dir_with_spaces

My shell is zsh with prezto and a tiny amount of my own customisation. I (should) have exactly the same dotfiles on both boxes

Here's ls. It's the same on both systems:

> which ls
ls: aliased to ls --group-directories-first --color=auto
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
mafrosis
  • 239
  • 3
  • 11
  • 2
    You'll get the quoting on newer Debian releases, too. See [Why is 'ls' suddenly wrapping items with spaces in single quotes](http://unix.stackexchange.com/questions/258679/why-is-ls-suddenly-wrapping-items-with-spaces-in-single-quotes) – Mark Plotnick Mar 16 '16 at 14:32
  • @MarkPlotnick you should make this comment an answer! I've searched high and low for this and didn't find that link you sent :) THANKS – mafrosis Mar 16 '16 at 16:10
  • @MarkPlotnick Debian undid this change in the mailing list because the maintainers agreed with me (asker of the question you linked) that it was a bad idea. – Wyatt Ward Apr 10 '16 at 01:51

2 Answers2

4

This is a new feature of Coreutils ls.

From the info documentation:

‘-N’
‘--literal’
‘--quoting-style=literal’

Do not quote file names. However, with ‘ls’ nongraphic characters are still printed as question marks if the output is a terminal and you do not specify the ‘--show-control-chars’ option.

ams
  • 5,707
  • 1
  • 19
  • 27
1

To disable this feature, add export QUOTING_STYLE=literal to your ~/.bashrc or, if you are using recent GNU coreutils with shells that don't support export var=value, use:

QUOTING_STYLE=literal
export QUOTING_STYLE

IMO, the recently added quoting styles are a good feature, but they should not have changed the default behaviour because It breaks too many existing scripts and command line habits - especially for people who are doing the Right Thing and properly quoting their variables.

BTW, Debian reverted the behaviour in coreutils 8.25-2, so it was only present briefly in sid in 8.25-1.

cas
  • 1
  • 7
  • 119
  • 185
  • It's still present in Arch Linux, however. – ams Mar 17 '16 at 09:55
  • @ams I feel bad for you. – Wyatt Ward Apr 10 '16 at 01:52
  • Upvoting but I thought I'd point out that the new(ish) output-style is only used when stdout is a terminal so it shouldn't break any scripts – and parsing `ls` was never a good idea: see https://unix.stackexchange.com/a/128987/22812 and http://mywiki.wooledge.org/ParsingLs – Anthony Geoghegan Nov 09 '18 at 15:30