我想知道是否可以ls -l
通过自定义列修改命令。
例如,我希望此列包含每个文件,例如的第一行$(CustomCommand FILE)
。
这是一个非常基本的概念证明。并不是特别健壮(例如,带空格的文件名会破坏它),但可以理解这一点。
$ export CustomCommand=file
$ alias ls=/tmp/test/myls
$ ls
a b c myls
$ ls -l
-rw-rw-r-- 1 steve steve 0 Sep 22 19:17 a a: empty
-rw-rw-r-- 1 steve steve 0 Sep 22 19:17 b b: empty
-rw-rw-r-- 1 steve steve 0 Sep 22 19:17 c c: empty
-rwxr-xr-x 1 steve steve 127 Sep 22 19:18 myls myls: POSIX shell script, ASCII text executable
$ cat /tmp/test/myls
#!/bin/sh
if [ "$1" = "-l" ]
then
shift
ls -l $* | awk 'NF>2{ printf "%s ",$0 ; system("$CustomCommand " $NF) }'
else
ls $*
fi
$
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句