The best I could find via Google/man ls was:

ls -l | grep -v '^total'

Is there something I'm missing in the flags to ls?

Also, why is the total size in kb, regardless of the -h flag? scratch that, seems like it does, not sure what I was seeing then.

  • 5
    Perhaps a little bit more efficient could be ls -l | tail -n+2, for the rest I do not have an answer.
    – enzotib
    Sep 13 '11 at 9:25
  • I like enzotib's method more. Suggestion: set it up as an alias and name it lsl. Just 3 letters ;) oh and ls -lh shows me 1.2K styled sizes.
    – Rinzwind
    Sep 13 '11 at 9:30
  • I think you've gotten the easiest way.
    – Robert
    Sep 23 '18 at 14:09
  • Lots of good suggestions here for the general case of removing any first line of an output
    – prosoitos
    Jun 27 '20 at 18:11

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.

  • 1
    actually -d lists directories instead of entries.
    – H2ONaCl
    Sep 21 '13 at 5:39
  • @broiyan You can take the ls manual page to the letter or consider this: ls / can be interpreted as "list the entry / if it is a file or the directory contents of / if it is a directory". Using -d removes the last condition and will always print the entry instead of directory contents. This applies no matter if a path is a file or directory.
    – Lekensteyn
    Sep 21 '13 at 9:41
  • I'd upvote this again if i could
    – a2f0
    Mar 17 '18 at 22:04

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):

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.

  • However, this won't work if you if you pass multiple filenames to ls.
    – Sparhawk
    Apr 26 '17 at 3:57

ls -l *

Will give you "normally named" folder contents without the total. That might be suitable for your needs. Unfortunately, it will not give you the dot prefixed files. If you use ls -l * .* you will get a mess since linux will navigate up the tree.

Note the dot prefix could mean the folder or with a wildcard it means the above folder so it does not help you to pick regular files that are dot prefixed. This seems to have been an unfortunate design decision.

  • Even ls -l * will list contents of the directories, not the directories themselves.
    – x-yuri
    Sep 12 at 14:23

$ ls -l [DIRECTORY] | sed 1d
(output contains file names)

$ ls -ld [path-to-dir]/*
(output contains relative paths but will preserve colors)

$ ls -l [DIRECTORY] | tail -n +2

$ ls -l [DIRECTORY] | awk 'NR>=1'

The following doesn't work if you have a file named "total...."

$ ls -l | grep -v '^total'

  • ...or if you have a non-English locale: LANG=ja_JP.utf8 ls -al | head -n 1 (given that the locale is installed).
    – x-yuri
    Sep 12 at 14:17

To answer your exact question would be ls -1A . which displays files, directories, and hidden files/directories, does not use any pipes or external tools (grep/tr/cut..), and does not rely on turning on or off any shell globbing options such as extglob, globstar, or nullglob. I have tested it to verify that statement.

-1    list one file per line.  Avoid '\n' with -q or -b
-A,   --almost-all           do not list implied . and ..

Example output:

user@host:/dir$ ls -1A .

As a side note, here is what I keep in my .bash_aliases relating to listing dirs/files:

# ls directories
alias lsd2='ls -d */'
alias lsd3='ls -p . | grep -E "/$" | tr -d "/"'
alias lsd4='ls -lA | grep -E "^d"'
alias lsd5='ls -pv . | grep -E "/$" | tr -d "/"'
alias lsd='ls -lAd */'
# ls files
alias lsf='ls -pA | grep -vE "/$"'
alias lsf2='ls -p | grep -v "/"'
alias lsf3='ls -p . | grep "/" | tr -d "/"'
alias lsf4='ls -lA | grep -vE "^d"'
# ls normal
alias lsnormal='ls -lAh1d *'
alias lsnormal2='ls -1 .'

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.