Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
3  
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
add comment

4 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
actually -d lists directories instead of entries. –  broiyan 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
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

$ 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'


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

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.