22

Ever since upgrading to emacs 24.x I've been seeing this error whenever I open a directory. The entire error is:

ls does not support --dired; see `dired-use-ls-dired' for more details.

Looking at the variable, one finds:

dired-use-ls-dired is a variable defined in `dired.el'.
Its value is nil
Original value was unspecified

Documentation:
Non-nil means Dired should pass the "--dired" option to "ls".
The special value of `unspecified' means to check explicitly, and
save the result in this variable.  This is performed the first
time `dired-insert-directory' is called.

Note that if you set this option to nil, either through choice or
because your "ls" program does not support "--dired", Dired
will fail to parse some "unusual" file names, e.g. those with leading
spaces.  You might want to install ls from GNU Coreutils, which does
support this option.  Alternatively, you might want to use Emacs's
own emulation of "ls", by using:
  (setq ls-lisp-use-insert-directory-program nil)
  (require 'ls-lisp)
This is used by default on MS Windows, which does not have an "ls" program.
Note that `ls-lisp' does not support as many options as GNU ls, though.
For more details, see Info node `(emacs)ls in Lisp'.

You can customize this variable.

I'm running on FreeBSD; so the default ls is not GNU'ish and doesn't offer the --dired option. I don't really feel like going to the trouble to install GNU coreutilities on all of my servers.

Anyone have any experience with the lisp ls alternative mentioned above?

Presumably dired.el is setting dired-use-ls-dired to something non-nil when loaded and I'm constantly clobbering it the first time I view a directory? And setting dired-use-ls-dired to nil in my .emacs would quiet the message?

Does anyone have the opinion that not getting dired to work might represent a security issue? i.e. would filenames composed of whitespace remain invisible?

Maybe I should test some of the above...

ericx
  • 835
  • 1
  • 10
  • 18
  • emacs relying on a GNU specific ls implementation, fun. I'm not familiar with ls-lisp, but not handling whitespace correctly in filenames screams possibly exploitable. – D'Nabre Nov 03 '14 at 07:25
  • "Presumably" -- you don't have to presume anything, just read the documentation you quoted. And if you want to know what happens to filenames composed of whitespace, just try one. And there's no security issue here, certainly as compared to unicode sequences that look identical to plain ASCII but aren't. – Jim Balter Oct 29 '18 at 01:25
  • 1
    "emacs relying on a GNU specific ls implementation, fun." -- emacs doesn't "rely" on it, it simply uses it if available. And it says right there that you can use `ls-lisp` if your `ls` doesn't support --dired; `ls-lisp` doesn't have all the features of GNU `ls`, but you don't need them for dired. And emacs handles whitespace correctly in filenames; it's `ls` that doesn't indicate which whitespace is or isn't part of the file name ... *but you don't have to use ls* ... just use `ls-lisp` instead. (emacs runs on some systems that don't have any `ls` command. It does not "rely" on it.) – Jim Balter Oct 29 '18 at 01:37
  • P.S. If you don't want blank file names to be invisible, set --quoting-style in dired-listing-switches (see man ls). – Jim Balter Nov 02 '18 at 02:53

3 Answers3

19

on macOS, ls doesn't support the --dired option while on Linux it is supported.

(when (string= system-type "darwin")       
  (setq dired-use-ls-dired nil))
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Aborn Jiang
  • 981
  • 10
  • 9
11

In this case you can also try to use gnu-ls, you can install this utilities takea look here how-to-replace-mac-os-x-utilities-with-gnu-core-utilities

In my case I maintain both and the gnu core utilities are prefixed by "g".

If you use gls, the --dired argument is enabled

man gls

NAME ls - list directory contents

SYNOPSIS ls [OPTION]... [FILE]...

DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

   Mandatory arguments to long options are mandatory for short options too.


                             .... 
   -d, --directory
          list directories themselves, not their contents

                              ....
which gls                                                                                                                                                                
/usr/local/bin/gls

Then we have all too configure emacs:

(when (string= system-type "darwin")
  (setq dired-use-ls-dired t
        insert-directory-program "/usr/local/bin/gls"
        dired-listing-switches "-aBhl --group-directories-first"))

Then you can use this:

anquegi
  • 11,125
  • 4
  • 51
  • 67
4

Presumably dired.el is setting dired-use-ls-dired to something non-nil when loaded and I'm constantly clobbering it the first time I view a directory? And setting dired-use-ls-dired to nil in my .emacs would quiet the message?

I think what you say is correct. Customize the value to nil. (If that doesn't help you can always remove your customization.)

Drew
  • 29,895
  • 7
  • 74
  • 104
  • 1
    I tried setting dired-use-ls-diredto nil on my OSX machine running 24.5.1, and it did get rid of the message. Dired seemed to work normally afterwards, as well. – Kevin May 01 '16 at 02:18
  • @kevin *if you set this option to nil ... Dired will fail to parse some "unusual" file names, e.g. those with leading spaces*. Unless you have such files, of course dired will "work normally". – Jim Balter Oct 29 '18 at 01:42