linux - What is the best way to pass a command alias/function without reducing the functionality of said command? -
i have function ll
expands this:
function ll () { ls -lh --color "$@" | grep "^d"; ls -lh --color "$@" | grep "^-" | grep -v "~"; ls -lh --color "$@" | grep "^l" }
what sort listed folder showing directories first, files, links. however, find such approach reduces functionality of ls
command, instance if try call ll /bin /tmp
, mix of files both folders.
is there general rule of thumb pass command aliases/functions such full functionality of commands not reduced? if there isn't, how can fix ll
command retain sorting, full functionality of ls
not lost?
please note have bash version 3.2.25(1)-release on system (ls version 5.97), --show-directories-first
flag not available me.
edit:
this function ended using, modified ll
work without args:
function ll () { if [ $# -eq 0 ]; set -- .; fi d; ls -lh --color "$d"|awk '$1~/^d/{i=0} $1~/^l/{i=1} $1~/^-/{i=2} nf>2{print ofs $0}' | sort -n -k1,1 | cut -d ' ' -f2- done }
extending answer of @chepner:
instead of running ls
multiple times grep
think can combined in single command awk, sort, cut , same output (directories first files , links):
function ll () { d in "$@"; ls -lh --color "$d"|awk '$1~/^d/{i=0} $1~/^l/{i=1} $1~/^-/{i=2} nf>2{print ofs $0}'|sort -n -k1,1|cut -d ' ' -f2- done }
Comments
Post a Comment