Iv. conclusion of the experiment
1. Practice command history, aliases, and special character usages in the shell (4th. 4.2, Section ~4.5)
2. Shell Command Application Exercise
(1) The use of the following documents is briefly reviewed through the Help information
①/ETC/PASSWD (Hint: View this file description description via man 5 passwd)
/ etc /passwd Store The password file, each user in the file has a corresponding record line, it records some basic properties of this user, including: login name, optional encrypted password, digital user ID , Numeric group ID , User name and Comment fields, user home directory, optional user command interpreter.
②/etc/shadow (Hint: View this file description description via Man 5 shadow)
/etc/Shadow isa shadow of the passWD file,/etc/shadow record lines in a file with/ etc /passwd one by one, but only system administrators can modify and view them.
③/etc/group (Hint: View this file description description via Man 5 group)
/etc/group store information about a local user group
④/etc/gshadow (Hint: View this file description description via man 5 Gshadow)
/etc/gshadow is /etc /group encrypted information files, such as user group management passwords, are stored in the file.
(2) Enter the following command to observe the results of the operation. Combined with the man ID to see the Help information, point out each command function
①id
②id-u
③id-u Root
④id-u Hadoop
-Gor--groupDisplays the group that the user belongs toID.
-Gor--groupsDisplays the additional groups that the user belongs toID.
-Nor--namedisplays the name of the user, the group to which it belongs, or the additional group.
-Ror--realShow the actualID.
-Uor--userShow UsersID.
-helpdisplays Help.
-versionDisplay version Information
ID Command can show real and valid usersID (UID)and GroupsID (GID). UIDis a single identity for a user. GroupID(GID) corresponds to multipleUID. IDcommand has been preinstalled in mostLinuxthe system. To use it, you only need to enter it in the consoleID. When we want to know a user'sUIDand theGIDwhenIDcommands are very useful. Some programs may requireUid/gidto run. IDmake it easier for us to find out the user'sUIDinGIDwithout having to/etc/groupsearch in the file.
(3) In the shell command terminal, enter the following command, observe the execution results, understand the specific functions of each command implementation
①which python
Whereis python
Locate Python
Find/usr/bin-name python
(Description: Which, Whereis, locate,find all have the function of retrieving, combine execution result, find help information, summarize its difference)
which to view the location of an executable file
W Her EIS to view the location of a file
L ocate to view file locations with a database
Find actual search hard disk query file name
②grep-n-E ' root|jsj|^user* '/etc/passwd (hint: extended regular expression)
Grep-n-E ' [[:d igit:]] '/etc/passwd
Grep-n-E ' [[: Alpha:] '/etc/passwd
Grep-n ' [0-9]\{4,\} '/etc/group (hint: Find the GID in the user group file is a 4-digit and above group information record)
(Description: A regular expression with option-e representing an extension;-e is a regular regular expression)
g Rep The command can search for text through regular expressions and print the line to which it matches; option -N to print line numbers,- E you can use more than one regular expression.
③sudo Apt-get Install GIMP
Which GIMP
sudo apt remove gimp
Which GIMP
sudo apt-get install gimp command to install GIMP
sudo apt remove gimp command to uninstall GIMP
which GIMP the location to view the file.
④ls-dl/root--time-style=long-iso
Ls-dl/root--time-style=long-iso | Cut-d '-f1,8
(Description: The option of the Cut command-D has spaces in the quotation marks; Hint: compare with previous line results)
option -D to customize the delimiter,-F displays the contents of the specified field, and the above command specifies the space as a delimiter, showing the contents of the 1th and 8th fields.
⑤ls-l--time-style=long-iso
Ls-l--time-style=long-iso-t
Ls-l--time-style=long-iso-t-R (Description: Execute in turn, compare to see, combine Help options)
⑥ls/usr/share/man
Ls/usr/share/man | grep Man[1-8]
Ls/usr/share/man/man1
File/usr/share/man/man1/ls.1.gz (combined with execution results, review2.8.1 section gzip command content)
the File command recognizes the type of files, and then creates a new directory , temp, with the ls . 1.gz Copy to t EMP Directory,the gzip command is to decompress.
Mkdir~/temp; Cp/usr/share/man/man1/ls.1.gz ~/temp
CD ~/temp; Ls
sudo gzip-d ls.1.gz; Ls
(Note: Execute sequentially, combined with the results of the instruction before and after, understand the command function; for the gzip command, refer to section 2.8.1 understanding)
⑦ls–l/home | grep "^d" | Wc–l
l s-l Find the file under the/home directory, GRE p "^ D " filter the file at the beginning of the line to D ,wc-l count rows
⑧sudo AddUser User7
Ls/home | Tee Users | WC-L (hint: Enter cat users to observe the contents of the file)
sudo AddUser command is used to add a new user
(4) write the corresponding shell command as required
① Search for files under directory/usr/include signal.h exists (hint: find command)
② finds the row containing the Bufsiz in all files in the/usr/include directory and displays the line number. Requirements: Only the found results are displayed on the screen and the error messages are filtered.
(Hint:① uses grep and wildcards *;② uses error message redirection and special device files/dev/null)
③ in the user name password file/etc/passwd The login shell to bash user information record, and display the line number
(Hint: use grep and $ in regular expressions)
④ intercepts the 1th column (group name) and 3rd column (group ID) from the/etc/group file and sorts it by the size of the group ID number from small to large. (Hint: Use cut, pipe line and sort command in combination)
(Commands to write out the functionality of the document, including commands and results, as they are submitted)
(5) Experience awk, sed usage: Execute commands sequentially to observe execution results
①CP/ETC/APT/SOURCES.LISTT1; Less T1
②sed-e "s/#.*//g" T1
③sed-e "S/#.*//g" t1| awk ' {if (length! = 0) Print $} '
④tail-5/etc/passwd | Awk-f: ' {print '} '
⑤tail-5/etc/group | Tee T2
awk ' begin{print ' file T2 '} {print ' line ' NR ': ' $} END {print ' over '} ' T2
(When submitting a document, review the network and summarize the following:
① file/etc/apt/sources.list Use, understand its content
/etc/apt/sources.list is the record used by the Package management tool apt
② command tool sed function, showing two or three self-attempted sed command exercises, and make necessary statement of specific functions
s Ed You can replace the characters with the practice of replacing love with hate
③ Command tool awk function, showing two or three of their own attempts to practice the awk command, and specific functions to make necessary statements
Row Matching statements a wk ' can only Use single quotation marks
each line is divided by a space or tab , the output text of 1, 4 items;
awk-f:-F equals built-in variable FS, specifies the split character, used in practice ' , ' split
(6) Check the network or Help to experience command curl and wget usage.
(When submitting a document, review the network and summarize the following:
② Command Tool curl function, display the exercises you try and make necessary statement instructions
in Linux, Curl is a file Transfer tool that works under the command line with the URL rule, and is a very powerful H-TTP command-line tool, It supports file upload and download, and is a comprehensive transfer tool.
(1) Installing Curl
(2) when using curl without any options , such as Curl http://www.baidu.com , the GET request is sent by default to get the link content to standard output.
(3) only HTTP headers are displayed, not file contents, use- I Options
(4) both HTTP headers and file contents are displayed, using the-I option.
(5) Save the link to a file. Use the > symbol to redirect the output to a local file.
② Command tool wget function, display the exercises you have tried, and make necessary statement instructions
wget is a tool for downloading files, which is used under the command line. wget The tool is fully functional, supports the breakpoint download function, and supports F TP and H TTP download mode, support proxy server and easy to set up.
(1) using wget to download a single file, the download process will show a progress bar, including (download complete percentage, the downloaded bytes, the current download speed, the remaining download time)
(2) use wget - o to download and save with a different file name. In practice, download a file and save it by name Download1
3. Write a shell script that is executed in 4 different ways (see Chapter 4th, Textbook/Courseware).
(1) Exercise 1
1th, using Vi/vim/gedit or another editor, write the shell script ex1.sh, which reads as follows:
The function of this script is to back up normal files that have been modified within the current directory for the last 1 days (that is, 24 hours). Use the backup system's current datetime as the file name and compress the archive. The error message is written to Error_info during the backup. Then view the backup document and the error message separately.
2nd, try the four ways that the 4th chapter describes, run the script, and understand the shell commands that are used synthetically in this example.
(2) Exercise 2
1th, using Vi/vim/gedit or another editor, write the shell script ex2.sh, which reads as follows:
Try the four ways introduced in chapter 4th to run the script.
If you are prompted to "Cannot find file Major_code.txt", copy the Major_code.txt from the public Email experiment folder to the directory where ex1.sh is located and execute it again.
Note: File Major_code.txt, please do not make any changes, including format.
Combined with the running results, analyze the script code and summarize the following in the lab report:
② write line3 the read command option-n11 function
- N 1 1 means enter 11 characters and end of input
② Write the LINE14 function
L ine 14:grep $code $filename > T1 && read x major < T1
function: Search for C ode and Filen ame redirect to T 1, then output from t1 to major
Feelings
In this experiment I practiced the special characters in the shell command, and I learned to use some command tools.
Experiment three shell commands (1)