1、每日课堂笔记总结
2、预习
3、每日课堂pdf练习
1、找出ifconfig命令结果中本机的所有IPv4地址
[root@Centos7 ~]# ifconfig |head -2 |tail -1|tr -s ' ' ':'|cut -d: -f3 10.1.252.77
2、查出分区空间使用率的最大百分比值
[root@Centos7 ~]# df|cut -c44-46|sort -n 0 0 0 Use 1 1 1 1 7 74
3、查出用户UID最大值的用户名、UID及shell类型
[root@Centos7 ~]# cat /etc/passwd |cut -d: -f1,3,7|sort -n -t: -k2|tail -1 nfsnobody:65534:/sbin/nologin
4、查出/tmp的权限,以数字方式显示
[root@Centos7 ~]# stat /tmp|head -n 4|tail -n 1|cut -d'(' -f2|cut -d'/' -f1 1777
5、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@Centos7 ~]# netstat -nt|cut -c "45-54"|sort|uniq -c 1 1 10.1.24.55 1 Foreign Ad
1、显示/proc/meminfo文件中以大小s开头的行;(要求:使用两种方式)
[root@Centos7 ~]# grep -ni "^s" /proc/meminfo 6:SwapCached: 0 kB 15:SwapTotal: 3905532 kB 16:SwapFree: 3905532 kB 21:Shmem: 9220 kB 22:Slab: 72404 kB 23:SReclaimable: 27452 kB 24:SUnreclaim: 44952 kB [root@Centos7 ~]# grep -n '^[Ss]' /proc/meminfo 6:SwapCached: 0 kB 15:SwapTotal: 3905532 kB 16:SwapFree: 3905532 kB 21:Shmem: 9220 kB 22:Slab: 72404 kB 23:SReclaimable: 27452 kB 24:SUnreclaim: 44952 kB
2、显示/etc/passwd文件中不以/bin/bash结尾的行
[root@Centos7 ~]# grep -nv '/bin/bash$' /etc/passwd 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:systemd-bus-proxy:x:999:998:systemd Bus Proxy:/:/sbin/nologin 15:systemd-network:x:998:997:systemd Network Management:/:/sbin/nologin 16:dbus:x:81:81:System message bus:/:/sbin/nologin 17:polkitd:x:997:996:User for polkitd:/:/sbin/nologin 18:abrt:x:173:173::/etc/abrt:/sbin/nologin 19:unbound:x:996:995:Unbound DNS resolver:/etc/unbound:/sbin/nologin 20:tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin 21:colord:x:995:994:User for colord:/var/lib/colord:/sbin/nologin 22:usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin 23:geoclue:x:994:991:User for geoclue:/var/lib/geoclue:/sbin/nologin 24:rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin 25:rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin 26:chrony:x:993:990::/var/lib/chrony:/sbin/nologin 27:radvd:x:75:75:radvd user:/:/sbin/nologin 28:qemu:x:107:107:qemu user:/:/sbin/nologin 29:avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin 30:setroubleshoot:x:992:989::/var/lib/setroubleshoot:/sbin/nologin 31:rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin 32:nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin 33:saslauth:x:991:76:Saslauthd user:/run/saslauthd:/sbin/nologin 34:libstoragemgmt:x:990:988:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin 35:pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin 36:gdm:x:42:42::/var/lib/gdm:/sbin/nologin 37:gnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologin 38:avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin 39:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 40:postfix:x:89:89::/var/spool/postfix:/sbin/nologin 41:ntp:x:38:38::/etc/ntp:/sbin/nologin 42:tcpdump:x:72:72::/:/sbin/nologin 45:fedora:x:4006:4007:Fecora Community:/home/fedora:/bin/tcsh 46:hbash:x:988:983::/home/hbash:/sbin/nologin 47:gentoo:x:4007:4008:Gentoo Distribution:/home/gentoo:/bin/csh 50:sarah:x:4010:4012::/home/sarah:/sbin/nologin
3、显示用户rpc默认的shell程序
[root@Centos7 ~]# grep '^rpc\>' /etc/passwd |cut -d: -f7 /sbin/nologin
4、找出/etc/passwd中的两位或三位数
[root@Centos7 ~]# grep -n '\<[[:digit:]]\{2,3\}\>' /etc/passwd 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:systemd-bus-proxy:x:999:998:systemd Bus Proxy:/:/sbin/nologin 15:systemd-network:x:998:997:systemd Network Management:/:/sbin/nologin 16:dbus:x:81:81:System message bus:/:/sbin/nologin 17:polkitd:x:997:996:User for polkitd:/:/sbin/nologin 18:abrt:x:173:173::/etc/abrt:/sbin/nologin 19:unbound:x:996:995:Unbound DNS resolver:/etc/unbound:/sbin/nologin 20:tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin 21:colord:x:995:994:User for colord:/var/lib/colord:/sbin/nologin 22:usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin 23:geoclue:x:994:991:User for geoclue:/var/lib/geoclue:/sbin/nologin 24:rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin 25:rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin 26:chrony:x:993:990::/var/lib/chrony:/sbin/nologin 27:radvd:x:75:75:radvd user:/:/sbin/nologin 28:qemu:x:107:107:qemu user:/:/sbin/nologin 29:avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin 30:setroubleshoot:x:992:989::/var/lib/setroubleshoot:/sbin/nologin 31:rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin 33:saslauth:x:991:76:Saslauthd user:/run/saslauthd:/sbin/nologin 34:libstoragemgmt:x:990:988:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin 35:pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin 36:gdm:x:42:42::/var/lib/gdm:/sbin/nologin 37:gnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologin 38:avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin 39:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 40:postfix:x:89:89::/var/spool/postfix:/sbin/nologin 41:ntp:x:38:38::/etc/ntp:/sbin/nologin 42:tcpdump:x:72:72::/:/sbin/nologin 46:hbash:x:988:983::/home/hbash:/sbin/nologin 65:uesr2:x:987:982::/home/uesr2:/bin/bash
5、显示/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面存非空白字符的行
[root@Centos7 ~]# grep -n '^[[:space:]].*[^[:space:]]' /etc/grub2.cfg 12: load_env 15: set default="${next_entry}" 16: set next_entry= 17: save_env next_entry 18: set boot_once=true 20: set default="${saved_entry}" 24: menuentry_id_option="--id" 26: menuentry_id_option="" 32: set saved_entry="${prev_saved_entry}" 33: save_env saved_entry 34: set prev_saved_entry= 35: save_env prev_saved_entry 36: set boot_once=true 40: if [ -z "${boot_once}" ]; then 41: saved_entry="${chosen}" 42: save_env saved_entry 43: fi 47: if [ x$feature_all_video_module = xy ]; then 48: insmod all_video 49: else 50: insmod efi_gop 51: insmod efi_uga 52: insmod ieee1275_fb 53: insmod vbe 54: insmod vga 55: insmod video_bochs 56: insmod video_cirrus 57: fi 62: set timeout_style=menu 63: set timeout=5 67: set timeout=5 77: source ${prefix}/user.cfg 78: if [ -n ${GRUB2_PASSWORD} ]; then 79: set superusers="root" 80: export superusers 81: password_pbkdf2 root ${GRUB2_PASSWORD} 82: fi 88: load_video 89: set gfxpayload=keep 90: insmod gzio 91: insmod part_msdos 92: insmod xfs 93: set root='hd0,msdos1' 94: if [ x$feature_platform_search_hint = xy ]; then 95: search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' c332bc3c-01b4-40e3-b600-c5791719e14b 96: else 97: search --no-floppy --fs-uuid --set=root c332bc3c-01b4-40e3-b600-c5791719e14b 98: fi 99: linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=UUID=4b461f3a-1b13-49c9-80eb-0a03f4fa9519 ro crashkernel=auto rhgb quiet.UTF-8 100: initrd16 /initramfs-3.10.0-327.el7.x86_64.img 103: load_video 104: insmod gzio 105: insmod part_msdos 106: insmod xfs 107: set root='hd0,msdos1' 108: if [ x$feature_platform_search_hint = xy ]; then 109: search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' c332bc3c-01b4-40e3-b600-c5791719e14b 110: else 111: search --no-floppy --fs-uuid --set=root c332bc3c-01b4-40e3-b600-c5791719e14b 112: fi 113: linux16 /vmlinuz-0-rescue-d84e4562ec594069be53afee569c711e root=UUID=4b461f3a-1b13-49c9-80eb-0a03f4fa9519 ro crashkernel=auto rhgb quiet 114: initrd16 /initramfs-0-rescue-d84e4562ec594069be53afee569c711e.img 136: source ${config_directory}/custom.cfg 138: source $prefix/custom.cfg;
6、找出"netstat -tan"命令的结果中以'LISTEN'后跟0、1或多个空白字符结尾的行
[root@Centos7 ~]# netstat -tan|grep 'LISTEN[[:space:]]*' tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN
7、添加用户bash、testbash、basher以及nologin(其shell为/sbin/nologin),而后找出/etc/passwd文件中用户名同shell名的行
[root@Centos7 ~]# grep -n '^\([[:alnum:]]\+\>\).*\1$' /etc/passwd 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 67:bash:x:5004:5008::/home/bash:/bin/bash
4、用正则表达式表示IP地址
[root@Centos7 ~]# ifconfig | grep -En "\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>" 2: inet 10.1.252.77 netmask 255.255.0.0 broadcast 10.1.255.255 11: inet 127.0.0.1 netmask 255.0.0.0 20: inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
5、用正则表达式表示手机号11 13 17 15 18
[root@Centos7 ~]# !ca cat f1 13450219905 11111111111 12345678999 13534245435 15546456564564 134567886566 13232242 17342432432 18424324323 [root@Centos7 ~]# grep -En "\<(13|15|17|18)[[:digit:]]{9}\>" f1 1:13450219905 4:13534245435 8:17342432432 18424324323
6、用正则表达式表示身份证号18
做不出来
7、用正则表达式表示邮箱
[root@Centos7 ~]# cat !$ cat f1 21e@3232.com maeefe@madede.com edweww@ddsds.comdw.dewew@dsdwddw.com 1111@111.1111.1111@11111.!111 [root@Centos7 ~]# grep -nE "\<^[[:alnum:]]+\>@\<[[:alnum:]]+\>.\<[[:alnum:]]+$\>" f1 1:21e@3232.com 2:maeefe@madede.com
原创文章,作者:麦德良,如若转载,请注明出处:http://www.178linux.com/30451