Marco 2016 new Linux+python high-end operation fifth Week

Source: Internet
Author: User
Tags echo command test email address egrep


Content of this week's job:

1. Display the default shell of root, fedora or User1 user on the current system;

# no Fedora, User1 users, add fadora,user1 simulation Environment [[email protected] ~]# useradd-s/sbin/nologin Fedora && useradd-s/bin/sh user1# add Fadora, user1 user, and specify a different default Shell[[email protected] ~]# getent passwd fedorafedora:x:1001:1001::/home/fedora:/ Sbin/nologin[[email protected] ~]# getent passwd user1user1:x:1002:1002::/home/user1:/bin/sh# filter/etc/passwd root, Fedora or User1 user, cut displays its corresponding default Shell[[email protected] ~]# egrep "^ (root|fedora|user1)"/etc/passwd | Cut-d:-f7/bin/bash/sbin/nologin/bin/sh


2. Find the line with a set of parentheses after a word in the/etc/rc.d/init.d/functions file, such as: Hello ();

# Filter each line, match all letters, and then follow a set of parentheses with the line # using EGREP to extend the regular, () need to escape [[email protected] ~]# Egrep-o "[[: Alpha:]]+\ (\)]/etc/rc.d/init.d/ functions# or [[email protected] ~]# Grep-o "[[: Alpha:]]\+ ()"/etc/rc.d/init.d/functions

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/86/BE/wKiom1fJHeTy-Cj-AABO7C4K6pk655.jpg-wh_500x0-wm_3 -wmp_4-s_3563558244.jpg "title=" Fifth week -2-1.jpg "alt=" Wkiom1fjhety-cj-aabo7c4k6pk655.jpg-wh_50 "/>


3. Use the echo command to output an absolute path, using grep to remove its base name;

# matches the base name, which is the last/after file name, exactly matches with the-o option, matches the end of [^/], [[email protected] ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" | Grep-o ' [^/]\+$ ' Ifcfg-eth0

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/86/BE/wKiom1fJHozCqp1ZAAAzPhHZy14585.jpg-wh_500x0-wm_3 -wmp_4-s_456849455.jpg "title=" Fifth week -3-1.jpg "alt=" Wkiom1fjhozcqp1zaaazphhzy14585.jpg-wh_50 "/>

Extension: Take out its path name

# Match path name, exact match with-o option, match last/previous content [[email protected] ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" | Grep-o ' ^/.*/'/etc/sysconfig/network-scripts/# then take the final/also remove [[email protected] ~]# echo "/etc/sysconfig/network-scripts /ifcfg-eth0 "| Grep-o ' ^/.*/' | Grep-o ' ^/.*[^/] '/etc/sysconfig/network-scripts

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/86/BE/wKiom1fJHtjQb9bYAABiGLz8YtY956.jpg-wh_500x0-wm_3 -wmp_4-s_2747756998.jpg "title=" Fifth week -3-2.jpg "alt=" Wkiom1fjhtjqb9byaabiglz8yty956.jpg-wh_50 "/>


4, find out the results of the ifconfig command between 1-255 numbers;

# Find the number between 1-255, use the-o option to exact match, [1-9] Find 1-9,[1-9][0-9] Find out 10-99,1[0-9]{2} find out 100-199,2[0-5]{2} Find out 200-255# sort, go to heavy [email Protected] ~]# # Ifconfig | Egrep-o ' \b (2[0-5]{2}|1[0-9]{2}|[ 1-9][0-9]| [1-9]) \b ' | Sort-n-U

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/86/BE/wKiom1fJHznSOJX_AAAnV1EvmIc684.jpg-wh_500x0-wm_3 -wmp_4-s_317763153.jpg "title=" Fifth week -4.jpg "alt=" Wkiom1fjhznsojx_aaanv1evmic684.jpg-wh_50 "/>


5, Challenge: Write a mode, can match the reasonable IP address;

# Class A address range: 1.0.0.1-126.255.255.254 Class B Address range: 128.0.0.1-191.255.255.254# Class C address range: 192.0.0.1-223.255.255.254 Class D address range: 224.0.0.1-239.255.255.254# Class E address range: 240.0.0.1-255.255.255.254 127.x.x.x is a reserved address, used for cyclic testing with the # Match range of 1-255.0-255.0-255.1-254# Ifconfig | Egrep-o "(2[0-5]{2}|1[0-9]{2}|[ 1-9][0-9]| [1-9]) \. ((2[0-5]{2}|1[0-9]{2}| [1-9] [0-9]| [0-9]) \.) {2}\< (2[0-5][0-4]|1[0-9]{2}|[ 1-9][0-9]| [1-9]) \> "

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/86/BE/wKiom1fJH6OBX3OKAAA078_WWtg075.jpg-wh_500x0-wm_3 -wmp_4-s_1108254149.jpg "title=" Fifth week -5.jpg "alt=" Wkiom1fjh6obx3okaaa078_wwtg075.jpg-wh_50 "/>


6, Challenge: Write a pattern, can match out all the email address;

