linux awk_Linux系统awk实现ls -l输出文件权限的数字&打造加强版的ls命令

更新时间:2020-04-20    来源:linux    手机版     字体:

【www.bbyears.com--linux】

ls -l | awk \"{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}\" 总用量 94372 0755 -rwxr-xr-x 1 www  www   8597776 8月  29 13:22 goproxy_arm 0755 -rwxr-xr-x 1 www  www  10592880 8月  29 13:29 goproxy_arm64 0644 -rw-r--r-- 1 www  www       129 8月  29 16:39 goproxy.bat 0755 -rwxr-xr-x 1 www  www   8647968 8月  29 13:21 goproxy_darwin_386 0755 -rwxr-xr-x 1 www  www  10731424 8月  29 13:21 goproxy_darwin_amd64 0755 -rwxr-xr-x 1 www  www   8588416 8月  29 13:21 goproxy_freebsd_386 0755 -rwxr-xr-x 1 www  www  10696016 8月  29 13:21 goproxy_freebsd_amd64 0755 -rwxr-xr-x 1 www  www   8631208 8月  29 13:20 goproxy_linux_386 0755 -rwxr-xr-x 1 www  www  10736192 8月  29 13:21 goproxy_linux_amd64 0755 -rwxr-xr-x 1 www  www   8665088 8月  29 13:21 goproxy_windows_386.exe 0755 -rwxr-xr-x 1 www  www  10696704 8月  29 13:22 goproxy_windows_amd64.exe 0644 -rw-r--r-- 1 root root    18311 8月  31 08:09 routes.list.gz 0644 -rw-r--r-- 1 www  www      1536 8月  29 13:49 RunHiddenConsole.exe

 

同时本站也作出了加强版的ls命令
#####一键升级加强版ls命令 wget -cq http://www.dwhd.org/script/lsmod -O /bin/lsmod && chmod +x /bin/lsmod && echo \"alias ls="/bin/lsmod"\" >> ~/.bashrc && . ~/.bashrc ######如果是Debian系系统请运行下面的一键 wget -cq http://www.dwhd.org/script/lsmod -O /bin/lsHmod && chmod +x /bin/lsHmod && echo \"alias ls="/bin/lsHmod"\" >> ~/.bashrc && . ~/.bashrc

 

Linux之awk实现ls -l输出文件权限的数字&打造加强版的ls命令
[root@vps197121 ~]# wget http://www.dwhd.org/script/lsmod -O /bin/lsmod && chmod +x /bin/lsmod && echo \"alias ls="/bin/lsmod"\" >> ~/.bashrc && . ~/.bashrc --2015-09-08 21:25:13--  http://www.dwhd.org/script/lsmod Resolving www.dwhd.org... 133.130.100.22, 2400:8500:1301:737:a133:130:100:220 Connecting to www.dwhd.org|133.130.100.22|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 783 [application/octet-stream] Saving to: “/bin/lsmod”  100%[===============================================================================>] 783         --.-K/s   in 0s        2015-09-08 21:25:14 (75.5 MB/s) - “/bin/lsmod” saved [783/783]  [root@vps197121 ~]# ls -l 0200 total 28 0644 -rw-r--r--  1 root root  3886 Sep  7 20:08 bench.sh 0644 -rw-r--r--  1 root root  4398 Aug 28 22:26 init.sh 0644 -rw-r--r--. 1 root root 10281 Dec  1  2014 install.log 0644 -rw-r--r--. 1 root root  3317 Dec  1  2014 install.log.syslog [root@vps197121 ~]# ls -la 0200 total 100 0550 dr-xr-x---.  5 root root  4096 Sep  8 19:00 . 0555 dr-xr-xr-x. 24 root root  4096 Aug 31 02:47 .. 0600 -rw-------.  1 root root  3376 Sep  8 18:37 .bash_history 0644 -rw-r--r--.  1 root root    18 May 20  2009 .bash_logout 0644 -rw-r--r--.  1 root root   176 May 20  2009 .bash_profile 0644 -rw-r--r--   1 root root    22 Sep  8 21:25 .bashrc 0644 -rw-r--r--   1 root root  3886 Sep  7 20:08 bench.sh 0644 -rw-r--r--.  1 root root   100 Sep 23  2004 .cshrc 0644 -rw-r--r--   1 root root  4398 Aug 28 22:26 init.sh 0644 -rw-r--r--.  1 root root 10281 Dec  1  2014 install.log 0644 -rw-r--r--.  1 root root  3317 Dec  1  2014 install.log.syslog 0755 drwxr-xr-x   5 root root  4096 Aug 31 05:24 .ipython 0740 drwxr-----   3 root root  4096 Aug 31 05:19 .pki 0644 -rw-r--r--   1  501  501  4149 Jul  9 11:40 .screenrc 0700 drwx------.  2 root root  4096 Sep  7 21:28 .ssh 0644 -rw-r--r--.  1 root root   129 Dec  3  2004 .tcshrc 0600 -rw-------   1 root root  4328 Sep  8 17:39 .viminfo 0644 -rw-r--r--   1  501  501  4546 Jul 16 11:33 .vimrc 0600 -rw-------   1 root root   126 Sep  8 18:43 .Xauthority [root@vps197121 ~]# ls /etc/fstab  /etc/fstab [root@vps197121 ~]# ls /etc/fstab -l 0644 -rw-r--r--. 1 root root 585 Aug 31 02:45 /etc/fstab [root@vps197121 ~]#

 

原版和加强版的区别

本文来源:http://www.bbyears.com/caozuoxitong/92891.html