Linux OPS Practice-August 27, 2015 Course assignments

Source: Internet
Author: User
Tags egrep

First, homework (exercise) content:

1. Summarize the use of the commands involved in this course and show the relevant examples;

2. Summarize basic regular expressions and extended regular expressions

3. Display the lines in the/etc/passwd file that end with bash

4. Display the two-digit or three-digit number in the/etc/passwd file

5. Display lines with ' LISTEN ' followed by 0, one or more whitespace characters in the ' Netstat-tan ' command result

6. Add user bash, Testbash, basher, and Nologin user (Nologin user's shell is/sbin/nologin), then find the same line in the/etc/passwd file as the user name and its shell name

7. Display the default shell and UID of root, CentOS, or User1 user on the current system (please create these users beforehand, if not present)

8, find a word in the/etc/rc.d/init.d/functions file (the middle of the word can be underlined) followed by a set of parentheses line

9, use echo to output a path, and then egrep find its path base name; Further use Egrep to remove its directory name

10. Find the number between 1-255 in the result of ifconfig command execution


question first to second : read the notes (mending)


Third question : Use the anchor bash for the suffix

[Email protected]_server home]# grep "bash$"/etc/passwdroot:x:0:0:root:/root:/bin/bashnginx:x:498:498::/home/ nginx:/bin/bashmysql:x:500:500::/home/mysql:/bin/bashhuangyisan:x:502:502::/home/huangyisan:/bin/ bashhuangyisan1:x:503:503::/home/huangyisan1:/bin/bashhuangyisan2:x:504:502::/home/huangyisan2:/bin/ Bashhuangyisan3:x:505:505::/home/huangyisan3:/bin/bash


question Fourth : The first bit is set to [1,9] then the second and third are [0,9], and let them appear once (because there is already the highest bit) so the second bit is actually 1 or 2 times, and then use-O will need to match the object to be keyed out.

[Email protected]_server home]# grep-o "\<[1-9][0-9]\{1,2\}\>"/etc/passwd_bak

The result of the final display does not match "07", since 07 belongs to one number. The question to note is that the first number cannot be 0.

[[Email protected]_server home]# Cat/etc/passwd_bak | grep 07halt:x:07:0:halt:/sbin:/sbin/halt[[email protected]_server home]# grep-o "\<[1-9][0-9]\{1,2\}\>"/etc/ Passwd_bak | grep 07[[email Protected]_server home]#



Fifth question : 0, 1 or more, then a multiple match of the previous character, you can use *, or use {0,\}, and then he asked to be a blank character end of the line, white space characters can be used [: space:] to indicate that the end of the line is used to anchor $

[[Email protected]_server home]# cat aa.txt active internet connections   (servers and established) proto recv-q send-q local address                Foreign Address              state      tcp         0      0  192.168.91.130:4506         192.168.91.131:54854         established tcp        0       0 :::8080                      :::*                          listen      tcp         0      0 ::1:53                        :::*                          LISTEN      tcp         0      0 ::ffff:127.0.0.1:8005        :::*                          LISTENING1       tcp        0      0  :::8009                      :::*                          listening

The

edited a aa.txt and wrote a disturbance.

[[email protected]_server home]# cat aa.txt  | egrep   "LISTEN[[: space:]]{0,}$ "TCP&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;0&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;0&NBSP;: ::8080                      :::*                          LISTEN       tcp        0      0 ::1:53                        :::*                          listen      [[email  protected]_server home]# cat aa.txt  | egrep   "listen[[:space:]]*$" tcp         0      0 :::8080                      :::*                          LISTEN      tcp         0      0 ::1:53                       :::*                           listen

Finally caught out of the Listen project, in fact, the listen behind there are space.


Sixth question:passwd distribution The first part is the user name, with ^ to anchor, the last part is the shell mode, with $ to anchor, he said to the user name and Shell mode is the same, first the user name to catch out, with \< user name \>, and then use \1 to match, The user name parameter is passed into the \1.

[Email protected]_server home]# grep-e ^ (\<[[:alnum:]]+) \>.+\1$ "/etc/passwdsync:x:5:0:sync:/sbin:/bin/ syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltbash:x:606:606::/home/bash:/ Bin/bashnologin:x:609:609::/home/nologin:/sbin/nologin

[[: Alnum:]] contains letters and numbers.


Seventh question: Three users or relationships, first think "|" symbols, extracted through passwd, the first part is the user name, the first line anchors the three users.

[Email protected]_server home]# grep-e ^ (\<root\>|\<centos\>|\<user1\>) "/etc/passwdroot:x:0:0: Root:/root:/bin/bashcentos:x:611:611::/home/centos:/bin/bashuser1:x:612:612::/home/user1:/bin/bash


question eighth: There is a problem with my wording. It is not possible to match the underscore between multiple words, which can be matched, but does not use the logic of the statement.

Grep-e "\<[[:alpha:]]+_? [[: Alpha:]].*\ (\) "/etc/rc.d/init.d/functions


question Nineth: Perhaps the path of ECHO will eventually exist/, my technique is to extract two times. Extract the base name first, and then extract the base name again.

[[Email protected]_server home]# echo/root/data/|  Egrep-o "[[: alnum:]]+/?$] | Egrep-o "[[: alnum:]]+" Data

To extract the directory, if only the level two directory can be crawled by anchoring and then crawling again [[: Alnum:]], the multilevel directory has not been considered.


question tenth: divided into five segments, single-digit segment, 10-segment, 100-199-segment, 200-249-segment, 250-255-segment

[[Email protected]_server home]# ifconfig | Egrep "\< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \> "

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/51/wKioL1XgimTx5PjCAAHHzsHS2iA054.jpg "title=" the tenth question " alt= "Wkiol1xgimtx5pjcaahhzshs2ia054.jpg"/>

There are still some problems, such as the number in the MAC address is not crawled out.


Extensions: fetch the IP address of the ifconfig. The feature is that the first cannot be 0 for a range of 1-255 second to fourth can be 0, the range is 0-255.

[[Email Protected]_server home]# ifconfig |egrep-o] (\< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \>\.) (\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \>\.) {2} (\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \>) "192.168.130.131192.168.130.255255.255.255.0127.0.0.1255.0.0.0


Linux OPS Practice-August 27, 2015 Course assignments

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.