Five weeks Third Lesson 8.1 Shell introduces 8.2 command History 8.3 command completion and alias 8.4 wildcard 8.

Source: Internet
Author: User
Tags aliases time and date

8.1 Shell Introduction
8.2 Command History
8.3 Command Completion and aliases
8.4 Wildcard Characters
8.5 input and output redirection

8.1 Shell Introduction

The shell is a command interpreter that provides interaction between the user and the machine
Support for specific grammars, such as logical judgments, loops (if for Whell)
Each user can have their own specific shell
CentOS7 default shell is bash (Bourne Agin Shell)
and zsh, Ksh and so on.

Yum List |grep zsh search for Yum for zsh

# yum list |grep ksh

8.2 Command History

Shell Attribute Properties


The commands we enter can be used to view the history commands with the UP ARROW keys, which are stored in the user's home directory
1. # Ls/root/.bash_history history commands are saved in the. bash_history file in the user's home directory

2. # History View how many commands are stored

History-c clears the command history inside the memory and does not delete the configuration file. Historical commands in Bash_history


The maximum storage for this file is 1000 commands.
1000 commands are determined by the system's own environment variables.
3. # echo $HISTSIZE environment variable histsize determines the number of saved history commands

The command we just knocked on is currently in memory and will not be saved in the history command file, but will not be saved in the history command file until you exit the terminal.

4. Where do I change the variable histsize? Change in/etc/profile


histsize=1000

5. # Source/etc/profile You need to run this command after changing the number to make the configuration file we changed take effect

6. # histtimeformat= "%y/%m/%d%h:%m:%s" definition format will record date and time
y--year m--month d--date h--hours m--minutes s--seconds

How to change the format of a command Oh ~ ~ ~
If you let the record time and date history command take effect need to put this command in the----# Vi/etc/profile and then------put the # histtimeformat= "%y/%m/%d%h:%m:%s" in histsize-----# SOU Rce/etc/profile---Re-open terminal--# echo $ histtimeformat---# History

Let the command history be saved permanently we can add a hidden permission to it
7. # chattr +a ~/.bash_history Permanent Save
Give. Bash_history plus a permission, cannot delete, can append

Commands that run in the current shell are saved to the. bash_history file only if the user exits the current shell normally.
Normal exit input exit or logout can exit gracefully if we shut down the server, our output history command is not saved.
8.#!! : Two in a row! Represents the execution of the previous command (the last command entered)

!n N Represents the number run nth command
     # !echo: !echo表示执行命令历史中最近一次以echo开头的命令(从下往上找)


8.3 Command Completion and aliases

Complement the whole

1. Tab key
Not only can complete the command can also complete the path (command at the beginning if more words to press twice,)
2.# Yum install-y bash-completion parameter completion requires installation Bash-completion

After the package has been installed, you will need to restart the computer parameters to fill the versatile can take effect

Reboot restart

Alias

1.alias give the order a name again.

Alias alias = ' original command ' change alias for command
# unalias 别名  取消自定义的别名


Alias Query alias Usage


2. Configure the name of the file where the alias is first in the user's home directory #. BASHRC There are some in/etc/profile.d/


Five weeks Third Lesson 8.1 Shell introduces 8.2 command History 8.3 command completion and alias 8.4 wildcard 8.

Related Article

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.