馬哥教育N22期第五周作業

1、顯示當前系統上root、fedora或user1用戶的默認shell;

[root@localhost ~]# egrep "^root|fedora|user1" /etc/passwd
root:x:0:0:root:/root:/bin/bash
fedora:x:1002:1002::/home/fedora:/bin/bash
user1:x:1003:1003::/home/user1:/bin/bash

2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();

[root@localhost ~]# egrep "[[: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() {

3、使用echo命令輸出一個絕對路徑,使用grep取出其基名; 擴展:取出其路徑名

[root@localhost ~]# echo /etc/sysconfig/ |egrep -o "[^/]+/?$"  \\基名
sysconfig/
[root@localhost ~]# echo /etc/sysconfig/ |egrep -o "^/[[:alpha:]]+"  \\路徑名
/etc

4、找出ifconfig命令結果中的1-255之間數字;

[root@localhost ~]# ifconfig |egrep -o "[0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]" |sort -nu
0
1
2
3
4
5
6
10
40
43
44
51
52
53
54
65
73
94
99
122
127
128
150
168
192
255

5、挑戰題:寫一個模式,能匹配合理的IP地址;

[root@localhost ~]# ifconfig |egrep -o "(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255

6、挑戰題:寫一個模式,能匹配出所有的郵件地址;

bash腳本:
#!/bin/bash
#
read -p "Please enter e-mail:" email
echo $email |egrep -o "^[[:alnum:]_-]*@[[:alnum:]_-]*\.[[:alpha:]_-]*$"
if [ `echo $?` -eq 0 ];then
        echo "it's e-mail address"
else
        echo "it's not e-mail address"
fi
舉例:
[root@localhost xuc-scripts]# bash e-mail.sh 
Please enter e-mail:14691171@qq.com
14691171@qq.com
it's e-mail address
[root@localhost xuc-scripts]# vim e-mail.sh
[root@localhost xuc-scripts]# bash e-mail.sh 
Please enter e-mail:354
it's not e-mail address

7、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;

[root@localhost var]# find /var -user root -group mail -ls
100667017    0 drwxrwxr-x   2 root     mail           65 Sep  8 21:49 /var/spool/mail
37675687    0 drwxr-xr-x   2 root     mail            6 Sep  9 04:15 /var/test
4392325    0 drwxr-xr-x   2 root     mail            6 Sep  9 04:24 /var/test1

8、查找當前系統上沒有屬主或屬組的文件; 進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;

[root@localhost var]# find / -nouser -o -nogroup -ls
find: ‘/proc/25303/task/25303/fd/6’: No such file or directory
find: ‘/proc/25303/task/25303/fdinfo/6’: No such file or directory
find: ‘/proc/25303/fd/6’: No such file or directory
find: ‘/proc/25303/fdinfo/6’: No such file or directory
find: ‘/run/user/1000/gvfs’: Permission denied
[root@localhost var]# find / -nouser -o -nogroup -atime -3 -ls
find: ‘/proc/25323/task/25323/fd/6’: No such file or directory
find: ‘/proc/25323/task/25323/fdinfo/6’: No such file or directory
find: ‘/proc/25323/fd/6’: No such file or directory
find: ‘/proc/25323/fdinfo/6’: No such file or directory
find: ‘/run/user/1000/gvfs’: Permission denied

9、查找/etc目錄下所有用戶都有寫權限的文件;

[root@localhost var]# find /etc/ -perm -222 -type f -ls
569318    4 -rwxrwxrwx   1 root     root         1982 Jun 10  2014 /etc/virc
818408    4 -rwxrwxrwx   1 root     root          970 Dec  3  2015 /etc/yum.conf

10、查找/etc目錄下大于1M,且類型為普通文件的所有文件;

[root@localhost var]# find /etc -size +1M -type f -ls
37239307 3772 -rw-r--r--   1 root     root      3858924 Nov 20  2015 /etc/selinux/targeted/policy/policy.29
69579782 6852 -r--r--r--   1 root     root      7014922 Sep  7 09:12 /etc/udev/hwdb.bin
68402927 1336 -rw-r--r--   1 root     root      1367395 Mar  5  2015 /etc/brltty/zh-tw.ctb

11、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;

[root@localhost var]# find /etc/init.d/ -perm -113 -type f -ls
67903846    4 -rwxrwxrwx   1 root     root         2989 Sep 16  2015 /etc/init.d/netconsole
67903847    8 -rwxrwxrwx   1 root     root         6630 Sep 16  2015 /etc/init.d/network

