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

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

[root@rhel677850 ~]# grep "^\(root\|fedora\|user1\)" /etc/passwd|awk -F: '{print $1,$7}'
root /bin/bash
[root@rhel677850 ~]# egrep "^(root|fedora|user1)" /etc/passwd|awk -F: '{print $1,$7}'
root /bin/bash

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

[root@rhel677850 ~]# egrep "[[:alpha:]]+\(\)" /etc/rc.d/init.d/functions
fstab_decode_str() {
checkpid() {
__readlink() {
__fgrep() {
__umount_loop() {
__umount_loopback_loop() {
__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() {
action_silent() {
strstr() {
confirm() {
get_numeric_dev() {
is_ignored_file() {
is_true() {
is_false() {
apply_sysctl() {
key_is_random() {
find_crypto_mount_point() {
init_crypto() {

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

[root@rhel677850 ~]# echo "/etc/passwd"|grep -o "[^/]\+$"
passwd
使用grep取路徑名
[root@rhel677850 ~]# echo "/etc/passwd"|grep -o ".*/"
/etc/

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

[root@rhel677850 ~]# ifconfig | egrep -o "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|[2[0-4][0-9]|25[0-5]])\>"

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

[root@rhel677850 ~]# ifconfig | egrep -o "(\<([1-9]|[1-9][0-9]|1[0-9][0-9]|[2[0-4][0-9]|25[0-5]])\>\.){3}\<([1-9]|[1-9][0-9]|1[0-9][0-9]|[2[0-4][0-9]|25[0-5]])\>"
10.31.78.50

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

[root@rhel677850 ~]# egrep "[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"   mail.txt
zhangxialoa@mageedu.com
318810@qq.com

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

[root@rhel677850 ~]# ls -l /var | awk '/\<root mail\>/{print $NF}'

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

[root@rhel677850 ~]# find / -nouser -a -nogroup

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

[root@rhel677850 ~]# find / -nouser -a -nogroup

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

[root@rhel677850 ~]# find / -perm -222

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

[root@rhel677850 ~]# find /etc/ -size +1M -type f
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/selinux/targeted/modules/active/policy.kern
/etc/selinux/targeted/policy/policy.24
/etc/gconf/gconf.xml.defaults/%gconf-tree.xml

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

[root@rhel677850 ~]# find /etc/init.d -perm -113
/etc/init.d

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

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

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

[root@rhel677850 ~]# find /etc/ -not -perm -222

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

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

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

(0)
zhangxiaolazhangxiaola
上一篇 2016-09-26
下一篇 2016-09-26

相關推薦

  • 學習試題演練

    1.寫一個腳本實現:提示用戶給出自己的選擇隨后顯示對應的信息。 區分大小寫: if [[ "$option" =~ [Dd][Ii][Ss][Kk] ]];then 2.根據id號來判斷用戶類型,若沒有則提示沒有此用戶 0:管理員 1-999:系統用戶 1000+:登陸用戶 不得不提下: bash -n usertype.sh 前期擅用是…

    Linux干貨 2016-08-21
  • 磁盤管理之swap,移動設備及dd命令的使用

    首先我們來復習一下前一天的內容 CHS Sector(扇區) 512字節 track(磁道) 63個 2^6個扇區 1024個磁道,10個位存儲磁道數 track=cylinder(柱面) cylinder=(容量)sector(512)track(63)head(256)=8M head(磁頭) 256 8位存儲 MBR的分區方式都是基于柱面為整…

    Linux干貨 2016-09-07
  • LAMP分離環境的搭建(最新版本的mysql+php+http源碼編譯安裝)

    實驗者:FrankStar      實驗日期:20150628 任務:主要是實現在Linux環境下配置LAMP環境,利用VMware+centos6.4實現,將LAMP分離為多臺主機; 附注:由于大家的環境不一樣,可能有些人已經安裝了這個包或者那個軟件,所以調試的環境結果也不一樣,為了盡量能模擬到 可能出現的所有問題,在編譯會…

    Linux干貨 2015-06-30
  • Linux磁盤管理命令

    Linux有著管理各種存儲設備的強大能力。Linux把所有磁盤都當作文件管理,從而簡化我們對其進行的讀寫等操作。 IDE接口的硬盤在Linux中命名為:/dev/hd{a|b|c……},比如/dev/hda; 其他硬盤比如SATA接口的硬盤命名為:/dev/sd{a|b|c……},比如/dev/sda。 注:{…

    Linux干貨 2015-12-06
  • 軟件包管理

    軟件運行與編譯過程:程序源代碼——預處理——-編譯——-匯編——-鏈接 靜態編譯:.a 動態編譯:.so 二進制程序的組成:二進制文件、庫文件、配置文件、幫助文件。 包的命名:1、源代碼:name -VERSION.tar.gz或bz2或xz   &nb…

    Linux干貨 2017-04-23
  • 自動化運維跟安全配置

    安全相關工具rpm -qf /usr/bin/sshopenssh semanage port -a -t ssh_port_t -p tcp #PORTNUMBER/端口9527修改ssh的默認端口,ssh默認只能用22端口多臺主機互聯免口令1 ssh-keygen三臺主機各自生成私鑰公鑰2 ssh-copy-id IP7三臺主機各自復制公鑰到同一臺主機3…

    2018-02-06

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-09-27 09:56

    寫的很好,看的出來很用心,不過還是要注意排版的問題,希望繼續保持

欧美性久久久久