Shell Command Basic knowledge point

Source: Internet
Author: User

Command history

# Cat/root/.bash_history//place where historical commands are stored

# History//View the number of command histories

# echo $HISTSIZE//View the number of bars that can be saved

# Vim/etc/profile//Change the value of variable histsize "/histsize" to search

# Source/etc/profile//This will make the value we just modified take effect

# vim/etc/profile→ Add histtimeformat= "%y/%m/%d%h:%m:%s" in Histsize to change the format of the output history, for example: 923 2017/06/28 17:56:42 source/etc/profile include what time input can be displayed!!!

# chattr +a ~/.bash_history//Permanently Save the input history (a permission, only allowed to increment, not allowed to delete)

# !! Executes the previous command

#!761//Find command No. 761 command, in command history!

Command completion

Parameter completion, installation bash-completion

Customize the commands you use frequently to improve efficiency: for example:

# alias resnet= ' systemctl restart Network.service '//But this is only stored in memory, if we need long-term use, it will be written in the configuration file, home directory of #. Bash RC

Wildcard characters

# ls *. txt//View all files ending in. txt

# ls 1* //View all Files beginning with 1

# ls ?. TXT//one-character and. txt files

# ls ??. TXT//two characters and. txt files

# ls [0-3].txt//contains 0.txt 1.txt 2.txt 3.txt

# ls [123].txt//contains 1.txt 2.txt 3.txt

Input and output redirection

">"//redirect >> "//Append Content

# cat 12.txt > 22.txt//view 12.txt content and redirect to 22.txt

# cat 12.txt >> 22.txt//view 12.txt content and append (previous content not deleted) to 22.txt

"2>"//Error redirection "2>>"//Error Append redirect

A command that is often used when writing a shell script at a later time:

# ls [12].txt txzzz.txt (without this file) >1.txt 2>b.txt//Put the correct output, output to 1.txt, error output output to B.txt

Pipe symbol, Job control

Pipe break: The output of a command result is passed to the following command;

# cat 1.txt |wc-l; View 1.txt content and give it back to see How many lines of output ~

# cat 1.txt |grep ' AAA '//view 1.txt content and give back grep to find AAA

# Find./-type F | Wc-l//View how many files are in the current directory and then the statistics output

Case: If the IP address is now being configured, when you enter Vim, you find that you forgot the IP address, and then use "Ctrl + Z" to temporarily return to the command line,FG back to the task, perhaps sometimes, background tasks are more, you can use jobs to view and then restore a task using FG+ID , or put a task in the background to continue with BG+ID, One-time put a command in the background to execute, # sleep & , you can use jobs to see.

System built-in variables

# env//View System variables

# Set//View the system's own variables + user-set variables

Custom variables:

# Zhdy=winner//Set Custom variables

# Set | grep zhdy//querying Zhdy in custom variables

# unset Zhdy//Cancel a custom variable

# variable name rules: Letters, numbers underline, the first cannot be a number

# variable values have special symbols that need to be enclosed in single quotation marks.

# a= ' a$bc ' → # echo $a → # A$BC

# a=1;b=2 → #echo $a $b → # 12

# echo $SSH _tty//See which TTY you're under

#export Zhdy=linux//Create a Global environment variable,

environment variable configuration file

System-level environment variables ( never change unless special requirements):

/etc/profile user Environment variables, interaction , login only execution

/ETC/BASHRC user does not have to log on, execution shell is effective

User-level environment variables ( for current users only ):

~/.BASHRC//Customize some aliases alias

~/.bash_profile//Customize some variables. Example: histsize=2000

~/.bash_history//Custom history-related configuration

~/.bash_logout//Custom actions performed after exit

Profile: When the user logs in, it is used to

BASH: A system or user executes some shell

[root@zhdy-02 ~]# echo $PS 1//output to the left of a format

[\u@\h \w]\$

[[email protected] ~]# ps1= ' [\[email protected]\h \w]\$ '//change format to absolute path

[[Email protected] ~] #cd/etc/sysconfig/network-scripts/

[[email protected] /etc/sysconfig/network-scripts]#//has been shown as absolute path!!!

# ps1= ' \[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ ' //color format

Of course, this is only a temporary memory, if you want to permanently modify, be sure to enter # VIM/ETC/BASHRC to modify!


This article is from the "Old seven Linux Operations Management" blog, please be sure to keep this source http://asd9577.blog.51cto.com/4291946/1943326

Shell Command Basic knowledge point

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.