ls -l adds a total line (for total number of blocks) at the top of its output. Is there a direct way to suppress this line from the output? I know I can pipe the output into another command to delete the first line, but I am wondering if I am missing a simple option to suppress that line in the first place.

  • 3
    May be ls -ld * helps
    – Costas
    Oct 25 '16 at 19:35
  • @Costas joined here just to upvote that comment. Exactly what I was looking for. Dec 21 '17 at 2:14

No, you're not missing a simple option to drop the total line, at least not when listing the contents of a directory (including the current one, with no arguments). For example, with GNU ls, the -l, -g, -n, -o and -s options cause the total line to be displayed, with no option to disable it:

if (format == long_format || print_block_size)
  const char *p;

  p = _("total");
  DIRED_FPUTS (p, stdout, strlen (p));
  p = human_readable (total_blocks, buf, human_output_opts,
                      ST_NBLOCKSIZE, output_block_size);
  DIRED_FPUTS (p, stdout, strlen (p));

This is actually mandated by POSIX.

However, if you specify the files to list, rather than a directory, ls won’t show the total; the -d option causes directories to be treated as files, producing the desired result, as mentioned by Costas:

ls -ld *

will produce the same output as

ls -l

minus the total line, as long as your shell doesn’t include hidden files when expanding * (dotglob) and as long as the current directory doesn’t contain so many files that the expansion of * exceeds the maximum command-line length.

You can specify a directory too (ls -ld /path/to/directory/*) but the output will list files with the given path, unlike ls -l /path/to/directory.

  • I only came back since someone posted a comment - and I found another comment that proves that in fact I was indeed missing something simple. ls -ld * seems to do the trick. Or am I missing something simple with that, now?
    – mathguy
    Apr 23 '20 at 20:08
  • Although ls -ld path/to/dir/* lists each filename in the form path/to/dir/x while ls -l path/to/dir lists only x. And both * forms fail if the total size of all filenames exceeds your system's ARGMAX. Also some shells have options to include some or all dotfiles in * while ls without -a or -A never will. Apr 24 '20 at 2:00

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.