22

After a upgrade to 18.04, from 16.04, all file names with spaces shows as 'file name'. Previously it was simply file name. File names without space shows up normally:

$ ls
 bar  'foo bar'

While it doesn't affect functionality in any way, I find this visually cluttering.

I use bash as shell.

How can I remove '' showing around file names with spaces?

  • 4
    Why do you want to remove them, they are not part of the filename and might help you managing filenames with spaces on command line or in scripts. – Soren A Dec 31 '18 at 16:10
  • 2
    I'm aware they are not part of the file name. But they are visual clutter, and I don't need them. – vidarlo Dec 31 '18 at 16:19
  • 4
    @SorenA If you use ls to manage files in your scripts you’re doing it wrong. Why you shouldn't parse the output of ls and Why not parse ls (and what do to instead)? – dessert Dec 31 '18 at 16:32
  • 2
    @WinEunuuchs2Unix It makes pasting easier, but as your answer mentions, it doesn't change behaviour when not outputting to terminal... – vidarlo Jan 1 at 14:14
  • 2
    @vidarlo The ls author is at least addressing some of the issues. Knowing the author is actively involved in Stack Exchange (the link in my answer) one could more easily suggest future improvements. Then comment upvotes from other users would encourage author to implement suggestions. – WinEunuuchs2Unix Jan 1 at 14:28
32

This ls behavior change was from 2016 but is finally making it's way into Ubuntu.

To get back the old behavior use ls -N.

Optionally you can use an environmental variable:

QUOTING_STYLE=literal ls

Make it an alias, or set export QUOTING_STYLE=literal in your ~/.bashrc to achieve the old behavior.

You can read the link above for more details including the history of when, where, why and how this all came to be. There are quite a few comments under the author of ls changes where he justifies the new behavior:

A few points about the change.

  • It was introduced in coreutils v8.25, and alignment improved in v8.26
  • It only happens when outputting to terminals so doesn't break scripts
  • It disambiguates the output for users for files containing whitespace
  • It sanitizes output so it is safe to copy and paste
  • Output is now always valid to copy and paste back to shell
  • Users can get back to the old format by adding -N to their ls alias
11

It's ls that is quoting the output, run:

ls -N

to get the output without any quoting.

man ls

-N, --literal

print entry names without quoting


Alias it if you want:

echo "alias ls='ls -N'" >> .bashrc

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.