在我的工作笔记本电脑上输入ls -l
输出:
drwx------+ 3 abcd123e VERYLONGDOMAINNAME\Domain Users 102 May 4 09:35 Movies
drwx------+ 4 abcd123e VERYLONGDOMAINNAME\Domain Users 136 May 5 00:25 Music
drwx------+ 3 abcd123e VERYLONGDOMAINNAME\Domain Users 102 May 4 09:35 Pictures
是否可以用ls
的输出替换长而丑陋的组名(可能还有用户),而不是修改任何系统设置,类似于:
drwx------+ 3 fb dusers 102 May 4 09:35 Movies
drwx------+ 4 fb dusers 136 May 5 00:25 Music
drwx------+ 3 fb dusers 102 May 4 09:35 Pictures
答案 0 :(得分:1)
<击> 我最近能做的就是
alias ll="ls -l | sed -- 's/USER GROUPNAME/replacement/'"
示例强>
$ ls -l
drwxr-xr-x+ 3 Theofanis staff 102 4 May 13:01 Desktop
drwx------+ 26 Theofanis staff 884 20 Mar 13:59 Documents
drwx------+ 22 Theofanis staff 748 5 May 12:38 Downloads
$ alias ll="ls -l | sed -- 's/Theofanis staff/somebody/'"
$ ll
drwxr-xr-x+ 3 somebody 102 4 May 13:01 Desktop
drwx------+ 26 somebody 884 20 Mar 13:59 Documents
drwx------+ 22 somebody 748 5 May 12:38 Downloads
击> $@
,以便您可以将参数传递给 ls 。--color=always
以不断输出颜色。
function ll() {
/bin/ls -l --color=always "$@" |
sed -- 's/USER1 GROUPNAME1/replacement1/' |
sed -- 's/USER2 GROUPNAME2/replacement2/'
}
$ ls -l
drwxr-xr-x+ 3 Theofanis staff 102 4 May 13:01 Desktop
drwx------+ 26 Theofanis staff 884 20 Mar 13:59 Documents
drwx------+ 22 Theofanis staff 748 5 May 12:38 Downloads
drwx------+ 22 Theofanis admin 748 5 May 12:38 Public
$ function ll() {
ls -l --color=always "$@" |
sed -- 's/Theofanis staff/somebody/' |
sed -- 's/Theofanis admin/someone/'
}
$ ll
drwxr-xr-x+ 3 somebody 102 4 May 13:01 Desktop
drwx------+ 26 somebody 884 20 Mar 13:59 Documents
drwx------+ 22 somebody 748 5 May 12:38 Downloads
drwx------+ 22 someone 748 5 May 12:38 Public
$ ll -F # appends '/' on directories
drwxr-xr-x+ 3 somebody 102 4 May 13:01 Desktop/
drwx------+ 26 somebody 884 20 Mar 13:59 Documents/
drwx------+ 22 somebody 748 5 May 12:38 Downloads/
drwx------+ 22 someone 748 5 May 12:38 Public/