linux experiment report 3

1. Purpose of the experiment
1. Practice and master the usage of special symbols such as wildcards, pipelines, and redirection in the
shell 2. Practice the usage of regular expressions in the shell
3. Experience and learn more common linux command tools, especially and pipelines
4. Master the basic usage of common variables in the shell
5. Master the method of establishing and executing shell script programs
2. Experiment preparation
Combined with chapter 4 courseware, study/review chapter 4 textbook section 4.1~ Section 4.5, including:
(1) Method of creating and executing shell scripts
(2) Usage of special characters in shell
3. Experiment content
1. Practice command history, aliases, and usage of special characters in shell (Chapter 4, Section 4.2 ~ Section 4.5 )

1) Show history commands

The syntax format is history[opyion][arg...]

①If there is no parameter, the history command list will be displayed

②If a positive integer m is given later, the last m lines are displayed

2) Define an alias

Syntax format: alias[name[value]]...

3) shell special characters

1.3.1 Quotes

There are three types of quotation marks: single quotation marks, double quotation marks and back quotation marks

① The characters in the backticks will be treated as shell commands and will be replaced.
② The characters in the single quotation marks will be treated as ordinary characters
. (!) are treated as ordinary characters

 

1.3.2 Input/Output Redirector

Input redirection:

Output redirection:

2. Practice the usage of regular expressions in the shell

1) Briefly describe the purpose of the following documents

① /etc/passwd: user account information

② /etc/shadow: secure user account information

③ /etc/group: group account information

④ /etc/gshadow: Security group account information

2) Point out the function of each command

① id prints the real and effective user and group ID

② id -u prints only valid user IDs

③ id -u root only prints the ID of the root user

④ id -u wt prints the ID of the wt user

 3) Observe the execution result of the following command to understand its function

2.3.1

which View the location of the executable file 
whereis View the location of the file 
locate Cooperate with the database to view the file location 
find Actual search hard disk query file name 

2.3.2

grep -n -E 'root|jsj|^user*' /etc/passwd Display the records starting with root, jsj, user in the directory
grep -n -E ' [[:digit:]] ' /etc/passwd Display the directory The next numeric character record
grep -n -E ' [[:alpha:]] ' /etc/passwd Display the text character record in the directory
grep -n '[0-9]\{4,\}' /etc/group in the user Find group information records whose GID is 4 digits or more in the group file

2.2.3

gimp: graphics processing tool under Linux

2.3.4

2.3.5

ls -l --time-style=long-iso Display detailed information in the current directory in detailed time format
ls -l --time-style=long-iso -t Sort by detailed time from first to last
ls -l --time -style=long-iso -t -r Sort by detailed time last to first

2.3.6

ls /usr/share/man List information in this directory
ls /usr/share/man | grep man[1-8] List information on man1-man8 in this directory
ls /usr/share/man/man1 List this Information
in the directory file /usr/share/man/man1/ls.1.gz List information in the directory
mkdir ~/temp; cp /usr/share/man/man1/ls.1.gz ~/temp in the current directory Create a directory and copy the compressed file to the past
cd ~/temp; ls enter the directory
sudo gzip -d ls.1.gz; ls decompress the file

2.3.7

Count the number of lines starting with d in the /home directory

2.3.8

sudo adduser user7 Create a new user
ls /home | tee users | wc -l count the number of users

3 Writing and executing shell scripts

1) Write and execute the script ex1.sh

Method 1: bash < script name

 

Way 2: bash filename [parameter]

 

Method 3: filename

Way 4: .filename

2) Write and execute the script ex2.sh

Method 1: bash < script name

 

3) Summarize the following in the script code

① Function of read command option -n11 in Line3 of ex2.sh: read 11 characters from the input, and automatically end the input after reading.

② The function of Line14 of ex2.sh: search the corresponding line in filename("major_code.txt") according to the professional code obtained above and redirect the result to him

middle. Then redirect the content in t1 to the major as input.

4. Summary

  Through this experiment, I have a new understanding of shell programming in Linux. I decided to learn more about the linux system in the future.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325218466&siteId=291194637