A nice ls alias

edited 5:10AM in Technical

Here's a nice "ls" alias for .bashrc

# alias for ls
lss() {
  ls -ald --color "$@" | less -RFX
}

^ Edited to quote the arguments "$@"

With the arguments quoted the "No such file or directory" error gets cut off.

$ lss *blah*
quoted
: No such file or directory

not quoted
ls: cannot access '*blah*': No such file or directory

But, overall it works better if you're passing quotes.

$ lss "test file.txt"
quoted
-rw-rw-r-- 1 david david 5 Oct  8 12:39 test file.txt

not quoted
ls: cannot access 'test': No such file or directory
ls: cannot access 'file.txt': No such file or directory
Tagged:

Comments

  • Ugh, after testing various arguments I forgot to test it without.

    This works better.

    # alias for ls
    lss() {
      if [[ "$@" == "" ]]
      then
        ls -al --color "$@" | less -RFX
      else
        ls -ald --color "$@" | less -RFX
      fi
    }
    

    ls -d is helpful when passing a wildcard, so the directory names are listed instead of recursing into directories, but without any arguments it just lists the home directory.

Sign In or Register to comment.