# email address, match user name @ Mail server, username can be number or letter, server name is letter or number, top-level domain is letter # Add some test email address [[email protected] ~]# cat >/tmp/test_mail.txt << eof[email protected][email protected][email protected][email protected][email protected][email Protected]EOF # Egrep-o "[[: Alnum:]][email protected][[:alnum:]]+\. [[: alpha:]]+] [[email protected] ~]# Egrep-o "[[: Alnum:]][email protected][[:alnum:]]+\. [[: alpha:]]+]/tmp/test_mail.txt

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/86/BE/wKioL1fJH8zAwfqwAAA5E0dVPoI447.jpg-wh_500x0-wm_3 -wmp_4-s_1226707726.jpg "title=" Fifth week -6.jpg "alt=" Wkiol1fjh8zawfqwaaa5e0dvpoi447.jpg-wh_50 "/>


7. Find the main root of the/var directory, and belong to all files or directories of mail;

# Find/var-user Root-group mail[[email protected] var]# find/var-user root-group mail-ls3153 0 drwxrwxr-x 2 ro OT Mail SEP 2 09:33/var/spool/mail


8, find the current system does not belong to the main or group of files;

# Find/\ (-nouser-o-nogroup \) # Create a few test files, visually compare [[email protected] ~]# useradd user2[[email protected] ~]# Su-user2[[em AIL protected] ~]$ cd/tmp[[email protected] tmp]$ touch Test{1..3}.txt[[email protected] tmp]# chown root test2.txt [[EMA Il protected] tmp]# chown. root test3.txt [[email protected] tmp]# userdel-r user2

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/86/BE/wKioL1fJIH2ydIT5AADrG4B94f4840.jpg-wh_500x0-wm_3 -wmp_4-s_4081219228.jpg "title=" Fifth week -8-1.jpg "alt=" Wkiol1fjih2ydit5aadrg4b94f4840.jpg-wh_50 "/>

# show some content [[email protected] tmp]# Find/\ (-nouser-o-nogroup \)-ls | Head

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/86/BF/wKioL1fJIt3gsXFEAADIDjp3Lq0647.jpg-wh_500x0-wm_3 -wmp_4-s_652284738.jpg "title=" Fifth week -8-2.jpg "alt=" Wkiol1fjit3gsxfeaadidjp3lq0647.jpg-wh_50 "/>


Further: Find files or directories that are not owned by the master or group on the current system and have been visited in the last 3 days;

# Find/\ (-nouser-o-nogroup \)-atime-3# display part [[email protected] tmp]# Find/\ (-nouser-o-nogroup \)-atime-3-L s | Head

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/86/BF/wKiom1fJI0rCWilBAACzCUaW8PM768.jpg-wh_500x0-wm_3 -wmp_4-s_2350400190.jpg "title=" Fifth week -8-3.jpg "alt=" Wkiom1fji0rcwilbaaczcuaw8pm768.jpg-wh_50 "/>


9, find all the users in/etc directory have write permission files;

# All users satisfy write permission at the same time, use -222# find/etc/-perm-222

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/86/BF/wKiom1fJI8fzgu0kAACx2KFIY4U965.jpg-wh_500x0-wm_3 -wmp_4-s_1016830171.jpg "title=" Fifth week -9.jpg "alt=" Wkiom1fji8fzgu0kaacx2kfiy4u965.jpg-wh_50 "/>


10. Find all files that are larger than 1M in/etc directory and are of normal file type;

# find/etc/-size +1m-type F

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/86/BF/wKiom1fJI-HiVSZ1AAA_MK2X-Os378.jpg-wh_500x0-wm_3 -wmp_4-s_2512620292.jpg "title=" Fifth week -10.jpg "alt=" Wkiom1fji-hivsz1aaa_mk2x-os378.jpg-wh_50 "/>


11, find/etc/init.d/directory, all users have execute permission, and other users have write permission files;

# Find/etc/init.d-perm-113[[email protected] tmp]# find/etc/init.d-perm-113-ls33709906 0 lrwxrwxrwx 1 root Root 09:39/ETC/INIT.D-RC.D/INIT.D


12. Find files that do not belong to root, bin or hadoop in the/usr directory;

# FIND/USR! \ (-user root-o-user bin-o-user hadoop \) or # FIND/USR! -user Root! -user bin! -user Hadoop

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/86/BF/wKiom1fJJHjheX9RAADSNY_WZhE374.jpg-wh_500x0-wm_3 -wmp_4-s_3152642446.jpg "title=" Fifth week -12.jpg "alt=" Wkiom1fjjhjhex9raadsny_wzhe374.jpg-wh_50 "/>


13, to find at least one type of/etc/directory Users do not have write permission files;

#-222 is all users have write permission to use! Take the opposite, is in addition to all users have write permission files, is at least one kind of user is no write permission # FIND/ETC! -perm-222

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/86/BF/wKioL1fJJImyxq0ZAACGQNEsfF0041.jpg-wh_500x0-wm_3 -wmp_4-s_4136175226.jpg "title=" Fifth week -13.jpg "alt=" Wkiol1fjjimyxq0zaacgqnesff0041.jpg-wh_50 "/>


14. Find files whose contents have been modified and not rooted or Hadoop for the last week in/etc directory;

# FIND/ETC-MTIME-7! \ (-user root-o-user hadoop \) or # FIND/ETC-MTIME-7! -user Root! -user Hadoop

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/86/BF/wKiom1fJJVvAWo53AABOAIuGiZA942.jpg-wh_500x0-wm_3 -wmp_4-s_1831107338.jpg "title=" Fifth week -14.jpg "alt=" Wkiom1fjjvvawo53aaboaiugiza942.jpg-wh_50 "/>

This article is from the "ld0381 Learning Journey" blog, reprint please contact the author!

Marco 2016 new Linux+python high-end operation fifth Week

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.