3

ls --dired -l prints all dir and files along with some number followed by

//DIRED// ***66 69 122 131 ....***
//DIRED-OPTIONS// --quoting-style=literal

What do these numbers in bold mean?

--dired is an Emacs option to work with directories but I don't understand the numbers here.

0
6

The output of ls -D is meant to be parsed by Emacs' dired mode.

From the GNU Coreutils manual

‘-D’
‘--dired’

With the long listing (-l) format, print an additional line after the main output:

//DIRED// beg1 end1 beg2 end2 …

The begn and endn are unsigned integers that record the byte position of the beginning and end of each file name in the output. This makes it easy for Emacs to find the names, even when they contain unusual characters such as space or newline, without fancy searching.

If directories are being listed recursively (-R), output a similar line with offsets for each subdirectory name:

//SUBDIRED// beg1 end1 …

Finally, output a line of the form:

//DIRED-OPTIONS// --quoting-style=word

where word is the quoting style (see Formatting the file names).

Here is an actual example:

$ mkdir -p a/sub/deeper a/sub2
$ touch a/f1 a/f2
$ touch a/sub/deeper/file
$ ls -gloRF --dired a
  a:
  total 8
  -rw-r--r-- 1    0 Jun 10 12:27 f1
  -rw-r--r-- 1    0 Jun 10 12:27 f2
  drwxr-xr-x 3 4096 Jun 10 12:27 sub/
  drwxr-xr-x 2 4096 Jun 10 12:27 sub2/

  a/sub:
  total 4
  drwxr-xr-x 2 4096 Jun 10 12:27 deeper/

  a/sub/deeper:
  total 0
  -rw-r--r-- 1 0 Jun 10 12:27 file

  a/sub2:
  total 0
//DIRED// 48 50 84 86 120 123 158 162 217 223 282 286
//SUBDIRED// 2 3 167 172 228 240 290 296
//DIRED-OPTIONS// --quoting-style=literal

Note that the pairs of offsets on the ‘//DIRED//’ line above delimit these names: f1, f2, sub, sub2, deeper, file. The offsets on the ‘//SUBDIRED//’ line delimit the following directory names: a, a/sub, a/sub/deeper, a/sub2.

Here is an example of how to extract the fifth entry name, deeper, corresponding to the pair of offsets, 222 and 228:

$ ls -gloRF --dired a > out
$ dd bs=1 skip=222 count=6 < out 2>/dev/null; echo
deeper

Note that although the listing above includes a trailing slash for the deeper entry, the offsets select the name without the trailing slash. However, if you invoke ls with --dired along with an option like --escape (aka -b) and operate on a file whose name contains special characters, notice that the backslash is included:

$ touch 'a b'
$ ls -blog --dired 'a b'
  -rw-r--r-- 1 0 Jun 10 12:28 a\ b
//DIRED// 30 34
//DIRED-OPTIONS// --quoting-style=escape

If you use a quoting style that adds quote marks (e.g., --quoting-style=c), then the offsets include the quote marks. So beware that the user may select the quoting style via the environment variable QUOTING_STYLE. Hence, applications using --dired should either specify an explicit --quoting-style=literal option (aka -N or --literal) on the command line, or else be prepared to parse the escaped names.

The numbers are the positions of the file names in the output

The begn and endn are unsigned integers that record the byte position of the beginning and end of each file name in the output.

1
  • Of course, there is no 222 in the ls --dired example quoted from the info page. But there is a 223. If one is supposed to subtract 1 from all offsets, that is not how it works in my tests – usretc Jan 11 at 7:37
1

-D, --dired
generate output designed for Emacs' dired mode.

6
  • what asked is --dired mode for "ls" command not for Emacs. Read the question carefully. – sameer pradhan Oct 26 '15 at 8:24
  • @sameerpradhan Yes the output of ls is made for Emacs. – Matteo Oct 26 '15 at 8:32
  • 1
    @Matteo Yes. But see my question 1st. What i want to know the numbers below the output of "ls --dired -l" command. – sameer pradhan Oct 26 '15 at 8:36
  • @sameerpradhan The output is meant for Emacs, the suggestion to look at the Emacs documentation is correct. – Matteo Oct 26 '15 at 8:40
  • 1
    @matteo :Again I am saying this, My question was : what are these numbers printed at the bottom of the output of "ls --dired -l" followed by //DIRED//. – sameer pradhan Oct 26 '15 at 8:44

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.