Shell Programming (ii) basic knowledge of--shell and common commands

Source: Internet
Author: User
Tags pear

The basics of the shell

First, Bash has the following features:

1. Record command history

2. Command and file name completion

3. Aliases

Alias rm= ' Rm-i '

4. Wildcard characters

* 0 or more characters

?? match one character

5 Input and output redirection

Input redirection <</p>

output redirection;?

6. Pipe symbol |

second, the variable

environment variable Path: It is a variable of the shell preset

Echo $PATH?

Echo $PWD

Echo $HOME

system-Preset variables : Use the ENV command to list the environment variables for the system presets?, but the user who logged on has different values for these environment variables

PATH: Determines to which directories the shell looks for commands or programs

Home Current User Home directory

Histsize history Data

LogName Current login Name

Name of the hostname host

PWD current directory?

The ENV command displays only the environment variables, and there are a number of system preset variables that can be displayed using the SET command.

The SET command can display not only the system preset variables, but also the user-defined variables

User-defined variables

Myname= ' Sassy Xu '? A single quotation mark is required when the variable content has a special character such as space

Myname= "Sassy '"? Double quotation marks are required when the contents of the variable itself have single quotes

Myname= ' pwd '? Variable content needs to run the result with other commands, use the back quotation marks

Myname= "$LOGNAME" Sassy variable contents accumulate the contents of other variables, need double quotation marks

configuration files for system environment variables and personal environment variables ?

/etc/profile: Files that store system environment variables, such as path,logname,hostname, etc.

/ETC/BASHRC: System files, pre-ps1,root identity login into the Linux system PS1 is [[email protected] ~]#?

Several hidden files under the user directory

. bash_profile

. BASHRC

. bash_history

. bash_logout

iii. common commands?

Sort command for sorting?

(1) Sort compares each line of a file as a unit, comparing the first character backwards, followed by the ASCII code, and finally outputting them in ascending order.

Cat Seq.txt

Banana

Apple

Pear

Orange

Sort Seq.txt?

Apple

Banana

Orange

Pear

? (2) sort-u Remove duplicates

(3) Sort-r in reverse order

Cat Number.txt

1

3

5

2

4

Sort-r Number.txt

5

4

3

2

1

(4) The SORT-N option is sorted by numerical size

(5)?? The-t option for sort and the-K option

If there is a file content like this, the cat Facebook.txt

banana:30:5.5

? apple:10:2.5

? pear:90:2.3

? orange:20:3.4?

The first column represents the fruit type, the second column indicates the fruit quantity, the third column represents the unit price

Sort by the number of fruits, that is, the second column,

SORT-T:-K 2? -N Facebook.txt

apple:10:2.5

? orange:20:3.4

? banana:30:5.5

? pear:90:2.3?

grep command?

Does grep work on lines of text?

Grep-n ' keyword ' filename filters out lines with keywords and loses travel numbers

GREP-VN ' keyword ' filename filters out lines without keywords and loses travel numbers

grep [0-9] text.txt filters out all rows that contain numbers

In regular expressions [0-9a-za-z] filters out numbers and uppercase and lowercase letters,

[^ character] denotes a character other than the characters in []?

^ Represents the beginning of the line, $ means the end of the line ^r h$

Grep-i ' keyword ' filename ignores case?

Grep-c ' keyword ' filename statistics find the number of keywords?

grep--color=auto will find the keywords plus color display?

Shell Programming (ii) basic knowledge of--shell and common commands

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.