How to create a Linux command shortcuts or custom commands __linux

Source: Internet
Author: User
Tags linux shell commands

For a friend who often uses Linux, it's annoying to have to type in a lot of commands every time you want to input a large number of times, and often to enter them more than once, for each repeat input or "↑" to select historical input, and today we'll learn how to create shortcuts to Linux shell commands.

1. Linux shell command alias (alias)
Linux shell aliases are a useful thing, especially when commands are particularly long and can significantly improve efficiency (reduce the time to enter characters and reduce the probability of errors).

How to create a shell alias, we are using the Shell alias command: Alias
a). See which alias commands are in the system [Test @tset Test] #alias to display the alias commands in the current system
Alias Ll= ' Ls-l '
Alias Vi= ' Vim '
B. How to create a shell command alias is also using [Test @tset test] #alias alias_name= ' command '
C. How do I remove an alias command that has been created? Use the Unalias command [Test @test test] #unalias alias_name to remove the alias command for Alias_name

However, the alias command set in this way is valid only for the current logon environment. After exiting, login is invalid, how to make the alias command always valid, that is, modify the RC configuration file, the process of setting up the alias to initialize the user's script after the system started, users only need to modify the ~/.BASHRC file , add the alias command you want to set, for example
1 #. BASHRC
2
3 alias ll= ' Ls-l '
5 alias vi= ' Vim '
6 # Source Global Definitions
7 if [-F/ETC/BASHRC]; Then
8. /etc/bashrc
9 fi
After you modify this file, we usually have to exit the name before it takes effect, or you can load the configuration directly into the current environment with the source command [Test @test test] #source ~/.BASHRC
BASHRC can refer to Linux profile, Bash_profile, BASHRC file description

2. Create Batch command file (not recommended)
The user can simply save the Linux commands that are often used in a shell file and add the shell file to any path in the environment variable path so that the shell commands contained in this shell file can be executed directly by executing the shell file.

You can also create your own custom bin directory, which contains some of your own custom command files, and then add this bin directory to the PATH environment variable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.