别名 ll 用于什么命令?

Soc*_*tes 43 command-line bash alias

有人可以告诉我别名ll用于什么终端命令吗?我能在网上找到的是许多人说,这是一个别名ls -lls -lals -ltr。但这完全是错误的。结果看起来不一样。有没有办法定位ll和查看它的语法?

Byt*_*der 92

您可以使用aliastype命令来检查特定别名的含义:

$ 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)

  • 请注意,在一般情况下,一个命令可以同时具有多个定义。`type -a commandname` 将显示所有内容 - 它会按照优先顺序告诉您该命令是别名、函数、内置文件中的一个或多个,还是 PATH 中的一个或多个可执行文件。这有助于理解为什么,例如,取消命令的别名不会将其完全返回到预期的行为。 (10认同)
  • 我推荐 `alias ll='ls -lh'`。如果您想要以字节为单位而不是人类友好的 B / kiB / MiB / GiB 大小,您可以运行“ls -l”。 (2认同)

des*_*ert 18

ll是在您的 中定义的别名~/.bashrc,前提是您没有更改它ls -alF

$ grep ll= <~/.bashrc
alias ll='ls -alF'
Run Code Online (Sandbox Code Playgroud)

这三个选项是:

  • -a, --all – 不要忽略以 .
  • -l – 使用长列表格式
  • -F, --classify – 将指示符(*/=>@| 之一)附加到条目

作为

$ grep ls= <~/.bashrc
alias ls='ls --color=auto'
Run Code Online (Sandbox Code Playgroud)

显示,ls它本身又是一个别名ls --color=auto

使用--color=auto,ls仅当标准输出连接到终端时才发出颜色代码。该LS_COLORS环境变量可以更改设置。使用dircolors 命令进行设置。

  • 没有必要将文件重定向到 `grep`,它会将文件名作为参数。虽然 grepping 启动文件将帮助您找到 _where_ 别名是(重新)定义的(请注意,它可能位于 `/etc` 中的文件中 - 知道如果您从用户启动文件中删除它,它将为您节省一些麻烦仍然存在甚至改变其行为),如果您只想快速了解定义是什么,_alias_ 命令(如已接受的答案中所述)将完成这项工作。 (2认同)

Cua*_*tli 5

您可以查看您的 ~/.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”命令的文件夹,该怎么办?有关更多有趣的信息,您可以参考以下相关问题的链接。