Are the command options and parameters too complicated to remember? Use alias to define aliases for commands

I posted treea replacement before and it was super long. A super handsome guy told me to just aliasset an alias and I wouldn’t have to hand in my homework!

What's the first aliasthing?

aliasThe command is used to set the alias of the command, or it can be a command with option parameters. Using it, we don’t have to remember too many complicated option parameters, just set them as aliases!

If only entered alias, all current alias settings will be listed.

grammar:alias [别名]=[指令名称]

The theory exists and practice begins!

first,

Prepare the command to define the alias. Let’s take this treeas an example. See here for details.

alias treee="find . -print | sed -e 's;[^/]*/;|**;g;s;**|; |;g'"

To be careful of:

  • aliasThe effect is only applicable to the login operation. If you want to automatically set the alias every time you log in, you can set the alias of the command in /etc/profileor your own .~/.bashrc
  • There cannot be spaces before and after the equal sign (=), otherwise a syntax error will occur.
  • If there are spaces or tabs in the value, the value must be enclosed in quotation marks (single or double quotation marks are acceptable).

Enter this line and you will find that
Delightful for the eyes!
it is cool!

But now this is only temporary, like a piece of loose sand that will be scattered when the wind blows.

If the system is restarted, the alias we just set will become invalid!

So in order to make it easier to use and make it permanently valid, we need to write it to .bashrca file.

Then always and forever !

Small tips

  1. Don’t set too many settings and you’ll cry if you forget them. However, you can also view all set aliasesalias by directly entering the command without adding any options or parameters ;

    $ alias 
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='grep --color=auto'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias perlll='eval `perl -Mlocal::lib`'
    alias treee='find . -print | sed -e '\''s;[^/]*/;|;g;s;|; |;g'\'''
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    
  2. If you just want to check whether a single command has an alias set , use aliasthe command plus parameters;

    $ alias ls
    alias ls='ls --color=auto'
    
  3. How to delete an alias ? You can use unaliascommands;

    我不想演示这个嘿嘿嘿
    
  4. If you want to delete all aliases , just use unaliasthe command -aoptions directly, use it with caution!

    我很谨慎,所以我不演示!
    
  5. How to execute the command itself instead of the alias?

    If the defined alias happens to have the same name as a certain command, it will be a disaster because the alias will always be executed in the shell. So, what should you do if you want to execute the actual command instead of the alias?

    1. Use the absolute path of the command;
    2. Switch to the directory where the command is located and execute ./command;
    3. Use a backslash (\) before the command.

Wish me to get rid of vegetables soon!

Guess you like

Origin blog.csdn.net/weixin_43843918/article/details/124614867