In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to define your own command in linux, the article is very detailed, has a certain reference value, interested friends must read!
Learn how to create aliases: You can package commands that are too long or hard to remember into commands you construct yourself.
Command alias In the Linux shell, Alias refers to combining multiple commands that are too long or too difficult to remember into a command that the user constructs himself.
Command aliases can be created with the alias command. You create a command alias by following alias with the name of the alias you want to create, an equal sign (=), and the command you want to execute using that alias. For example, the ls command does not color the output by default, making it impossible for users to distinguish directories, files, and connections at a glance. To do this, you can create a command alias that colors the output content when outputting directory content:
alias lc='ls --color=auto'
lc is a custom command alias that stands for "list with color." When creating command aliases, you need to make sure that the alias used already has a corresponding command, and if so, the original command will be overwritten. Note that when defining command aliases,= ends with no spaces. When lc is run, the ls --color command is executed.
After that, when executing lc to list the contents of the directory, it will output the contents with coloring.
You may find that when you execute ls, you are outputting colored content. That's because most Linux distributions already use ls as a command alias with coloring.
Command aliases that can be used directly
In fact, executing the alias command without any content shows you all the command aliases that are currently set. Different distributions contain different command aliases, but the following command aliases are common:
alias ls='ls --color= auto': This command alias was mentioned earlier. -- The color=auto parameter causes the ls command to shade when displaying content in terminals via standard output, but not otherwise (for example, when exporting to files via pipes). -- Color can also be set to always or never.
alias cp='cp -i': -i parameter represents "
interactive
"。When copying files using cp, you may inadvertently overwrite existing files. After using the-i parameter, cp asks the user before doing something critical.
alias free='free -m': Adding the-m argument to the free command allows the output memory information to be read and calculated in MiB units instead of the default Byte units.
The command aliases that come with the distribution you are using may differ somewhat from the above. But you can always use the most basic form of a command (not an alias) by prefixing it with the\modifier. For example:
\free
It is free, not free -m. Also:
\ls
The implementation is ls without the--color=auto parameter.
If you want to persist command aliases, you can modify them in the.bashrc file, which comes from our/etc/skel directory.
Correct errors using command aliases
The designers of various distributions try to set command aliases that users may need. But habits vary from user to user, some users may have just migrated to Linux from other operating systems, and the basic commands for different operating systems vary from shell to shell. Therefore, for users who have just migrated from Windows/MS-DOS to Linux systems, you may wish to use
alias dir='ls'
This command alias lists directory contents.
Similarly,
alias copy='cp'alias move='mv'
It can also be used when you are not fully familiar with Linux.
There is also a case where fault tolerance is made in situations where typing errors often occur. For example, for me, the word Administration is difficult to type quickly and correctly, so many users will set aliases like this:
alias sl='ls'
and
alias gerp='echo "You did it *again*! "; grep'
The grep command is basically used to look up strings in files, and once you're familiar with it, it must be one of the most common commands, so it's maddening to have to retype a command because of a typo.
In the gerp example above, there is not just one command, but two. *** echo "You did it *again*! "A message alerting the user to a spelling error is printed, then a semicolon (;) separates the two commands, followed by grep, the correct command.
Using gerp on my system to search for lines in/etc/skel/.bashrc that contain the word "alias" would output the following:
$ gerp -R alias /etc/skel/.bashrcYou did it *again*! alias ls='ls --color=auto' alias grep='grep --colour=auto' alias egrep='egrep --colour=auto' alias fgrep='fgrep --colour=auto' alias cp="cp -i"alias df='df -h'alias free='free -m'alias np='nano -w PKGBUILD' alias more=less shopt -s expand_aliases
Executing multiple commands in a fixed order within a command alias, or even further, concatenating multiple commands so that subsequent commands can use the results of previous commands. This approach is very close to bash scripting. This article is nearing its end and we will cover it in detail in the next article.
If you want to delete an alias temporarily set in the terminal, you can use the unalias command.
unalias gerp The above is "How to define your own commands in linux" All the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
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.