简体   繁体   English

Linux 命令“将”不起作用

[英]Linux command 'll' is not working

我可以用我的用户运行 ll 命令,但不能用 sudo,它给我错误,因为找不到命令!

ll创建别名。

alias ll="ls -al"

Try sudo ls -l .试试sudo ls -l

As ll is a shorthand for ls -l .因为llls -l的简写。

As it has been explained:正如它所解释的:

ll is actually an alias to ls -l ll实际上是ls -l的别名

In your prompt, I would recommend using the following 3 commands when you are not sure about a command that you input:在您的提示中,当您不确定输入的命令时,我建议您使用以下 3 个命令:

  • type <command_name> will give you information about the command, in our particular case, the output will be: ll is aliased to 'ls -l' type <command_name>会给你关于命令的信息,在我们的特殊情况下,输出将是: ll is aliased to 'ls -l'

    • which <command_name> will show you the path of the command you are going to use which <command_name>将显示您将要使用的命令的路径

    • whatis <command_name> will give you basic information about the command whatis <command_name>会给你关于命令的基本信息

Last but not least, alias ll="ls -al" will allow you to create the alias you are looking for.最后但并非最不重要的是, alias ll="ls -al"将允许您创建您正在寻找的别名。 However to avoid redefining your aliases every single time you open a new shell.但是,为了避免每次打开新 shell 时都重新定义别名。 You will have to save them in your .profile or add them in your .bashrc file (use .bash_aliases file for this purpose and uncomment that section in your .bashrc ) in the home directory of your user.您必须将它们保存在.profile或将它们添加到用户home directory中的.bashrc文件中(为此使用.bash_aliases文件并取消注释.bashrc中的该部分)。

For additional information, please have a look at the following link:有关其他信息,请查看以下链接:

https://unix.stackexchange.com/questions/183496/how-to-create-permanent-aliases-on-unix-like-systems https://unix.stackexchange.com/questions/183496/how-to-create-permanent-aliases-on-unix-like-systems

That's expected because ll is defined in your profile (.bashrc in Ubuntu, for instance).这是意料之中的,因为 ll 是在您的配置文件中定义的(例如,Ubuntu 中的 .bashrc)。

grep "alias ll" ~/.bashrc
alias ll='ls -alF'

Your .bashrc will not run when you sudo.当您使用 sudo 时,您的 .bashrc 将不会运行。

I am quite late, but ... In Debian 10 the command ll is commented (#) .我来晚了,但是...在 Debian 10 中,命令ll注释 (#)

To make ll available just change yourr .bashrc file:要使ll可用,只需更改您的.bashrc文件:

su gedit .bashrc

After in your text editor uncommnet as you wish:在你的文本编辑器中 uncommnet 后,如你所愿:

# some more ls aliases alias ll='ls -l' #alias la='ls -lA'

Do not forget to restart your terminal emulator .不要忘记重新启动您的终端模拟器

In order to run ll with sudo, the user that is sudo'ed (superuser or another user, as specified by the security policy) needs an alias ll='ls -al' in his profile.为了使用 sudo 运行ll ,被 sudo 操作的用户(超级用户或其他用户,由安全策略指定)需要在他的配置文件中使用alias ll='ls -al'

Note that even if defined, you may not be allowed to execute it by the security policy.请注意,即使已定义,安全策略也可能不允许您执行它。 To find out which commands you may execute type sudo -l要找出可以执行的命令,请键入sudo -l

For some reason, alias was not working on my system, when I used with double quote (") or single quote (') . Once I removed all quotes , then it works with below command .出于某种原因,当我使用双引号 (")单引号 (')时,别名在我的系统上不起作用。一旦我删除了所有引号,它就可以使用以下命令

1: First, create an alias with alias ll=ls -als (without double/single quotes) 1:首先,用alias ll=ls -als创建一个别名(不带双引号/单引号)

2: Now run this command ll and it will list all files & folders. 2:现在运行此命令ll它将列出所有文件和文件夹。

在此处输入图片说明

alias ll='ls -al' would work temporarily in my case. alias ll='ls -al'在我的情况下会暂时起作用。 What I did is:我所做的是:

  1. Switched to root user切换到root用户
  2. echo "alias ll='ls -ahl'" > /etc/profile.d/ll.sh

It works smoothly :)它工作顺利:)

Check if the alias exists in ~/.bashrc which should be something like检查别名是否存在于 ~/.bashrc 中,它应该类似于

alias ll = ls -al

sometimes after a bunch of changes (in my case installing python3.6 and it's libraries, etc) the bashrc file wasn't sourced to pick up the changes to it so just source the bashrc file using the command有时经过一系列更改(在我的情况下安装 python3.6 和它的库等)后,bashrc 文件没有被获取来获取对它的更改,因此只需使用命令获取 bashrc 文件

source ~/.bashrc

Just doing this worked like a charm.只是这样做就像一个魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM