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.

  • Does the bin directory have an actual space as the first character in its name? – Kusalananda Nov 21 at 10:43
  • @Kusalananda No, it doesn't. – StackedCrooked Nov 21 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 at 10:45
  • Which distro? And what does ls -l say -- does the space also appear in the columned listing? – Paul_Pedant Nov 21 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 at 10:46
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.