12、查找/usr目錄下不屬于root、bin或hadoop的文件;

[root@localhost usr]#  find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls
101333886    4 drwx------   2 polkitd  root         4096 Sep  7 07:06 /usr/share/polkit-1/rules.d
35800731   16 -rwsr-sr-x   1 abrt     abrt        15336 Dec  1  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
37675688    0 drwxr-xr-x   2 xuc      xuc             6 Sep  9 05:16 /usr/test1
69105679    0 drwxr-xr-x   2 xuc      xuc             6 Sep  9 05:16 /usr/test2
101683877    0 drwxr-xr-x   2 xuc      xuc             6 Sep  9 05:16 /usr/test3

13、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;

[root@localhost usr]# find /etc/ -not -perm -222 -type f -ls
102641157    8 -rwxr-xr-x   1 root     root         5767 Jun 10  2014 /etc/smartmontools/smartd_warning.sh
68122669    4 -rwxr-xr-x   1 root     root         1382 Nov 20  2015 /etc/qemu-ga/fsfreeze-hook
102705029    4 -rwxr-xr-x   1 root     root         1676 Nov 20  2015 /etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
3936052    8 -rw-r--r--   1 root     root         5171 Jun  9  2014 /etc/man_db.conf
 18596   52 -rw-r--r--   1 root     root        51787 May 14  2013 /etc/mime.types
4008275    4 -rw-r-----   1 root     root         3181 Jul 25  2013 /etc/sudo-ldap.conf

14、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;

[root@localhost usr]# find /etc/ -not -user root -a -not -user hadoop -mtime -7 -type f -ls

原創文章,作者:N22_熊寶,如若轉載,請注明出處:http://www.www58058.com/45734

(0)
N22_熊寶N22_熊寶
上一篇 2016-09-15 22:20
下一篇 2016-09-15 22:21

相關推薦

  • 第七周

    1、創建一個10G分區,并格式為ext4文件系統; (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl; (2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳; fdisk /dev/sdb歡迎使用 fdisk (util-li…

    Linux干貨 2016-09-19
  • 磁盤管理的補充及擴展

    磁盤管理的補充及擴展 掛載點和/etc/fstab(配置文件) 使用mount命令掛載為臨時掛載開機重啟后就會自動卸載,為了永久掛載必須寫在配置文件中! 配置文件系統體系 ? 被mount、fsck和其它程序使用 ? 系統重啟時保留文件系統體系 ? 可以在設備欄使用文件系統卷標 ? 使用mount  -a 命令掛載/etc/fstab中的所有文件系…

    Linux干貨 2016-08-30
  • awk命令詳解

    簡介: wak是一個強大的文本分析工具,也可以叫做報告生成工具。相對于grep的查找,sed的編輯,awk在對其數據分析并生成報告時,顯得尤為強大。簡單來說awk就是把文件逐行的讀入,以空格 為默認分隔符將每行切片,切開的部分再進行各種分析處理。 awk有三個不同的版本:awk,nawk,gawk。我們目前所使用的awk一般指gawk,gawk是AWK和GN…

    Linux干貨 2016-11-28
  • Linus Torvalds 語錄 Top 10

    下面是Linux的創始人Linus Torvalds的一些言論,這是我個人認為最有意思的10句。如果你想看更多的Linus Torvalds說過的話,你可以看看他在維基百科上的詞條:Linux Torvalds。我們在下面給出中英文對照,希望你能喜歡。 “Really, I’m not out to dest…

    Linux干貨 2015-04-03
  • Linux發展史

    前言     Linux屬于類Unix中的一個當下比較流行的操作系統,占領了服務器大部分江山。作為一個專業復雜的操作系統,了解其發展過程是很有必要的。如果要講linux的歷史,肯定是從三個團體開發Multics系統說起,貝爾實驗室離開Multics項目后,Tompson和他的同事一起創造了unix,而在unix的各種分支中BSD則是迅速發…

    Linux干貨 2016-10-14
  • SHELL流程控制之循環

    當進行腳本編程時,語句執行的流程控制通常有三種: l  順序執行 l  選擇執行 l  循環執行   條件選擇if: if語句可以進行嵌套 if 判斷條件;then          條件為真的分支代碼 elif  判斷條件;th…

    Linux干貨 2016-08-18

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-09-19 19:04

    寫的很棒,給你點贊

欧美性久久久久