Get the App
SLTechnology News&Howtos  ›  Servers  › 

Unix shell programming Notes Series (1)

Shulou Source: shulou.com Published: 2022-06-02 04:39:46 10月03日 Update

I. Review of Basic Orders

date //Display date and time

who //View all users logged in to the system

echo //Display input

file manipulation class

ls //List files

cat //Show file contents

wc //Count the number of words in the file

cp //copy files

mv //file renaming

rm //Delete files

directory operation class

pwd //Display current working directory

cd //Change current working directory

mkdir //Create directory

ln //link file

ln -s source file destination file//links source file to destination file

rmdir //delete directory

character matching

* //matches 0 or more characters

? //matches any character

[abc]//matches a single a or b or c

[0-9]//Matches one character from 0 to 9, the first character in the specified range must have a sequence number less than that of the next character

Examples:

[a-np-z]* //matches a filename starting with any letter from a-z except o

! //not

Examples:

[! a-z] //matches any character except lowercase letters a through z

*[! o] //Matches any filename that does not end in lowercase o

ls [a-z]*[0-9] //Lists file names that begin with a lowercase letter and end with a number

Standard input, output

For example, the who command writes a list of users logged into the system to standard output devices.

Input and output redirection

> //Output redirection, overwrite existing content

>> //Add output redirection, do not overwrite existing content

cat(catenate) //When followed by multiple files, multiple files can be concatenated

For example:

cat a b >> c //appends the contents of files a and b to file c

> file //Create an empty file named file with a length of 0 characters

wc -l a //Count the number of rows in a file

pipeline

| //pipe character

who |wc -l //Feedback the output of the who command to wc -l as input

filter

Any program that accepts input from a standard input, processes the input, and writes the result to a standard output, such as sort, wc, but not ls;

standard error

2> //standard error redirection

; //Separate commands, such as date;pwd

& //Used after commands to indicate background execution

ps //Displays information about the processes the system is running

2 What is Shell?

init->getty->login->sh

If you want to execute a particular program, the shell searches disk and finds the specified program. When it finds it, the shell requests that the program be initialized, and then the shell goes to sleep until the program finishes executing.

program name parameter table

Shell functions:

Implementation procedures;

Interpreting programming languages;

Environmental control;

pipeline connection;

I/O redirection;

Variable and file name substitution;

Shell uses specific characters to determine the starting and ending positions of program names and parameter lists, including space characters, tabs, and line terminators (collectively referred to as white space characters);

shell automatically ignores white space characters;

Tags: File character program input output standard content command directory letter file name lowercase list pipe system location parameter parameter table multiple beginning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB vpn Microsoft Xiaomi Redmi