linux experiment 3

1. Practice shell command history, aliases, and special character usage

 

two,

1./etc/passwd

    passwd is a password file used to manage user passwords. Ordinary users can usually only modify their own password information.

2. /etc/shadow

    shadow is a shadowed password file that contains password information and optional age information for system accounts. Only administrators can view changes.

3. /etc/group

    The group file is the configuration file of the user group, including users and user groups, and can show which user group or which user groups the user belongs to, because a user can belong to one or more different user groups; the same user group users have similar characteristics.

4./etc/gshadow

    /etc/gshadow is the encrypted information file of /etc/group, such as user group (Group) management password is stored in this file. /etc/gshadow and /etc/group are two complementary files; for large servers, for many users and groups, it is extremely necessary to customize some permission models with complex relational structures and to set user group passwords.

 

, shell command application exercise

 (1)

1. /etc/passwd user account file

2. /etc/shadow optional encrypted password file

3. /etc/group A file related to user group management

4. /etc/gshadow contains shadowed group account information

(2)

The id command outputs the own id and group id of all users

id -u display user user id

id -u root Display the id of user root  

id -u wcc displays the uid of user wcc

 (3)

which can find files that can be executed directly

whereis can find source files and man files

These two are suitable for finding already installed commands

locate can find files of any type

find can find all but the slowest

(3)

 sudo apt install gimp: Install the software gimp.
which gimp: Query the location of gimp.
sudo apt remove gimp: uninstall gimp.
which gimp: query the location of gimp, there are no query results at this time.

(4)

ls -dl /root --time-style=long-iso | cut -d ' ' -f1,8

First display the defined time display method in the place where the space is used as the separator

(5)

Display time of file

Display file times in reverse order

show in order

(6)

ls /usr/share/man

Directories displayed under /usr/share/man

ls /usr/share/man | grep man[1-8]:

Search for man1~man8 based on the directory under /usr/share/man

ls /usr/share/man/man1:

Display the directories under /usr/share/man/man1

file /usr/share/man/man1/ls.1.gz 

mkdir ~/temp; cp /usr/share/man/man1/ls.1.gz ~/temp:

Create a temp folder in the root directory and copy ls.1.gz to temp

cd ~/temp; ls: Go to the temp directory and view all the file directories, at this time there is a suffix .gz

(7)

 ls –l /home | grep "^d" | wc –l:

Find files starting with d in the home directory and count the number of lines in the file

(8)

sudo adduser user7
ls /home | tee users | wc -l

Create a user user7 as an administrator, display the users in the home directory and count the number of rows

(2) Enter the following commands in turn to observe the running results. Combined with the help information viewed by man id, point out the function of each command

①id

 

Shid -u

 

③id -u root

 

④id -u hadoop

 

g or --group Display the ID of the group to which the user belongs. 
 -G or --groups Display the IDs of additional groups to which the user belongs. 
 -n or --name Display the name of the user, the group he belongs to, or the attached group. 
 -r or --real Display the actual ID. 
 -u or --user Display user ID. 
 -help Display help. 
 -version display version information

 (3)

①which python

 

whereis python

locate python

 

find /usr/bin -name python

 

(Explanation: which, whereis, locate, find all have the function of retrieval, combined with the execution results, find help information, and summarize the differences)

which to see the location of the executable

w her eis to view the location of the file

l ocate cooperates with the database to view the file location

find actually searches the hard disk to query the file name

 

②grep -n -E 'root|jsj|^user*' /etc/passwd (hint: extended regular expression)

 

grep  -n  -E  '[[:digit:]]'  /etc/passwd

 

 

grep  -n  -E  '[[:alpha:]]'  /etc/passwd

 

 

grep  -n  '[0-9]\{4,\}'  /etc/group

 

①cp/etc/apt/sources.listt1;  less t1

 

 

 

②sed -e "s/#.*//g"t1

 

 

 

 

③sed -e "s/#.*//g"t1| awk '{if (length != 0) print $0}'

 

 

④tail -5 /etc/passwd | awk -F: '{print $1}'

 

 

⑤tail -5 /etc/group | tee t2

awk 'BEGIN{print "file t2"} {print "line" NR ":" $0} END {print "over"}' t2

 

In linux, curl is a file transfer tool that uses URL rules to work under the command line. It is a very powerful http command line tool. It supports file uploading and downloading, and is a comprehensive transfer tool.

(1) Install curl

 

 

( 2) When using curl without any options, such as curl http://www.baidu.com  , a GET request will be sent by default to get the link content to the standard output. 

 

 

 

( 3) Only show the http header, not the file content, use the -I option

 

 

 

(4) To display the http header and file content at the same time, use the -i option.

 

 

 

( 5) Save the link to a file. Use the > symbol to redirect output into a local file. 

 

 

three,

Exercise 2

Step 1, use vi/vim/gedit or other editor to write the shell script ex2.sh, the content is as follows:

Try the four methods described in Chapter 4 to run the script.

If it prompts "the file major_code.txt cannot be found", please copy the major_code.txt in the public mail experiment folder to the directory where ex1.sh is located, and execute it again.

Note: the file major_code.txt, please do not make any changes, including the format.

Combined with the running results, analyze the script code, and summarize the following contents in the experimental report:

② Write out the read command option -n11 function in line3

-n 1 1 means the input ends after 11 characters are entered

② Write the function of line14

   Line14:grep $code $filename >t1 && read x major < t1

   Function: search code and filename redirect to t 1 , then output from t 1 to major

 

Summary: The content of this experiment is large, and there are many programs that need to be run, and more experiments are needed.

Guess you like

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