我必须操作什么系统文件才能创建宏?

时间:2013-10-31 15:35:50

标签: ubuntu macros ubuntu-12.04

例如,我想以详细格式ls -l而不是通常的ls格式列出当前工作目录中的所有文件,而不必每次都输入该选项。任何帮助,将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:1)

你称之为“宏”,在bash中被定义为“别名”。从man bash(在第3744行的某处):

alias [-p] [name[=value] ...]
          Alias with no arguments or with the -p option prints the list of
          aliases in the form alias name=value on standard  output.   When
          arguments  are supplied, an alias is defined for each name whose
          value is given.  A trailing space in  value causes the next word
          to be checked for alias substitution when the alias is expanded.
          For each name in the argument list for which no  value  is  sup‐
          plied,  the  name  and  value  of  the  alias is printed.  Alias
          returns true unless a name is given for which no alias has  been
          defined.

您可以在~/.bash_aliases文件中创建别名,如下所示:

alias ls="ls -l"

此外,在Ubuntu 12.04中,ls文件中已存在~/.bashrc的别名,您可以根据需要进行更新。要找到它,请搜索以下行:

alias ls="ls --color=auto"

并将其更改为:

alias ls="ls --color=auto -l"

有关How to create a permanent “alias”?

的更多信息