Skip to content

Instantly share code, notes, and snippets.

@jjsty1e
Last active March 30, 2018 08:24
Show Gist options
  • Save jjsty1e/bbb0a69792a1f04a215308b338e5687f to your computer and use it in GitHub Desktop.
Save jjsty1e/bbb0a69792a1f04a215308b338e5687f to your computer and use it in GitHub Desktop.
ls extend
#!/bin/bash
#########################################################################
# File Name: Advanced_ls_commond.sh
# Author: LookBack
# Email: admin#dwhd.org
# Version:
# Created Time: 2015年09月09日 星期三 03时52分41秒
# usage: wget -cq http://www.dwhd.org/script/lsmod -O /bin/lsmod && chmod +x /bin/lsmod && echo 'alias ls="/bin/lsmod"' >> ~/.bashrc && . ~/.bashrc
#########################################################################
LSARGS="${@}"
LSPATH="/bin/ls"
#[ -z "${LSARGS}" ] && ( ${LSPATH} && exit )
lsmod() {
awk '{
if($1!="total"){
k=0;
s=0;
for(i=0;i<=8;i++ ){
k+=((substr($1,i+2,1)~/[rwxst]/)*2^(8-i))
}
j=4;
for(i=4;i<=10;i+=3){
s+=((substr($1,i,1)~/[stST]/)*j);
j/=2
}
if(k){
printf("%0o%0o ",s,k)
}
print}
else {print}
}'
}
awk '{for(i=1;i<=NF;i++)if($i~/^-(.*)?[lno]/)a=0;exit}END{if (a~/0/){exit 0}else{exit 1}}' <<< $LSARGS
[ $? -eq 0 ] && ${LSPATH} --color="auto" $LSARGS | lsmod || ${LSPATH} $LSARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment