Linux experiment three: Shell programming (1)

Source: Internet
Author: User
Tags curl readable

    1. Hell Command Application Exercise

①/ETC/PASSWD '

ETC/PASSWD contains a row for each user account, containing seven fields separated by a colon (":"): Login name, selected encrypted password, Word user ID, Word Group ID, username and comment field, user home directory, optional user command interpreter

②/etc/shadow

Shadow is a file that contains password information for the system account and optional age information. This file must never be readable by ordinary users if the password is not maintained properly.

③/etc/group

A file is a profile of a user group that includes users and groups of users, and can show which user group or groups of users belong to, because one user can belong to one or more different groups of users, and users of the same user group have similar characteristics.

④/etc/gshadow,

The/etc/gshadow contains the shadow group account information. This file must never be readable by ordinary users if the password is not maintained properly.

(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 displays the actual valid user ID (UID) and group ID (GID)

②ID-U Display User ID

③id-u root Displays the root user ID

④id-u Jiang Display the ID of the Jiang

(3) In the shell command terminal, enter the following command, observe the execution results, understand the specific functions of each command implementation

The purpose of the ①which Python which command is to search for the location of a system command in the path specified by the path variable, and return the first search result.

Whereis python View the location of a file

Locate Python with database view file location

Find/usr/bin-name python actual search HDD Query file name

③grep-n-E ' root|jiang|^user* '/etc/passwd

Find rows that start with root or Jiang in/etc/passwd

Grep-n-E ' [[:d igit:]] '/etc/passwd

Find the number contained in the/ETC/PASSWD

Grep-n-E ' [[: Alpha:] '/etc/passwd

Find the letters contained in the/ETC/PASSWD

Grep-n ' [0-9]\{4,\} '/etc/group (hint: Finding GID in the user group file is 4

sudo apt install gimp: Installing GIMP software

Which GIMP find the location of GIMP

sudo apt remove gimp uninstall gimp

Which GIMP again finds the location of GIMP and cannot find

④ls-dl/root--time-style=long-iso

Ls-dl/root--time-style=long-iso | Cut-d '-f1,8

⑤ls-l--time-style=long-iso

To list the time of a file as Long-ios

Ls-l--time-style=long-iso-t

List files in time-modified chronological order

Ls-l--time-style=long-iso-t-R

In reverse order of the above time

⑥ls/usr/share/man View this directory

Ls/usr/share/man | grep man[1-8] Search for man1-8 in this directory

Ls/usr/share/man/man1 View Man1 Directory

file/usr/share/man/man1/ls.1.gz View this file information

mkdir ~/temp; cp/usr/share/man/man1/ls.1.gz ~/temp Create a temp directory and copy ls.1.gz to that directory

CD ~/temp; LS go to the temp directory and view

sudo gzip-d ls.1.gz; LS extract and view file directory

⑦ls–l/home |  grep "^d" | Wc–l

⑧sudo adduser user7 Creating user users

Ls/home | Tee Users | Wc–l finding users and counting numbers

(4) write the corresponding shell command according to the requirements ① search for files under directory/usr/include signal.h existence

② 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.

③ in the user name password file/etc/passwd The login shell to bash user information record, and display the line number

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

(5) Experience awk, sed usage: Execute commands sequentially to observe execution results

①cp/etc/apt/sources.list T1; 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

(6) Check the network or Help to experience command curl and wget usage.

① Command Tool curl function, display the exercises you try and make necessary statement instructions

② Command tool wget function, display the exercises you have tried, and make necessary statement instructions

(1) Exercise 1

(2) Exercise 2

Linux experiment three: Shell programming (1)

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.