What's the easiest way to remove the "total <size>" line from the output of ls -l?

Solution 1:

Looking in the source code of coreutils, I found out that total will always be displayed when using the -l option on directories.

Using the -d option to list entries instead of directory contents hides total. But if you run that without arguments (or on a directory), it'll just show the directory and not its contents. Therefore, you need wildcards. * matches all files and .* matches hidden files as well (which corresponds with the -a option):

ls -ld * .*

As for the -h option, it works for me. 1118360 bytes show up as 1.1M. Files smaller than 1024 show up in bytes.

Solution 2:

Using wildcards to avoid having ls running the directory listing is suboptimal, because it prevents you from using ls options like --almost-all.

Like Enzotib's suggestion, the simplest way to remove it is to pipe it through tail to chop off the first line. However, ls will detect that it its output is a pipe rather than interactive, and change its defaults in an unwanted way. Hence, to make it robust, you should also add some options:

  • --color=always: keep showing colors
  • --hide-control-chars: print ? in filenames in place of control characters that could mess up the console output

I have a script ~/bin/l (you could also use a Bash alias in ~/.bash_aliases):

#!/bin/bash
ls -l --color=always --hide-control-chars "$@" | tail --lines=+2

You can also add any other ls options you want by default, e.g. --group-directories-first --time-style='+%FT%T.%N%:::z' --indicator-style=slash.