如何在 Linux 中为“ls”设置默认参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9120406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:20:42  来源:igfitidea点击:

How can I set default arguments for "ls" in Linux?

linuxls

提问by JoshL

Im constantly doing "ls -ahl" whenever I want to list what is in the directory. Is there a way for me to make -ahl the default args passed when I do "ls" or should I just create an alias like "alias lsa=ls -ahl" in bash_profile?

每当我想列出目录中的内容时,我都会不断地执行“ls -ahl”。有没有办法让 -ahl 成为我执行“ls”时传递的默认参数,还是应该在 bash_profile 中创建一个像“alias lsa=ls -ahl”这样的别名?

采纳答案by dlannoye

You could just alias ls itself. So something like:

你可以只是别名 ls 本身。所以像:

alias ls='ls -ahl'

回答by Kevin

Create an alias in your .bashrc. You can even call it lsand override the program.

在您的.bashrc. 您甚至可以调用它ls并覆盖该程序。

回答by Chris Seymour

Set an aliasin your ~/.bash_profilefile.

alias在您的~/.bash_profile文件中设置一个。

alias ls="ls -ahl"

A couple of common aliases that I use all the time are:

我一直使用的几个常见别名是:

alias ll="ls -lh --color"
alias l="ls -1"