grep 第四天

1 使用grep 取 passwd 显示行数

grep -c '' /etc/passwd

[root@master ~]# grep -c '' /etc/passwd
135

2 使用grep 取passwd 显示行号

grep -n '' /etc/passwd



[root@master ~]# grep -n '' /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
2:bin:x:1:1:bin:/bin:/sbin/nologin
3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6:sync:x:5:0:sync:/sbin:/bin/sync
7:shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8:halt:x:7:0:halt:/sbin:/sbin/halt
9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11:games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13:nobody:x:99:99:Nobody:/:/sbin/nologin
14:avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
15:dbus:x:81:81:System message bus:/:/sbin/nologin
16:polkitd:x:999:998:User for polkitd:/:/sbin/nologin
17:tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
18:postfix:x:89:89::/var/spool/postfix:/sbin/nologin
19:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
20:wang:x:1000:1000:wang:/home/wang:/bin/bash
21:systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
22:it101:x:1001:1001::/home/it101:/bin/bash
23:it1:x:1002:1002::/home/it1:/bin/bash
24:it2:x:1003:1003::/home/it2:/bin/bash
25:it3:x:1004:1004::/home/it3:/bin/bash
26:it4:x:1005:1005::/home/it4:/bin/bash
27:it5:x:1006:1006::/home/it5:/bin/bash
28:it6:x:1007:1007::/home/it6:/bin/bash
29:it7:x:1008:1008::/home/it7:/bin/bash
30:it8:x:1009:1009::/home/it8:/bin/bash
31:it9:x:1010:1010::/home/it9:/bin/bash
32:it10:x:1011:1011::/home/it10:/bin/bash
33:it11:x:1012:1012::/home/it11:/bin/bash
34:it12:x:1013:1013::/home/it12:/bin/bash
35:it13:x:1014:1014::/home/it13:/bin/bash
36:it14:x:1015:1015::/home/it14:/bin/bash
37:it15:x:1016:1016::/home/it15:/bin/bash
38:it16:x:1017:1017::/home/it16:/bin/bash
39:it17:x:1018:1018::/home/it17:/bin/bash
40:it18:x:1019:1019::/home/it18:/bin/bash
41:it19:x:1020:1020::/home/it19:/bin/bash
42:it20:x:1021:1021::/home/it20:/bin/bash
43:it21:x:1022:1022::/home/it21:/bin/bash
44:it22:x:1023:1023::/home/it22:/bin/bash
45:it23:x:1024:1024::/home/it23:/bin/bash
46:it24:x:1025:1025::/home/it24:/bin/bash
47:it25:x:1026:1026::/home/it25:/bin/bash
48:it26:x:1027:1027::/home/it26:/bin/bash
49:it27:x:1028:1028::/home/it27:/bin/bash
50:it28:x:1029:1029::/home/it28:/bin/bash
51:it29:x:1030:1030::/home/it29:/bin/bash
52:it30:x:1031:1031::/home/it30:/bin/bash
53:it31:x:1032:1032::/home/it31:/bin/bash
54:it32:x:1033:1033::/home/it32:/bin/bash
55:it33:x:1034:1034::/home/it33:/bin/bash
56:it34:x:1035:1035::/home/it34:/bin/bash
57:it35:x:1036:1036::/home/it35:/bin/bash
58:it36:x:1037:1037::/home/it36:/bin/bash
59:it37:x:1038:1038::/home/it37:/bin/bash
60:it38:x:1039:1039::/home/it38:/bin/bash
61:it39:x:1040:1040::/home/it39:/bin/bash
62:it40:x:1041:1041::/home/it40:/bin/bash
63:it41:x:1042:1042::/home/it41:/bin/bash
64:it42:x:1043:1043::/home/it42:/bin/bash
65:it43:x:1044:1044::/home/it43:/bin/bash
66:it44:x:1045:1045::/home/it44:/bin/bash
67:it45:x:1046:1046::/home/it45:/bin/bash
68:it46:x:1047:1047::/home/it46:/bin/bash
69:it47:x:1048:1048::/home/it47:/bin/bash
70:it48:x:1049:1049::/home/it48:/bin/bash
71:it49:x:1050:1050::/home/it49:/bin/bash
72:it50:x:1051:1051::/home/it50:/bin/bash
73:it51:x:1052:1052::/home/it51:/bin/bash
74:it52:x:1053:1053::/home/it52:/bin/bash
75:it53:x:1054:1054::/home/it53:/bin/bash
76:it54:x:1055:1055::/home/it54:/bin/bash
77:it55:x:1056:1056::/home/it55:/bin/bash
78:it56:x:1057:1057::/home/it56:/bin/bash
79:it57:x:1058:1058::/home/it57:/bin/bash
80:it58:x:1059:1059::/home/it58:/bin/bash
81:it59:x:1060:1060::/home/it59:/bin/bash
82:it60:x:1061:1061::/home/it60:/bin/bash
83:it61:x:1062:1062::/home/it61:/bin/bash
84:it62:x:1063:1063::/home/it62:/bin/bash
85:it63:x:1064:1064::/home/it63:/bin/bash
86:it64:x:1065:1065::/home/it64:/bin/bash
87:it65:x:1066:1066::/home/it65:/bin/bash
88:it66:x:1067:1067::/home/it66:/bin/bash
89:it67:x:1068:1068::/home/it67:/bin/bash
90:it68:x:1069:1069::/home/it68:/bin/bash
91:it69:x:1070:1070::/home/it69:/bin/bash
92:it70:x:1071:1071::/home/it70:/bin/bash
93:it71:x:1072:1072::/home/it71:/bin/bash
94:it72:x:1073:1073::/home/it72:/bin/bash
95:it73:x:1074:1074::/home/it73:/bin/bash
96:it74:x:1075:1075::/home/it74:/bin/bash
97:it75:x:1076:1076::/home/it75:/bin/bash
98:it76:x:1077:1077::/home/it76:/bin/bash
99:it77:x:1078:1078::/home/it77:/bin/bash
100:it78:x:1079:1079::/home/it78:/bin/bash
101:it79:x:1080:1080::/home/it79:/bin/bash
102:it80:x:1081:1081::/home/it80:/bin/bash
103:it81:x:1082:1082::/home/it81:/bin/bash
104:it82:x:1083:1083::/home/it82:/bin/bash
105:it83:x:1084:1084::/home/it83:/bin/bash
106:it84:x:1085:1085::/home/it84:/bin/bash
107:it85:x:1086:1086::/home/it85:/bin/bash
108:it86:x:1087:1087::/home/it86:/bin/bash
109:it87:x:1088:1088::/home/it87:/bin/bash
110:it88:x:1089:1089::/home/it88:/bin/bash
111:it89:x:1090:1090::/home/it89:/bin/bash
112:it90:x:1091:1091::/home/it90:/bin/bash
113:it91:x:1092:1092::/home/it91:/bin/bash
114:it92:x:1093:1093::/home/it92:/bin/bash
115:it93:x:1094:1094::/home/it93:/bin/bash
116:it94:x:1095:1095::/home/it94:/bin/bash
117:it95:x:1096:1096::/home/it95:/bin/bash
118:it96:x:1097:1097::/home/it96:/bin/bash
119:it97:x:1098:1098::/home/it97:/bin/bash
120:it98:x:1099:1099::/home/it98:/bin/bash
121:it99:x:1100:1100::/home/it99:/bin/bash
122:it100:x:1101:1101::/home/it100:/bin/bash
123:apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
124:oldboy01:x:1102:1103::/home/oldboy01:/bin/bash
125:oldboy02:x:1103:1104::/home/oldboy02:/bin/bash
126:oldboy03:x:1104:1105::/home/oldboy03:/bin/bash
127:oldboy04:x:1105:1106::/home/oldboy04:/bin/bash
128:oldboy05:x:1106:1107::/home/oldboy05:/bin/bash
129:oldboy06:x:1107:1108::/home/oldboy06:/bin/bash
130:oldboy07:x:1108:1109::/home/oldboy07:/bin/bash
131:oldboy08:x:1109:1110::/home/oldboy08:/bin/bash
132:oldboy09:x:1110:1111::/home/oldboy09:/bin/bash
133:oldboy10:x:1111:1112::/home/oldboy10:/bin/bash
134:mailuser:x:1112:1113::/home/mailuser:/bin/bash
135:oldboy:x:1113:1114::/home/oldboy:/bin/bash

