I posted tree
a replacement before and it was super long. A super handsome guy told me to just alias
set an alias and I wouldn’t have to hand in my homework!
What's the first alias
thing?
alias
The 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 tree
as an example. See here for details.
alias treee="find . -print | sed -e 's;[^/]*/;|**;g;s;**|; |;g'"
To be careful of:
alias
The 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/profile
or 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
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 .bashrc
a file.
Then always and forever !
Small tips
-
Don’t set too many settings and you’ll cry if you forget them. However, you can also view all set aliases
alias
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'
-
If you just want to check whether a single command has an alias set , use
alias
the command plus parameters;$ alias ls alias ls='ls --color=auto'
-
How to delete an alias ? You can use
unalias
commands;我不想演示这个嘿嘿嘿
-
If you want to delete all aliases , just use
unalias
the command-a
options directly, use it with caution!我很谨慎,所以我不演示!
-
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?
- Use the absolute path of the command;
- Switch to the directory where the command is located and execute ./command;
- Use a backslash (\) before the command.
Wish me to get rid of vegetables soon!