馬哥教育網絡班21期+第5周課程練習

1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;

[root@centos ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf 
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vg_centos-lv_root rd_NO_LUKS.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img

2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;

[root@centos ~]# grep "^#[[:space:]]\+[^[:space:]]" /etc/rc.d/rc.sysinit 
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg's bcheckrc.
# Check SELinux status
# Print a text banner.
# Only read this once.
# Initialize hardware
# Set default affinity
# Load other user-defined modules
# Load modules (for backward compatibility with VARs)
# Configure kernel parameters
# Set the hostname.
# Sync waiting for storage.
# Device mapper & related initialization
# Start any MD RAID arrays that haven't been started yet
# Remount the root filesystem read-write.
# Clean up SELinux labels
# If relabeling, relabel mount points.
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
# The 'no' applies to all listed filesystem types. See mount(8).
# Update quotas if necessary
# Check to see if a full relabel is needed
# Initialize pseudo-random number generator
# Configure machine if necessary.
# Clean out /.
# Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
# Clean up /var.
# Clean up utmp/wtmp
# Clean up various /tmp bits
# Make ICE directory
# Start up swapping.
# Set up binfmt_misc
# Boot time profiles. Yes, this should be somewhere else.
# Now that we have all of our basic modules loaded and the kernel going,
# let's dump the syslog ring somewhere so we can find it later
# create the crash indicator flag to warn on crashes, offer fsck with timeout
# Let rhgb know that we're leaving rc.sysinit

3、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;

[root@centos ~]# netstat -tan | grep "LISTEN[[:space:]]*$"
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      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:56665               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 :::51608                    :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN

4、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;

[root@centos ~]# grep "^\([[:alnum:]]\+\b\).*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt

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

[root@centos ~]# for i in root fedora user1; do grep "^$i" /etc/passwd | cut -d: -f1,7; done
root:/bin/bash
fedora:/bin/bash
user1:/bin/bash

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

[root@centos ~]# grep "\b[[:alpha:]]\+\b()" /etc/rc.d/init.d/functions 
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {
confirm() {

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

[root@centos ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" | grep -E -o "[^/]+/?$" | cut -d"/" -f1
ifcfg-eth0

    擴展:取出其路徑名

[root@centos ~]# echo "/etc/rc.d/rc.sysinit" | egrep -o  "^(/.*/)"
/etc/rc.d/

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

[root@centos ~]# ifconfig | egrep -o "\b`for i in {1..256};do echo $i; done;`" 
29
7
51
192
168
40
128
192
168

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

[root@centos ~]# ifconfig | egrep -o "[1-2][0-9]?[0-9]?.[0-2]?[0-9]?[0-9].[0-2]?[0-9]?[0-9].[0-2]?[0-9]?[0-9]"
192.168.40.128
192.168.40.255
255.255.255.0
127.0.0.1
255.0.0.0

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

[root@centos ~]# cat mailaddress
#yuan@baidu.com
yuan_xin@baidu.com.cn
smith@top.com__
3982294699@qq.com
xinixn@sina.com
[root@centos ~]# cat mailaddress | egrep  "^[[:alnum:]].*@[[:alnum:]]+[.].*[[:alnum:]]$"
yuan_xin@baidu.com.cn
3982294699@qq.com
xinixn@sina.com

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

[root@centos ~]# find /var/ -user root -a -group mail 
/var/spool/mail

12、查找當前系統上沒有屬主或屬組的文件;

[root@centos ~]# find / -nouser -o -nogroup -type f
find: `/proc/3658/task/3658/fd/5': No such file or directory
find: `/proc/3658/task/3658/fd/5': No such file or directory
find: `/proc/3658/task/3658/fdinfo/5': No such file or directory
find: `/proc/3658/task/3658/fdinfo/5': No such file or directory
find: `/proc/3658/fd/5': No such file or directory
find: `/proc/3658/fd/5': No such file or directory
find: `/proc/3658/fdinfo/5': No such file or directory
find: `/proc/3658/fdinfo/5': No such file or directory

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

[root@centos ~]# find / -nouser -o -nogroup  -a -atime -3
find: `/proc/2535/task/2535/fd/5': No such file or directory
find: `/proc/2535/task/2535/fd/5': No such file or directory
find: `/proc/2535/task/2535/fdinfo/5': No such file or directory
find: `/proc/2535/task/2535/fdinfo/5': No such file or directory
find: `/proc/2535/fd/5': No such file or directory
find: `/proc/2535/fd/5': No such file or directory
find: `/proc/2535/fdinfo/5': No such file or directory
find: `/proc/2535/fdinfo/5': No such file or directory

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

[root@centos ~]# find /etc -perm -222 -exec ls -l {} \;
lrwxrwxrwx. 1 root root 10 Jun  2 18:13 /etc/rc5.d -> rc.d/rc5.d
lrwxrwxrwx. 1 root root 14 Jun  2 18:13 /etc/system-release -> centos-release
lrwxrwxrwx. 1 root root 19 Jun  2 18:25 /etc/pam.d/fingerprint-auth -> fingerprint-auth-ac
lrwxrwxrwx. 1 root root 25 Jun  2 18:14 /etc/pam.d/smtp -> /etc/alternatives/mta-pam
lrwxrwxrwx. 1 root root 14 Jun  2 18:25 /etc/pam.d/system-auth -> system-auth-ac
lrwxrwxrwx. 1 root root 16 Jun  2 18:25 /etc/pam.d/password-auth -> password-auth-ac
lrwxrwxrwx. 1 root root 17 Jun  2 18:25 /etc/pam.d/smartcard-auth -> smartcard-auth-ac
lrwxrwxrwx. 1 root root 10 Jun  2 18:13 /etc/rc3.d -> rc.d/rc3.d
lrwxrwxrwx. 1 root root 10 Jun  2 18:13 /etc/rc6.d -> rc.d/rc6.d

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

[root@centos ~]# find /etc/ -type f -size +1M 
/etc/selinux/targeted/modules/active/policy.kern
/etc/selinux/targeted/policy/policy.24
/etc/gconf/gconf.xml.defaults/%gconf-tree.xml
[root@centos ~]# find /etc/ -type f -size +1M -exec ls -lh {} \;
-rw-r--r--. 1 root root 7.8M Jun  2 18:17 /etc/selinux/targeted/modules/active/policy.kern
-rw-r--r--. 1 root root 7.8M Jun  2 18:17 /etc/selinux/targeted/policy/policy.24
-rw-r--r--. 1 root root 2.2M Jun  2 18:21 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml

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

[root@centos ~]# find /etc/init.d/ -perm -113 -exec ls -lh {} \;

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

[root@centos ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)

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

[root@centos ~]# find /etc/  -not -perm -222 -ls | less
260098   12 drwxr-xr-x 118 root     root        12288 Jul 23 10:27 /etc/
260242    4 -rw-r--r--   1 root     root          801 Jul 19  2011 /etc/gssapi_mech.conf
260103    4 drwxr-xr-x   2 root     root         4096 Jun  2 18:19 /etc/modprobe.d
260106    4 -rw-r--r--   1 root     root           52 Jun  2 18:06 /etc/modprobe.d/anaconda.conf
260348    4 -rw-r--r--   1 root     root          884 Oct 16  2014 /etc/modprobe.d/blacklist.conf
260345    4 -rw-r--r--   1 root     root          382 Oct 15  2014 /etc/modprobe.d/dist-alsa.conf
260347    8 -rw-r--r--   1 root     root         5596 Oct 15  2014 /etc/modprobe.d/dist.conf
273795    4 -rw-r--r--   1 root     root           30 Oct 10  2009 /etc/modprobe.d/openfwwf.conf
260346    4 -rw-r--r--   1 root     root          473 Oct 15  2014 /etc/modprobe.d/dist-oss.conf
264283    4 -rw-r--r--   1 root     root          524 Oct 16  2014 /etc/auto.misc
260162    4 -rw-r--r--   1 root     root          272 Nov 18  2009 /etc/mailcap

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

[root@centos ~]# find /etc/  -mtime -7 -a  -not \( -user root -o -user hadoop\)

原創文章,作者:Snoo,如若轉載,請注明出處:http://www.www58058.com/25230

(0)
SnooSnoo
上一篇 2016-07-29
下一篇 2016-07-29

相關推薦

  • btrfs文件系統

                                                      &nbsp…

    Linux干貨 2015-08-21
  • Linux 系統中screen命令不能使用的解決辦法,screen包的正確安裝

           有些同學可能在安裝完Linux發行版之后,發現screen功能不能實現,這是因為是實現該功能的包在安裝系統的過程中沒有安裝上,這里我根據自己的經驗介紹兩種安裝screen包的方法,用來你實現screen命令。 方法一、     條件:連網狀態;   &nb…

    2017-07-12
  • 目錄,inode學習筆記

    目錄,inode學習筆記 1. 關于目錄,文件,數據塊 對于使用計算機的人而言,經常有一種 錯誤的認知:目錄(或者說,文件夾)里面存放著文件。實際上,目錄里面并不存放文件,以及文件數據。 實際上,目錄是一個特殊的文件,針對這個特殊的文件也存在一些特殊的規則,比如利用命令cp /dev/null <your directory>…

    Linux干貨 2017-04-01
  • CentOS下命令基礎練習

    馬哥教育網絡班23期+第五周課堂作業 CentOS下命令基礎練習 1、顯示當前系統上root、fdeora或user1用戶的默認shell 2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello() 3、使用echo命令輸出一個絕對路徑 使用grep取出其基名 擴展:取出其路徑名 (…

    Linux干貨 2016-10-24
  • Linux用戶、組管理和正則表達式的基礎命令

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其他用戶均沒有任何權限 [root@localhost skel]# cp -r /etc/skel /home/tuser1 [root@localhost skel]# ls -al /home/tuser1 total 12 drwxr-xr-x.…

    Linux干貨 2017-07-20
  • linux命令的使用格式

    Linux命令的一般格式為: [root@node1 ~]#command [選項] [參數] 1、ifconfig 設備 參數 參數: up:啟動指定設備 down:關閉指定設備 arp:指定設備是否支持ARP協議 -a:顯示全部接口信息 例如:[root@node1 ~]#ifconfig eth0 up #啟動eth0網卡 2、echo打印 &nbsp…

    Linux干貨 2016-09-17

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-07-29 15:48

    寫的很好,排版也很棒,第8題不是我們要的結果,在想象,用grep做。加油

欧美性久久久久