Soc*_*tes 43 command-line bash alias
有人可以告诉我别名ll用于什么终端命令吗?我能在网上找到的是许多人说,这是一个别名ls -l或ls -la或ls -ltr。但这完全是错误的。结果看起来不一样。有没有办法定位ll和查看它的语法?
Byt*_*der 92
您可以使用alias或type命令来检查特定别名的含义:
$ alias ll
alias ll='ls -alF'
$ type ll
ll is aliased to `ls -alF'
Run Code Online (Sandbox Code Playgroud)
但是请注意,别名可能会使用其他别名,因此您可能必须递归检查它,例如在 的情况下ll,您还应该检查ls它调用的命令:
$ alias ls
alias ls='ls --color=auto'
$ type ls
ls is aliased to `ls --color=auto'
Run Code Online (Sandbox Code Playgroud)
所以ll实际上意味着:
ls --color=auto -alF
Run Code Online (Sandbox Code Playgroud)
des*_*ert 18
ll是在您的 中定义的别名~/.bashrc,前提是您没有更改它ls -alF:
$ grep ll= <~/.bashrc
alias ll='ls -alF'
Run Code Online (Sandbox Code Playgroud)
这三个选项是:
作为
$ grep ls= <~/.bashrc
alias ls='ls --color=auto'
Run Code Online (Sandbox Code Playgroud)
显示,ls它本身又是一个别名ls --color=auto:
使用
--color=auto,ls仅当标准输出连接到终端时才发出颜色代码。该LS_COLORS环境变量可以更改设置。使用dircolors命令进行设置。
您可以查看您的 ~/.bashrc (或您的别名所在的某个文件),或者您可以在您的 shell 中编写其中一些命令:
command -v ll # "command" is a shell built-in that display information about
# the command. Use the built-in "help command" to see the
# options.
type -p ll # "type" is another built-in that display information about how the
# command would be interpreted
grep -r "alias ll=" ~ # and don't worry about de .file that contains your
# alias. This command search recursively under each
# folder of your home. So it's something rude.
find ~ -maxdepth 1 -type f | xargs grep "alias ll" # Just look in
# the files (not folders) in your home folder
Run Code Online (Sandbox Code Playgroud)
但是为什么要使用 find 而不带 -name ".*" 呢?因为你可以把它放在你的 .bashrc 中
source bash_hacks # where the file bash_hacks, in your home directory can
# contain the alias ll='ls -la etc etc'.
Run Code Online (Sandbox Code Playgroud)
由于“ll”它是一个别名,它没有必要只有一个含义(ll='ls -alF --color'),您可以像另一个命令一样将您的“ll”作为别名,我不知道,“rm” . 我认为这更像是一种约定(常用产品)。
但是“ll”可以是存储在 PATH 任何文件夹中的程序。例如,如果您的家中有一个名为“bin”的文件夹,请制作一个包含类似内容的“ll”脚本
#!/bin/bash
ls -lhar
Run Code Online (Sandbox Code Playgroud)
但是,如果您的 PATH 已被更改以添加另一个包含新“ll”命令的文件夹,该怎么办?有关更多有趣的信息,您可以参考以下相关问题的链接。