if($1 == "total") { // Set X when start of ls is detectedX = 1} else if (!X) { // Until X is set, collect the sizes from `du`SIZES[$2] = $1} else {// Replace the size on current current line (with alignment)sub($5 "[ ]*", sprintf("%-7s ", SIZES["./" $9]), $0);print $0}
样例输出:
drwxr-xr-x 2 root root 4.0K Feb 12 16:43 cgi-bindrwxrws--- 6 root www 20M Feb 18 11:07 document_rootdrwxr-xr-x 3 root root 1.3M Feb 18 00:18 iconsdrwxrwsr-x 2 localusr www 8.0K Dec 27 01:23 passwd
function duls {paste <( du -hs -- "$@" | cut -f1 ) <( ls -ld -- "$@" )}
我称它为duls,因为它显示了du和ls的输出(按此顺序):
$ duls210M drwxr-xr-x 21 kk staff 714 Jun 15 09:32 .
$ duls *36K -rw-r--r-- 1 kk staff 35147 Jun 9 16:03 COPYING8.0K -rw-r--r-- 1 kk staff 6962 Jun 9 16:03 INSTALL28K -rw-r--r-- 1 kk staff 24816 Jun 10 13:26 Makefile4.0K -rw-r--r-- 1 kk staff 75 Jun 9 16:03 Makefile.am24K -rw-r--r-- 1 kk staff 24473 Jun 10 13:26 Makefile.in4.0K -rw-r--r-- 1 kk staff 1689 Jun 9 16:03 README120K -rw-r--r-- 1 kk staff 121585 Jun 10 13:26 aclocal.m4684K drwxr-xr-x 7 kk staff 238 Jun 10 13:26 autom4te.cache128K drwxr-xr-x 8 kk staff 272 Jun 9 16:03 build60K -rw-r--r-- 1 kk staff 60083 Jun 10 13:26 config.log36K -rwxr-xr-x 1 kk staff 34716 Jun 10 13:26 config.status264K -rwxr-xr-x 1 kk staff 266637 Jun 10 13:26 configure8.0K -rw-r--r-- 1 kk staff 4280 Jun 10 13:25 configure.ac7.0M drwxr-xr-x 8 kk staff 272 Jun 10 13:26 doc2.3M drwxr-xr-x 28 kk staff 952 Jun 10 13:26 examples6.2M -rw-r--r-- 1 kk staff 6505797 Jun 15 09:32 mrbayes-3.2.7-dev.tar.gz11M drwxr-xr-x 42 kk staff 1428 Jun 10 13:26 src
$ duls doc7.0M drwxr-xr-x 8 kk staff 272 Jun 10 13:26 doc
$ duls [bM]*28K -rw-r--r-- 1 kk staff 24816 Jun 10 13:26 Makefile4.0K -rw-r--r-- 1 kk staff 75 Jun 9 16:03 Makefile.am24K -rw-r--r-- 1 kk staff 24473 Jun 10 13:26 Makefile.in128K drwxr-xr-x 8 kk staff 272 Jun 9 16:03 build