[Shell] basic Shell functions: Historical commands & alias, basic shell functions

Source: Internet
Author: User

[Shell] basic Shell functions: Historical commands & aliases, and basic shell functions

Bytes --------------------------------------------------------------------------------------------------------

I. History commands

  History# View historical commands

 

  History-c# Clear history commands

 

  History-w# Directly write the history commands in the cache into the history command to save the file ~ /. Bash_history

 

  Vim/etc/profile# The default history command saves 1000 records. You can modify the HISTSIZE to save the number of records (unlimited). The command is saved in ~ /. Bash_history File

 

Call Of History commands:

1. Call up and down arrows

2 .! N # Run the command whose line number is n. The command displayed in history displays the corresponding line number before it.

3 .! His # execute the last command starting with his

 

Command and file completion: Tab

-------------------------------- @ Blackeye poet <www. chenwei. ws> ----------------------------------

Ii. aliases and shortcut keys

  Alias vi = "vim"# Define an alias to take effect temporarily

  Alias# View all aliases

 

Command Execution sequence:

First, use the absolute or relative path to execute the command.

Alias for second-order execution

Third, execute Bash Internal commands.

Fourth, run the first command in the search order defined by the $ PATH environment variable; echo $ PATH; you can see the PATH of a series of commands. The system command does not use the PATH, this is because the environment variable is set and is automatically searched.

 

Permanent save alias:

Edit. BashrcFile to write alias vi = 'vim.

Vim/root/. bashrc

Vim/home/. bashrc

 

Delete alias:

  Unalias vi# Unalias alias

 

Common Bash shortcut keys:

  Ctrl + cTermination command

  Ctrl + lClear Screen

  Ctrl + uCommand before deleting or cutting the cursor

Ctrl + k delete or cut the content after the cursor

  Ctrl + yPaste the content cut by ctrl + u or ctrl + k

Ctrl + r search in the History command. After pressing ctrl + r, the search page appears. You only need to enter the search content and search from the history command.

  Ctrl + dExit the current terminal (equivalent to exit)

Bytes ------------------------------------------------------------------------------------------------------


In linux, what is the path of the Shell history Command record file?

Bash shell in "~ /. Bash_history "(" ~ /"Indicates the user directory.) The file contains 500 used commands, which makes it easy to enter the used long commands. Each user with an account in the system has a ". bash_history" file in his directory.

Bash shell should save a small number of commands and delete these historical commands every time the user logs out.
Step 1:
The "HISTFILESIZE" and "HISTSIZE" lines in the "/etc/profile" file determine that all users can retain
Number of old commands saved. We strongly recommend that you set the values of "HISTFILESIZE" and "HISTSIZE" in the "/etc/profile" file to a smaller number, for example
30. Edit the profile file (vi/etc/profile) and change the following line:
HISTFILESIZE = 30
HISTSIZE = 30
This means that each user's ". bash_history" file can only save 30 old commands.
Step 2:
In the "/etc/skel/. bash_logout" file, add the following line "rm-f $ HOME/. bash_history ". In this way, the ". bash_history" file will be deleted every time you log out.

Role of shell in the operating system (details)

A main function of shell is to explain the commands entered from the command line in interactive mode. Shell parses the command line and splits it into words (also called tokens). Words are separated by spaces. spaces are composed of tabs, space keys, or line breaks. If a word contains special metacharacters, shell replaces it. Shell processes file I/O and background processes. After the command line is processed, shell searches for the command and starts to run it.
Another important function of shell is to define the user environment, which is usually completed in the shell initialization file. There are many definitions in the initialization file, including setting terminal keys and window properties, setting variables used to define search paths, permissions, prompts, and terminal types, and setting variables required by specific applications, such as Windows, word processing programs, and programming language libraries. Korn/Bash shell and C/TC shell also provide more customization functions: Adding history, alias, setting built-in variables to prevent users from damaging files or accidentally exiting, and notifying users of job completion.
Shell can also be used as an explanatory programming language. A shell program (also called a shell script) is composed of a column of commands in the file. The shell program is generated in the editor (the script can also be directly input on the command line ). They are composed of UNIX commands, with some basic program structures inserted between commands, such as variable assignment, conditional testing, and loops. Shell scripts do not need to be compiled. Shell will explain the script line by line, it seems that he entered the same from the keyboard. Shell is responsible for interpreting commands. Therefore, you need to know which commands are available. Some useful commands are listed in Appendix.
1.3.2 shell responsibilities
Shell ensures that the command entered after the command prompt is correctly executed. Its responsibilities include:
(1) read the input and parse the command line
(2) Replace special characters, such as wildcards and historical command characters
(3) set MPs queues, redirection, and background processing.
(4) processing signals
(5) settings for Program Execution

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.