3

If I use the ls command in my home directory each line of output has a leading whitespace:

$ ls
 bin      Documents ...

It only seems to do this for my home directory.

Why does it do this?

Note: I don't consider this to be a duplicate of Why is 'ls' suddenly wrapping items with spaces in single quotes? because that's not what I asked and I'm not interested in knowing the answer. Simply knowing that the whitespace is a side-effect of the quoting sufficiently answers my question.

StackedCrooked
  • 217
  • 1
  • 7
  • Does the `bin` directory have an actual space as the first character in its name? – Kusalananda Nov 21 '19 at 10:43
  • @Kusalananda No, it doesn't. – StackedCrooked Nov 21 '19 at 10:43
  • 1
    Does `ls` automatically _quote_ some of the _other_ filenames in the output due to them containing "special" characters? I can recreate this if I create any other filename with e.g. a space character in its name. GNU `ls` would then quote that name and indent other names in the directory listing output. – Kusalananda Nov 21 '19 at 10:45
  • Which distro? And what does ls -l say -- does the space also appear in the columned listing? – Paul_Pedant Nov 21 '19 at 10:45
  • 1
    @Kusalananda Intersting! There's a directory named 'VirtualBox VMs'. I noticed that the leading whitespace is no longer printed if I remove this directory. – StackedCrooked Nov 21 '19 at 10:46
  • @Paul_Pedant Ubuntu 18.04. The leading space also appears when I use `ls -l`. And it seems I have found the reason. One of the subdirectories contains a space and is quoted and it seems ls output reserves a column for the quote. I'll update my question. – StackedCrooked Nov 21 '19 at 10:48
  • @StackedCrooked Yes, write that up as a proper answer. – Kusalananda Nov 21 '19 at 10:50
  • @StackedCrooked Answers goes in the box at the bottom of the page, not in the question text :-) You can accept your own answer after a time, if you don't want to accept someone else's answer. Accepting an answer is done by clicking the greyed-out checkmark by the answer, and this marks the issue as having been resolved. See also https://unix.stackexchange.com/help/accepted-answer – Kusalananda Nov 21 '19 at 10:55
  • I can't make this happen. In LinuxMint ls -Q double-quotes every name and ls never quotes, same with -l in both. So what distro does this happen in. Also, is ls aliased to anything? – Paul_Pedant Nov 21 '19 at 11:05
  • @Paul_Pedant With `coreutils-8.31` installed on OpenBSD, I get the described behaviour by default with GNU `ls`, with no special aliases or anything. With `ls -Q`, the indent is "used up" by the double quotes (which is use for _every_ name), so you won't see it. I think `--quoting-style=locale` is the default (which may possibly mean it's locale-dependent). – Kusalananda Nov 21 '19 at 11:07
  • Possible duplicate of [Why is 'ls' suddenly wrapping items with spaces in single quotes?](https://unix.stackexchange.com/questions/258679/why-is-ls-suddenly-wrapping-items-with-spaces-in-single-quotes) – Michael Hampton Nov 21 '19 at 19:07

1 Answers1

7

I figured it out thanks to @Kusalananda's and @Paul_Pedant's suggestions.

When using ls -l the output looks like this:

drwxr-xr-x  2 francis francis  4096 Feb 15  2019  bin
drwxrwxr-x  3 francis francis  4096 Jan 16  2019  builds
drwxr-xr-x  8 francis francis  4096 Nov 15 10:00  Desktop
drwxr-xr-x  2 francis francis  4096 Aug 21 11:37  Documents
drwxr-xr-x  6 francis francis 20480 Nov 21 10:57  Downloads
drwx------ 23 francis francis  4096 Nov 21 10:57  Dropbox
drwxrwxr-x  3 francis francis  4096 Apr 11  2019 'VirtualBox VMs'

The 'VirtualBox VMs' directory is quoted by ls (probably because it has a space in its name). And it appears ls aligns the output so the leading quote has its own dedicated column.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
StackedCrooked
  • 217
  • 1
  • 7