Linux基础练习题(三)
生活随笔
收集整理的這篇文章主要介紹了
Linux基础练习题(三)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、顯示當前系統上root、fedora或user1用戶的默認shell;
[root@www ~]# egrep "^(root|fedora|user1)" /etc/passwd|cut -d: -f1,7 root:/bin/bash user1:/bin/bash fedora:/bin/zsh2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行;例如:hello();
[root@www ~]# egrep "\w+\(\)" /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() {3、使用echo命令輸出一個絕對路徑,使用grep取出其基名;擴展:取出其路徑名;
# 取出其基名 [root@www ~]# echo "/var/log/messages"|egrep -o "[^/]+\/?$" messages # 取出其路徑名 [root@www ~]# echo "/var/log/messages"|grep -o "^/.*/" /var/log/4、找出ifconfig命令結果中的1-255之間的數字;
[root@www ~]# ifconfig |egrep -o "\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"5、挑戰題:寫一個模式,能匹配出合理的IP地址;
[root@www ~]# ifconfig | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" 192.168.1.141 255.255.255.0 192.168.1.255 127.0.0.1 255.0.0.06、挑戰題:寫一個模式,能匹配出所有的郵件地址;
[root@www ~]# egrep -o "\w+@\w+\.(cn|com)" /etc/test.txt tom@163.com jerry@163.com zhangsan@testdomain.cn7、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;
[root@www ~]# find /var/ -user root -a -group mail -ls 134295636 0 drwxrwxr-x 2 root mail 103 12月 30 00:38 /var/spool/mail 136092594 884 -rw------- 1 root mail 900983 12月 30 00:38 /var/spool/mail/root8、查找當前系統上沒有屬主或屬組的文件;查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;
[root@www ~]# find / -atime -3 -nouser -a -nogroup -exec ls -l {} \; -rw-rw-rw- 1 1000 1000 6 12月 30 00:35 /etc/test.txt9、查找/etc目錄下所有用戶都有寫權限的文件;
[root@www ~]# find /etc/ -type f -perm -222 -ls 67190743 0 -rw-rw-rw- 1 root root 0 12月 30 00:10 /etc/test.txt10、查找/etc目錄下大于1M,且類型為普通文件的所有文件;
[root@www ~]# find /etc/ -type f -size +1M -exec ls -lh {} \; -r--r--r--. 1 root root 6.7M 12月 4 18:22 /etc/udev/hwdb.bin -rw-r--r--. 1 root root 3.7M 11月 21 2015 /etc/selinux/targeted/policy/policy.2911、查找/etc/init.d目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;
[root@www ~]# find /etc/init.d/ -perm -113 -ls12777 0 -rwxr-xrwx 1 root root 0 12月 30 00:17 /etc/init.d/test.txt12、查找/usr目錄下不屬于root,bin或hadoop的文件;
[root@www ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \) -ls 618038 0 drwx------ 2 polkitd root 6 6月 10 2014 /usr/share/polkit-1/rules.d13、查找/etc目錄下至少有一類用戶沒有寫權限的文件;
[root@www ~]# find /etc/ -not -perm -222 -ls14、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;
[root@www ~]# find /etc/ -mtime -7 -type f -a -not \( -user root -o -user hadoop \) -exec stat {} \;文件:"/etc/test.txt"大小:6 塊:8 IO 塊:4096 普通文件 設備:803h/2051d Inode:67190743 硬鏈接:1 權限:(0666/-rw-rw-rw-) Uid:( 1000/enzhi.wang) Gid:( 1000/enzhi.wang) 最近訪問:2016-12-30 00:10:38.089508753 +0800 最近更改:2016-12-30 00:35:36.988831137 +0800 最近改動:2016-12-30 00:36:09.092832268 +0800 創建時間:-轉載于:https://www.cnblogs.com/wangenzhi/p/6235456.html
總結
以上是生活随笔為你收集整理的Linux基础练习题(三)的全部內容,希望文章能夠幫你解決所遇到的問題。