一、找出/etc/rc.d/init.d/functions文件中某單詞後面跟一組小括號的行,形如:hello();linux
[root@localhost ~]# grep -E "[[:alpha:]]+\(\)+" /etc/rc.d/init.d/functions checkpid() { __pids_var_run() { __pids_pidof() { daemon() { killproc() { pidfileofproc() { pidofproc() { status() { echo_success() { echo_failure() { echo_passed() { echo_warning() { update_boot_stage() { success() { failure() { passed() { warning() { action() { strstr() { is_ignored_file() { is_true() { is_false() { apply_sysctl() {
二、使用echo命令輸出一個絕對路徑,使用grep取出其基名;git
[root@localhost ~]# echo "/bin/bash/" | grep -E -o "[^/]+/?$" | cut -d/ -f1 bash
擴展:取出其路徑名vim
[root@localhost ~]# echo "/bin/bash/d/" | grep -E -o "^/.*[^/]" | grep -E -o "^/.*/" /bin/bash/
三、找出ifconfig命令結果中的1-255之間數字;bash
[root@localhost ~]# ifconfig | grep -E -o "[[:digit:]]{1,}" | grep -E -w "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])" 192 168 223 128 255 255 255 192 168 223 255 6 80 20 29 3 6 64 20 29 3 6 7 19 8 73 127 1 255 6 1 128 10 26 2 26 2 192 168 122 1 255 255 255 192 168 122 255 52 54 70 9 5
[root@localhost ~]# ifconfig | grep -E -w "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])" inet 192.168.223.128 netmask 255.255.255.0 broadcast 192.168.223.255 inet6 fe80::20c:29ff:fe3d:6dea prefixlen 64 scopeid 0x20<link> ether 00:0c:29:3d:6d:ea txqueuelen 1000 (Ethernet) RX packets 501011 bytes 692867068 (660.7 MiB) TX packets 157560 bytes 20813669 (19.8 MiB) lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> RX packets 314 bytes 26870 (26.2 KiB) TX packets 314 bytes 26870 (26.2 KiB) inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:70:c9:d5 txqueuelen 0 (Ethernet)
四、查找當前系統上沒有屬主或屬組的文件;app
[root@localhost ~]# find / -nouser -nogroup find: ‘/proc/38302/task/38302/fd/6’: No such file or directory find: ‘/proc/38302/task/38302/fdinfo/6’: No such file or directory find: ‘/proc/38302/fd/6’: No such file or directory find: ‘/proc/38302/fdinfo/6’: No such file or directory
進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;ide
[root@localhost ~]# find / -nouser -nogroup -atime -3 find: ‘/proc/38312/task/38312/fd/6’: No such file or directory find: ‘/proc/38312/task/38312/fdinfo/6’: No such file or directory find: ‘/proc/38312/fd/6’: No such file or directory find: ‘/proc/38312/fdinfo/6’: No such file or directory
五、查找/etc目錄下大於1M,且類型爲普通文件的全部文件;oop
[root@localhost ~]# find /etc -size +1M -type f -ls 69639801 3772 -rw-r--r-- 1 root root 3858924 Nov 20 2015 /etc/selinux/targeted/policy/policy.29 135034268 6852 -r--r--r-- 1 root root 7014922 Dec 23 00:49 /etc/udev/hwdb.bin 68629841 1336 -rw-r--r-- 1 root root 1367395 Mar 5 2015 /etc/brltty/zh-tw.ctb
六、查找/etc/init.d/目錄下,全部用戶都有執行權限,且其它用戶有寫權限的文件;spa
[root@localhost ~]# find /etc/init.d/ -perm -113 -type f
七、查找/etc目錄下最近一週內其內容被修改過,且不屬於root或hadoop的文件;3d
[root@localhost ~]# find /etc -mtime -7 -not -user root -not -user hadoop -ls
八、複製/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以致少一個空白字符開頭的行的行首加#;crontab
[root@localhost~]# cp /etc/rc.d/rc.sysinit /tmp/ [root@localhost~]# vim /tmp/rc.sysinit
在末行模式中輸入:
%s/^[[:space:]]\+/#&/g
九、刪除/tmp/rc.sysinit文件中的以#開頭,且後面跟了至少一個空白字符的行行的#和空白字符
[root@localhost~]# vim /tmp/rc.sysinit
在末行模式中輸入:
%s/^[#][[:space:]]\+//g
十、將/etc/yum.repos.d/CentOS-Media.repo文件中全部的enabled=0或gpgcheck=0的最後的0修改成1;
[root@localhost~]# vim etc/yum.repos.d/CentOS-Media.repo
在末行模式中輸入:
%s#\(enabled=\)[[:digit:]]#\11#g
%s#\(gpgcheck=\)[[:digit:]]#\11#g
十一、每週2,4,6備份/var/log/messages文件至/backup/messages_logs/目錄中,保存的文件名形如messages-20161202
[root@study ~]# crontab -e 0 0 * * 2,4,6 /bin/cp -a /var/log/messages /backup/messages_logs/messages-$(date +\%Y\%m\%d)
十二、天天每兩小時取當前系統/proc/meminfo文件中的全部以S開頭的信息至/stats/memory.txt文件中
[root@localhost ~]# crontab -e 00 */2 * * * cat /proc/meminfo |grep "^S" >> /stats/memory.txt
1三、寫一個腳本建立10用戶user10-user19;密碼同用戶名;
#!/bin/bash# for i in {10..19};do if id user$i ;then echo "user$i exists." else useradd user$i echo "user$i" | passwd --stdin user$i fi done