Experiment three, Shell programming

Source: Internet
Author: User
Tags aliases alphabetic character

first, the contents 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 (see Experimental steps)

3. Write a shell script that executes in 4 different ways (see experimental steps)

4. Combine the individual learning progress bar to select new attempts and explorations in the Linux environment

Second, the experimental steps

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

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/shadow (Hint: View this file description description via Man 5 shadow)

③/etc/group (Hint: View this file description description via Man 5 group)

④/etc/gshadow (Hint: View this file description description via man 5 Gshadow)

1)/etc/passwd File description

A row of records in/etc/passwd corresponds to a user, and each row of records is separated by a colon (:) into 7 fields, with the following format and specific meanings:
  User name : password : user ID : group identification number : annotative description : home directory : login Shell

User name (login_name): is a string representing the user account.

Password (passwd): In some systems, the encrypted user password word is stored.

User identification Number (UID): is an integer that is used internally by the system to identify the user.

Group identification Number (GID): The field records the user group to which the user belongs. It corresponds to a record in the/etc/group file.

Annotative Description (Users): A field that records some personal information about a user, such as a user's real name, phone number, address, and so on.

Home directory (home_directory): The user's starting working directory, which is the directory where the user logs on to the system.

Login Shell: After a user logs in, to start a process that is responsible for passing the user's actions to the kernel, which is the command interpreter or a specific program, the Shell, that the user is running after logging on to the system.

2)/etc/shadow File description

The/etc/shadow file format is similar to the/etc/passwd file format and consists of several fields, separated by a ":" Between the fields.

The main meanings of the fields in the file are:

Login: Encrypted password: Last modified: Minimum time interval: Maximum time interval: Warning Time: Inactivity time: Expiry time: Flag

"Login Name" is a user account that matches the login name in the/etc/passwd file

The password field holds the encrypted user password Word:

Last modified time represents the number of days from the time the user last modified the password. The beginning of time may not be the same for different systems.

"Minimum time interval" refers to the minimum number of days required between changing the password two times.

Maximum time interval refers to the maximum number of days that a password remains valid.

The warning Time field represents the number of days from the beginning of the system warning user to the official expiration of the user's password.

"Inactivity Time" represents the maximum number of days that a user does not have a login activity but the account remains valid.

The "Expiration Time" field gives an absolute number of days, and if this field is used, the lifetime of the corresponding account is given. After expiry, the account is no longer a legitimate account, and can no longer be used to log on.

3)/etc/group

Both the/etc/group file and the/etc/passwd and/etc/shadow files have files related to the management of users and user groups by the system administrator. Linux/etc/group files are files that the system administrator manages for users and user groups, and all the information for the Linux user group is stored in the/etc/group file. A user group is a collection of users with a common feature. The user group profile mainly has/etc/group and/etc/gshadow, where/etc/gshadow is the/etc/group encrypted information file.

All the information for the user group is stored in the/etc/group file. The format of this file is separated by a colon (:) several fields, these fields are as follows:

Group Name: password: Group identification number: List of users in the group

Group Name:

The group name is the name of the user group, consisting of letters or numbers. As with logins in/etc/passwd, group names should not be duplicated.

Password:

The password field holds the password word after the user group is encrypted. The user groups in the General Linux system do not have a password, that is, the field is generally empty or *.

Group identification number:

The group identification number is similar to the user identification number and is an integer that is used internally by the system to identify the group. Alias Gid.

List of users in the group:

is a list of all users belonging to this group, separated by commas (,) between different users. This user group may be the user's primary group, or it may be an additional group.

4)/etc/gshadow

/etc/gshadow
/etc/gshadow is a/etc/group encrypted information file, such as user group management password is stored in this file.
/etc/gshadow and/etc/group are complementary two files; for large servers, for many users and groups, custom some relational structure more complex permissions model, set user group password is very necessary.

Group Name: Password: Group manager: List of users in the group
1) Group name: is the name of the user group, consisting of letters or numbers.
2) Password: User group password, this segment can be empty or!, if it is empty or has!, means no password
3) Group Manager: This field can also be empty, if there are multiple user group managers, with the number of split
4) List of users in the group: if there are multiple members, use, number segmentation;

(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 display the current user ID

②ID-U Display User ID

③id-u root displays the root ID

④id-u Kyo Displays the ID of the user Kyo

(3) In the shell command terminal, enter the following command, observe the execution results, understand the specific functions of each command
can be
①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 viewing the location of an executable file

Which is to find the executable file through the PATH environment variable to that route, so the basic function is to find the executable file
Whereis viewing the location of a file

The Whereis lookup is very fast compared to find, because the Linux system records all the files in the system in a single database file. When using Whereis and the locate described below, the data is looked up from the database, rather than being looked up by traversing the hard disk like the Find command, which is naturally very efficient.
However, the database file is not updated in real time and is updated once a week by default, so when we use Whereis and locate to find files, we sometimes find data that has been deleted, or just created the file, but cannot find it because the database file is not updated.
Locate to view file locations with a database
Find actual search hard disk query file name

Find is a hard disk to traverse lookups, so it consumes hard disk resources and is very inefficient

②grep-n-E ' root|kyo|^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)

GREP supports only the underlying regular expression by default, and if you want to use an extensibility regular expression, you can use GREP-E. GREP-E and Egrep are equivalent to the command alias relationship.

[:d Igit:] matches any numeric character

[: Alpha:] matches any alphabetic character (including uppercase and lowercase letters)

(4) write the corresponding shell command as required

① Search for files under directory/usr/include signal.h exists (hint: find command)

Using Find/udr/include-name signal.h

② 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. (Tip: ① uses grep and wildcard characters *;② to leverage error message redirection and special device files/dev/null)
③ in the user name password file/etc/passwd The login shell for bash user information record, and displays the line number (hint: use grep and $ in regular expression)

④ 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)

3. Write a shell script that is executed in 4 different ways (see Chapter 4th, Textbook/Courseware).

(2) Exercise 2 1th, use Vi/vim/gedit or other editor, write shell script ex2.sh, the content is as follows:

Summary and Experience

The experiment was so uncomfortable that Ubuntu on my virtual machine did not know why many of the commands in the experiment could not be executed, and many things could not be installed like GIMP, without that part of the experiment. There will be time to solve the problem. The overall feeling of the shell is very interesting, but also very powerful, after the examination will be carefully pondering.

Experiment three, Shell programming

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.