Study Notes (11)--linux Shell Basics

Source: Internet
Author: User

1. Shell Features:

To view the command history using the historical command:

[Email protected] ~]# history

the user's history record is located in the user's home directory . Bash_history File:

[Email protected] ~]# vim ~/.bash_history

Quick Actions related to history:

[[email protected] ~]#!! Previous Command

[[email protected] ~]#!$// last parameter of previous command

[[email protected] ~]#!n// execute nth record in history

[[email protected] ~]#! character // executes the most recent command beginning with the specified character in history

Wildcard: * match 0 or more characters, ? matches one character.

Job Control: Ctrl + Z put the process into the background, jobs View All the background process, FG%n(number) put the background process number n process back to the foreground, BG%n will the process with the foreground process number n is put in the background, and kill%n kills the process with the background process number N, & puts the process into the background after the command is executed:

[Email protected] ~]# sleep &

2. variables:

System variables are uppercase.

env allows you to list all environment variables for the current user and user-defined global variables:

[[Email protected] ~]# env

The Set command can list all variables, including all the variables listed in env and the custom local variables of the current shell ( You can declare global variablesusing the Export command: Export myvar= "Test" , which is not declared with the Export command, is the local variable myvar= "test" of the current Shell):

[[Email protected] ~]# set

if the current shell defines a global variable , export myvar= "test", and now wants to cancel the global variable, use the unset command:

[Email protected] ~]# unset myvar

the Export command without any parameters indicates that all environment variables and user-defined variables are declared:

[Email protected] ~]# export

3. system environment variables and personal environment variable profiles:

/etc/profile :environment variables such as PATH USER LOGNAME MAIL INPUTRC HOSTNAME histsize umask are set in this configuration file.

/ETC/BASHRC : environment variables such as $PS 1 umask are set in this configuration file.

~/.bash_profile : User-owned environment variables are set in this configuration file.

~/.BASHRC : User-owned environment variables are set in this configuration file.

simply, profile and BASHRC The links and differences are as follows :

(1) when the user logs on,the profile configuration files (including /etc/profile and ~/.bash_profile) are executed (source/ Etc/profile;source~/.bash_profile), and the profile configuration file execution causes the BASHRC configuration file (including /ETC/BASHRC and ~/.BASHRC) Execution (SOURCE/ETC/BASHRC;SOURCE~/.BASHRC).

(2) When a user opens a new shell in the login state ,the BASHRC profile executes, and the profile configuration file is not executed.

(3) If you want to modify an environment variable, it is best to modify it in the profile configuration file.

More differences can be found in the following articles:

Http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

4.shell Special symbols in:

* match symbols to match 0 or more arbitrary characters.

? match symbols, match 1 arbitrary characters

# comment symbol, followed by an entire line of the contents of the comment information

\ Caret, restores special characters to ordinary characters

| pipe Symbol

[] represents any one of the included characters:

[Email protected]~]# ls [ad]bc.log

Abc.log Dbc.log

5. common commands:

5.1 Cut :

Slice the display. -D Specifies the delimiter, used with-F, and - f Specifies which columns to display:

[Email protected] ~]# cut-d ': '-f 1,3/ETC/PASSWD

[Email protected] ~]# cut-d ': '-f 1-3/etc/passwd

-c Specifies the number of characters to display per line from the beginning:

[Email protected] ~]# cut-c 1,3/etc/passwd

[Email protected] ~]# cut-c 1-3/etc/passwd

5.2 Sort:

sort. -T specifies the delimiter, which is used with-K, and-K specifies which ones are sorted by separation. By default , the ASCII values are ordered from small to large, and the -n parameter can be sorted by numeric size,and the-r parameter is ordered from large to small:

[Email protected] ~]# sort-t ': '-K 3-nr/etc/passwd

5.3 Uniq:

Remove duplicate rows. the-c parameter counts the number of rows with the same content:

[email protected] ~]# ... | Uniq-c

5.4 Tee :

similar to output redirection, but one more function than output redirection, which can be displayed on standard output. Can be easily understood as cat + > .

[Email protected] ~]# CAT/ETC/PASSWD | Tee/tmp/passwd.bak

5.5 WC:

Number of rows, characters, and words of the statistics file:

[Email protected] ~]# WC/ETC/PASSWD

The-l parameter counts only the number of rows,the-w parameter only counts the number of words, and the -m parameter only counts the number of characters (which is part of the actual number of characters, because each line end has a $ sign end):

[Email protected] ~]# wc-l/etc/passwd

5.6 TR:

TR for the replacement, the actual work is not much use, you can refer to a previous blog, the address is as follows:

http://xitongjiagoushi.blog.51cto.com/9975742/1621301

5.7 Split:

Used to split a large file into multiple small files, creating a larger file manually:

[[email protected] ~]# for i in ' seq 1 10000 ' cat/etc/passwd >> bigfile.log done;

The-l parameter specifies how much the behavior of a sub-file is split, andthe -B parameter specifies how large the file size is for a sub-file to be split:

[Email protected] ~]# split-l Bigfile.log

[Email protected] ~]# split-b 1M bigfile.log


Resources:

Http://www.aminglinux.com/bbs/thread-7717-1-1.html


This article is from the "barrel of fake dog excrement" blog, please be sure to keep this source http://xitongjiagoushi.blog.51cto.com/9975742/1632780

Study Notes (11)--linux Shell Basics

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.