3 统计test信息在文件中出现了几次

grep -c 'test' file

[root@master ~]# grep -c 'test' file
0

4 显示/etc/inittab中包含了:一个数字:(即两个冒号中间一个数字)的行

egrep ':[0-9]+' /etc/inittab
grep ':[0-9]' /etc/inittab

5 显示/etc/passwd中以nologin结尾的行

grep 'nologin$' /etc/passwd


[root@master ~]# grep 'nologin$' /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin

6 显示 /etc/httpd/httpd.conf 注释的行取出来

grep '^#' /etc/httpd/httpd.conf



经查实centos7.4的httpd目录有变化  
find / -name 'httpd.conf'
/etc/httpd/conf/httpd.conf



[root@master ~]# grep '^#' /etc/httpd/conf/httpd.conf 
#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so 'log/access_log'
# with ServerRoot set to '/www' will be interpreted by the
# server as '/www/log/access_log', where as '/log/access_log' will be
# interpreted as '/log/access_log'.
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#
# Relax access to content within /var/www.
#
# Further relax access to the default document root:
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
#
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default.  To use the 
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#
#
# EnableMMAP and EnableSendfile: On systems that support it, 
# memory-mapping or the sendfile syscall may be used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted 
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults if commented: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
# Supplemental configuration
#
# Load config files in the "/etc/httpd/conf.d" directory, if any.

7 .统计/etc/services文件中有井号开头的行

grep -c '^#' /etc/services 


[root@master ~]# grep -c '^#' /etc/services 
102

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。