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
mafrosis
  • 239

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,807
  • 1
  • 20
  • 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
  • 78,579
  • 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