Megeedu Linux+python Advanced Operations 3 period five weeks

Source: Internet
Author: User
Tags echo command egrep

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

[[email protected] ~]# useradd fedora          #添加用户fedora [[email protected] ~]# useradd user1           #添加用户user1 [[email protected] ~]# egrep  ' ^ ( Root|fedora|user1) '  /etc/passwd | cut -d: -f1,7                                         #使用表达式 (Root|fedora|user1) Find root, Fedora, or user1root:/bin/bashfedora:/bin/bashuser1:/bin/bash[[email protected] ~]# 

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

[Email protected] ~]# egrep-o "^[_[:alpha:]]+\ (\)"/etc/rc.d/init.d/functions #使用 [: Alpha:] Special character set matching [a-z,a-z]

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

Extension: Take out its path name

[Email protected] ~]# echo "/home/etc/" | Egrep-o "[^/]+/?$" | Cut-d "/"-f1

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

[Email protected] ~]# Ifconfig | Egrep-o ' ([1-9]|[ 1-9][0-9]| [0-2] [0-5] [0-5]) '

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

#以IPV4地址为例: #现在的IP网络使用32位地址, in dotted decimal notation, such as 192.168.0.1. #地址格式为: IP address = Network address + host address #这里不做细化, simple match satisfies host address is not full 0 or full 1, ie (1-255). (0-255). (0-255). (1-254) can # "([1-9]|[ 1-9][0-9]| [0-2] [0-5] [0-5]). ([0-9]| [1-9] [0-9]| [0-2] [0-5] [0-5]). ([0-9]| [1-9] [0-9]| [0-2] [0-5] [0-5]). ([1-9]| [1-9] [0-9]| [0-2] [0-5] [0-4]) " [email protected] ~]# cat TestIP.txt 2.34.67.991.0.0.11.22.0.01.24.0.255192.168.999.254192.167.255.255[[email Protected] ~]# egrep "\< ([1-9]|[ 0-9][1-9]| [0-2] [0-5] [0-5]) \. ([0-9]| [1-9] [0-9]| [0-2] [0-5] [0-5]) \. ([0-9]| [1-9] [0-9]| [0-2] [0-5] [0-5]) \. ([1-9]| [1-9] [0-9]| [0-2] [0-5] [0-4]) \> "TestIP.txt 2.34.67.991.0.0.1[[email protected] ~]#

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

#邮箱地址一般分为三大部分, username @ domain # The first part of the user name, can contain numbers, letters, underscores, and does not start with special characters. #第二部分为 @, available @ Direct Match # Part Three is a domain name that can contain letters, numbers, underscores, and "." And does not start with a special character. For example: qq.com, 163.com[[email protected] ~]# cat mail.txt #创建mail. txt file, handwritten several e-mail addresses. [Email protected] [Email protected] [Email protected] [email protected]_djfie.dlfl.com[[email protected] ~]# egrep "^[[:alnum:]][_[:alnum:]]*@[[:alnum:]][_[:alnum:]]*\. [[: Alnum:]] "mail.txt [email protected][email protected][[email protected] ~]#

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

[[email protected] ~]# find/var-user root-group mail #使用find命令加-user and-group options specify their owner group/var/spool/mail[[email Prot  Ected] ~]# find/var-user root-group mail-ls #使用选项-ls View Details 262439 4 drwxrwxr-x 2 root mail 4096 September 5 18:46/var/spool/mail

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

[[email protected] ~]# Find/-nouser-o-nogroup #选项-nouser means no owner,-nogroup means no group,-O indicates Condition ' or '

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;

[[email protected] ~]# Find/-nouser-o-nogroup-atime-3 #选项-atime-3 to find files or directories that have been visited in the last 3 days

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

[Email protected] ~]# find/etc/-perm-222-ls #使用选项-perm Find #-222 According to permissions: every A class of objects must also have a permission standard assigned to it; #/mode: the permission of any class of (U,g,o) object can only be one match

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

[[email protected] ~]# find /etc -size +1m -type f -ls                           #选项-size : Specify find File Size                           #选项-type: Specifying File types                          #   f:  General Documents                          #    d:  Catalog Files                          #   l:  Symbolic Link File                          #    s: Socket file                          #   b:  Block device Files                           #   c:  Character device Files                          #   p:  Piping Files

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

[Email protected] ~]# Find/etc/init.d-perm-113-ls

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

[Email protected] ~]# find/usr-not \ (-user root-o-user bin-o-user hadoop \)-ls[[email protected] ~]# find/usr/-   Not-user root-a-not-user bin-a-not-user hadoop #选项-not condition non-#选项-a For conditions and

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

[Email protected] ~]# Find/etc-not-perm-111-ls

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

[Email protected] ~]# find/etc/-mtime-7-a-not \ (-user root-o-user hadoop \) #选项-mtime lookup means Files or directories that have been modified during the


This article from "blog" blog, declined reprint!

Megeedu Linux+python Advanced Operations 3 period five weeks

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.