What command is linux ll?

Linux ll is not a command provided by the linux system. It is usually the command alias we set. Generally, the ls -l command is set to ll.

For example, open a terminal window and type the following command:

➜  ~ alias | grep "ll="

ggpull='git pull origin "$(git_current_branch)"'
gstall='git stash --all'
ll='ls -lh'

###
# Since I am using the zsh shell environment
# (use: echo $SHELL), many aliases are configured 
# by default, so I use grep to filter it.
###

You will find my linux ll alias command is: ls -lh

So how to set the command alias?

There are two ways:

  • One is to use the alias command;
  • One is to modify the shell configuration file;

The first method can only take effect in the current terminal window. It is invalid in other windows and is automatically lost when closed.

The second method can be permanent and effective in the terminal window.

Next, let’s introduce how to use the above two methods to set aliases?

For example, we want to set up such an alias:

dw='cd ~/Downloads/'

use the alias command

We open a new terminal window and type in the alias dw, the following information will be displayed:

➜  ~ dw
zsh: command not found: dw

This is correct. Because the system does not provide this command and has not configured this alias.

Below we use alias to configure aliases and cancel aliases.

Syntax:

#set 
alias set aliasName=‘commands’

#cancel
unalias aliasName

Examples:

First, open a terminal and type the following commands:

➜  ~ alias set dw='cd ~/Downloads/'

Then execute the alias and grep commands to see if they are successful:

➜  ~ alias | grep "dw"

dw='cd ~/Downloads/'
gdw='git diff --word-diff'

Finally, we type dw in the terminal to test the effect.

➜  ~ dw

This method only takes effect on the current terminal window. If you want to be effective permanently, you need to use the configuration file method.

Modify the shell configuration file

By default, all shell environments will have a “.****rc” file, which can store some personal configuration information, including aliases of course.

As mentioned above, I use the zsh shell environment. So, here directly add the dw alias in the zsh configuration file.

The configuration file of the zsh shell environment is .zshrc, which is a hidden file in the current user’s root directory.

Similarly, we first open a new terminal window, use the vim command to directly open the .zshrc file, and then add the following statement at the end of the file:

alias dw='cd ~/Downloads/'

Then, we save the .zshrc file and exit.

Finally, execute the following command to make the alias effective immediately;

➜ ~ source .zshrc

Let’s test it, type in the current terminal:

➜ ~ dw

ok, you will find that you have jumped to the download directory. Of course, it is also possible to open a new terminal window, and the test is not done here.

Ours is a directly modified .zshrc root configuration file.

Of course, you can also follow the rules of zsh. Its aliases are all configured in the .oh-my-zsh/lib/ directory. There are a wealth of alias configurations. You can learn by yourself.

Add a Comment

Your email address will not be published.