How to display column headers for 'ls -l' command in unix/linux? How to display column headers for 'ls -l' command in unix/linux? linux linux

How to display column headers for 'ls -l' command in unix/linux?


exa is a replacement/enhancement for ls. If you pass on the arguments -lh with exa, it will include a header row printing the column names like so:

exa -lh

Example output:

Permissions Size User     Date Modified Name.rwx------    19 username 29 Sep 11:25  dont_cra.shdrw-r-----     - username 29 Sep 11:26  f1.rw-r--r--@ 811k username 29 Sep 11:25  row_count.dat.rw-r--r--    54 username 29 Sep 11:25  some_text.txt

You can set up an alias in .bashrc that replaces ls with exa.


The last answer using sed was slick, but unfortunately, if you have color added to your output (which most people do) it removes all color. I would like to suggest a better way, and ironically, simpler too.

First off, my .bashrc USED to have the following:

 enable color support of ls and also add handy aliasesif [ -x /usr/bin/dircolors ]; then    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"alias ls='ls --color=auto'fialias ls='ls -AFhls --color --group-directories-first'

To be honest, you don't need the dircolors part, that is just a little extra I use, you could have something as simple as:

alias ls='ls --color=auto'

I wanted column headers too, Googled it, and wound up here. However after I tried what the previous user suggested, with sed and realizing everything was white, and my colors have all gone away.

That's when I tried something different in my bashrc file, and it worked.

Simply alias ls, echo first, then place a semi-colon, then your ls command.My .bashrc file now has the following line.

alias ls='echo "Dir Size|Perms|Link Count|Owner|Group|Size|Mod. Time|Name"; ls -AFhls --color --group-directories-first'

When doing it this way, utilizing echo instead of sed, all colors continue to work.


Not sure if this is specific to my terminal's output but, this worked for me.

enter image description here

And this is the output it yields. As you can see, it preserves color using this method. Just be sure to keep the ${1} variable in double quotes so files and directories with spaces in the name won't cause an error.

enter image description here

Here is the code so you can copy and paste for testing.

long_ls() {local VAR="Permissions|Owner|Group|Size|Modified|Name"if [ ! "${1}" ]; then   echo -e "$VAR" | column -t -s"|" && ls -lelse   echo -e "$VAR" | column -t -s"|" && ls -l "${1}"fi}alias lls=$"long_ls ${1}"