Bash – Wondering about a nice combo of ls & cat

bashcatcommand linelsshell-script

As ll, I use ls -alh /some/file frequently, and just as often then, follow immediately with cat /some/file. I have to believe this has been addressed with various aliases. And on the next level, with shell functions. I have written a couple hundred aliases, but no shell function. Maybe that's what the doctor orders. Is this an old hat? Is there a shelf remedy? Thank you.

Best Answer

lcat() {
    ls -alh "$@"
    cat "$@"
}

or with less instead of cat. Or ( ls -alh "$@"; cat "$@") | less to see the permissions and all in the same browseable listing.

The I would need is something like this:

lcd() {
    if [ -d "$1" ]; do
        ls -lvF "$1"
    else
        less "$1"
    fi
}

i.e. either take a listing of a directory or view file. There's probably some less frontend that already runs ls on directories, but anyway.

Related Question