When you type dir in terminal, the name file with space separate with symbol backslash \

Terminal Text

$ cd LALALA
~/LALALA $ dir
la\ la\ 1 la\ la\ 2
~/LALALA $ 

Directory Image

Directory Image

When I use dir command in terminal, the list of file show \ (backslash) to separate their word (see: Terimanal Image). Whereas in the origin, there is no '\' (backslash) (see: Directory Image). How do I change this back to normal?

NB. I think the reason is because of the pwd command on the terminal. After I use the PWD command, this happens.


What you experience is quoting, dir has the -N or --literal option to disable it:

-N, --literal
       print entry names without quoting

The exact same applies to ls, just that it quotes the whole filenames with single quotes instead of escaping special characters (which can be triggered with -b or --escape for ls as well). Calling ls with -N disables this behaviour as well.

Example run

$ touch 'la la '{1,2}
$ dir
la\ la\ 1  la\ la\ 2
$ dir -N
la la 1  la la 2
$ ls
'la la 1'  'la la 2'
$ ls -b
la\ la\ 1  la\ la\ 2
$ ls -N
la la 1  la la 2

Further reading

  • man dir and info dir
  • Difference between 'dir' and 'ls' terminal commands?
  • Regarding the similar behaviour of ls: Filenames with space showing as 'file name' after upgrade to 18.04