第五週作業

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

grep -E '^root|fedora|allan:' /etc/passwd |cut -d: -f1,7  #顯示root,allan默認shell

root:/bin/bash

allan:/bin/bash


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

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取出其基名;

echo '/etc/networks' | egrep -o '[[:alpha:]]+/?$' | cut -d/ -f1

networks

    擴展:取出其路徑名

echo '/etc/networks' | egrep -o '.*/'

/etc/

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

ifconfig | egrep '\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>

inet 192.168.113.128  netmask 255.255.255.0  broadcast192.168.113.255

        inet6 fe80::20c:29ff:fe58:9f08  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:58:9f:08  txqueuelen 1000  (Ethernet)

        RX packets 1232  bytes 110338 (107.7 KiB)

        TX packets 877  bytes 95121 (92.8 KiB)

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>

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

((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)

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

var  reEmail=/^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;

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

find /var/ -user root -a -group mail -ls

16819288    4 drwxrwxr-x   2 root     mail         4096 Aug 29 11:30 /var/spool/mail

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

find / -nouser -a -nogroup -ls

find: ‘/proc/3426/task/3426/fd/6’: No such file or directory

find: ‘/proc/3426/task/3426/fdinfo/6’: No such file or directory

find: ‘/proc/3426/fd/6’: No such file or directory

find: ‘/proc/3426/fdinfo/6’: No such file or directory

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

find / -nouser -a -nogroup -a -atime -3 -exec stat {} \;

find: ‘/proc/3433/task/3433/fd/6’: No such file or directory

find: ‘/proc/3433/task/3433/fdinfo/6’: No such file or directory

find: ‘/proc/3433/fd/6’: No such file or directory

find: ‘/proc/3433/fdinfo/6’: No such file or directory

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

find /etc -perm -222 -ls>/tmp/findperm

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

find /etc/ -size +1M -a -type f -exec ls -lh {} \;

-r--r--r--. 1 root root 6.7M Aug 12 14:11 /etc/udev/hwdb.bin

-rw-r--r--. 1 root root 3.7M Nov 21  2015 /etc/selinux/targeted/policy/policy.29

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

find /etc/init.d/ -perm -113 -ls

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

find /usr/ -not \( -user root -o -user bin -o -user hadoop \) -ls

462063    0 drwx------   2 polkitd  root            6 Jun 10  2014 /usr/share/polkit-1/rules.d

26046807   16 -rwsr-sr-x   1 abrt     abrt        15336 Dec  1  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cach

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

find ./ -not -perm -222 -ls

25165953    4 dr-xr-x---   2 root     root         4096 Aug 30 12:03 ./

26768063    4 -rw-r--r--   1 root     root           18 Dec 29  2013 ./.bash_logout

26870528    4 -rw-r--r--   1 root     root          176 Dec 29  2013 ./.bash_profile

26870529    4 -rw-r--r--   1 root     root          176 Dec 29  2013 ./.bashrc

26870530    4 -rw-r--r--   1 root     root          100 Dec 29  2013 ./.cshrc

26870531    4 -rw-r--r--   1 root     root          129 Dec 29  2013 ./.tcshrc

26873169    4 -rw-------   1 root     root         1548 Aug 12 13:50 ./anaconda-ks.cfg

26873181   12 -rw-------   1 root     root        11886 Aug 29 16:52 ./.bash_history

26880279    0 -rw-r--r--   1 root     root            0 Aug 30 12:03 ./findnouser

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

find ./ -mtime -7 -a -not \( -user root -o -user hadoop \) -ls
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章