In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use and create permanent aliases for Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Entering text and memorizing commands is one of the disadvantages of Linux command line enthusiasts. If you need to enter and remember equally long commands, this may reduce the efficiency of the terminal.
What if you could replace long commands with your own short name, or group multiple commands? Yes, alias is a way to help you use the command line effectively.
What does an alias (alias) mean in Linux?
An alias is an alternative name for another command or set of commands. It helps to create shortcut strings for commands that you enter for a long time or need to remember.
For example, if you want to synchronize the local directory with the remote directory, you can use the following command.
$rsync-a username@host:
But if you perform directory synchronization frequently, you may get tired of typing such a long command (unless you are using shell with automatic prompts). Therefore, to simplify regular synchronization tasks, you can create an alias for the rsync command.
$alias remote= "rsync-a user@host:"
The next time you want to transfer and synchronize local content to a remote system, you can type "remote" in your terminal. According to availability, there are two types of aliases: temporary aliases and permanent aliases. Temporary aliases are available only for the current terminal session. Once you close the terminal, you can no longer use custom aliases. Conversely, if you create a permanent alias in Linux, you can use it immediately in a new session, even after a reboot. How to create and use aliases under Linux? The syntax format for customizing aliases using the alias command is:
Alias new_name='value' for example, if you like to use the exa utility to list files, but still want to use the ls command, you can use "lsa" as the "ls" alias and use the ls command to print the exa output.
Linuxmi@linuxmi:~/www.linuxmi.com$ alias ls='exa-lh' linuxmi@linuxmi:~/www.linuxmi.com$ ls
Once you have created many aliases, you can also simply run the alias command to check or list it:
Linuxmi@linuxmi:~/www.linuxmi.com$ alias
Later, if you want to delete or unset any aliases, you can use the unalias command and pass the alias as a parameter.
Linuxmi@linuxmi:~/www.linuxmi.com$ unalias ls
You can also delete all aliases using the-an option of the unalias command.
How does linuxmi@linuxmi:~/www.linuxmi.com$ unalias-a create a permanent alias in Linux?
Do you still want to use aliases after closing the terminal and rebooting to the system? If so, you need to create a permanent alias. To do this, you need to put your alias in the ~ / .bashrc file by opening the alias in the editor or running the following command:
Linuxmi@linuxmi:~/www.linuxmi.com$ echo "alias up='sudo apt update & & sudo apt upgrade'" > > ~ / .bashrc linuxmi@linuxmi:~/www.linuxmi.com$ source ~ / .bashrc
If you are not using bash shell, you may need to add aliases to the appropriate shell configuration files, such as ~ / .zshrc for ZSH and ~ / .config / fish/config.fish for Fish shell.
Store aliases in a separate file
If you use a large number of aliases, it is best to prepare a separate file for it. You can create a bash_aliases dot file in the home directory and put all aliases here.
Linuxmi@linuxmi:~/www.linuxmi.com$ touch / .bash_aliases
# add an alias to the above file
After adding the alias to the "bash_aliases" file, you also need to add the following code to the ~ / .bashrc file.
If [- e ~ / .bash_aliases]; then source ~ / .bash_aliases fi "how to use and create permanent aliases for Linux" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.