練習06

20170523
1、顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間出現至少一位數字的文件或目錄
ls 1[[:digit:]][[:lower:]]
2、顯示/etc目錄下以任意一位數字開頭,且以非數字結尾的文件或目錄
ls -d /etc/[[:digit:]][^[:digit:]]
3、顯示/etc/目錄下以非字母開頭,后面跟了一個字母及其它任意長度任意字符的文件或目錄
ls -d /etc/[^[:alpha:]][[:alpha:]]

4、顯示/etc/目錄下所有以rc開頭,并后面是0-6之間的數字,其它為任意字符的文件或目錄
ls -d /etc/rc[0-6]*
5、顯示/etc目錄下,所有以.d結尾的文件或目錄
ls -d /etc/.d
6、顯示/etc目錄下,所有.conf結尾,且以m,n,r,p開頭的文 件或目錄
ls -d /etc/[mnrp]
.conf
7、只顯示/root下的隱藏文件和目錄
ls -aI "[^.]" /root
ls -a --ignore=[^.]
/root
8、只顯示/etc下的非隱藏目錄
ll /etc/ | grep ^d
ls -d /etc/*/

1、對/etc/passwd 取用戶名和UID,并對UID倒序排序
cut -d: -f1,3 /etc/passwd|sort -t: -k2 -nr

2、取分區(qū)利用率最大值
df |tr -s " " %|cut -d% -f5|sort -nr|head -n1
df -i |tr -s " " %|cut -d% -f5|sort -nr|head -n1

3、取出http服務訪問次數最高的IP
cut -d" " -f1 /var/log/httpd/access_log |sort|uniq -c| sort -nr|head -n1|tr -s " "|cut -d" " -f3

4、取出UID最大的用戶,UID和shell
sort -t: -k3 -n /etc/passwd|tail -n1|cut -d: -f1,3,7

5、取/tmp/數字權限
stat /tmp|head -n4|tail -n1|cut -d "(" -f2|cut -d / -f1

6、取/mnt/Packages下rpm包的編譯版本
ls *.rpm |rev|cut -d. -f2|rev|sort |uniq -c
ls rpm|egrep -o "<[_0-9a-zA-Z].rpm" |cut -d. -f1|sort |uniq -c
ls *rpm|egrep -o "<[^.]+.rpm" |cut -d. -f1|sort |uniq -c
ls *rpm|egrep -o "[^.]+.rpm" |cut -d. -f1 |sort |uniq -c


7、卸載rpm包,并恢復
rpm -e rpm --nodeps

20170525
1、cmd linkfile
readlink 文件


2 硬,軟鏈接的區(qū)別
硬鏈接
硬鏈接必須在同一個分區(qū)中創(chuàng)建,不能跨分區(qū),跨分區(qū)只能用軟鏈接
硬鏈接不支持對目錄創(chuàng)建
不復制原數據,僅分配一個inode號和文件名
鏈接文件跟原文件使用同一個inode號
硬鏈接工作的相對路徑相對于當前目錄
鏈接文件沒有依賴性關系,鏈接數會隨著鏈接次數增加加1,
軟鏈接
可以對目錄進行
可以跨分區(qū)
指向的是另一個文件的路徑;其大小為指向的路徑字符串的長度;不增加或減少目標文件inode的引用計數;
inode號跟原文件不一致,會分配其他的inode號
刪除鏈接原文件,則鏈接指向失效
軟鏈接用相對路徑時相對的不是當前工作目錄,而是相對軟鏈接工作路徑
3、將/etc/issue文件中的內容轉換為大寫后保存至/tmp/issue.out文件中
tr 'a-z' 'A-Z' </etc/issue >/tmp/issue.out
4、將當前系統(tǒng)登錄用戶的信息轉換為大寫后保存至/tmp/who.out文件中
who | tr 'a-z' 'A-Z' > /tmp/who.out
5、一個linux用戶給root發(fā)郵件,要求郵件標題為”help”,郵件正文如下:
Hello, I am 用戶名,The system version is here,pleasehelp me to check it
,thanks!
操作系統(tǒng)版本信息
(echo "hello,I am $USER,the system version is here,pleasehelp me to check it,thnaks! ";uname -o) | mail -s "hello" root
6、將/root/下文件列表,顯示成一行,并文件名之間用空格隔開
ls /root | tr -s '\n' ' '
7、計算1+2+3+..+99+100的總和
echo {1..100} | tr -s ' ' '+' | bc
8、刪除Windows文本文件中的‘^M’字符
tr -s '^M' ' ' < qq.txt
9、處理字符串“xt.,l 1 jr#!$mn2 c/fe3 uz4”,只保留其中的數字和空格
echo ‘xt.l 1 jr#cdmn2 ,,,c
/fe3 uz4’ | tr -dc '[:digit:][:space:]'
10、將PATH變量每個目錄顯示在獨立的一行
echo $PATH | tr ':' '\n'
11、將指定文件中0-9分別替代成a-j
tr -t [0-9] [a-j] < q
12、將文件中每個單詞(由字母組成)顯示在獨立的一行,并無空行
tr -s ' :' '\n' < q

20170531
1 、顯示/proc/meminfo 文件中以大小s 開頭的行( 要求:使用兩種方法)
cat /proc/meminfo | grep -i ^s
cat /proc/meminfo | grep ^[Ss]
grep -e ^s -e ^S /proc/meminfo
2 、顯示/etc/passwd 文件中不以/bin/bash 結尾的行
grep -v /bin/bash$ /etc/passwd
3 、顯示用戶rpc 默認的shell 程序
grep ^danran> /etc/passwd | cut -d: -f7
4 、找出/etc/passwd 中的兩位或三位數
grep "<[0-9]{2,3}>" /etc/passwd
5 、顯示CentOS7 的/etc/grub2.cfg 文件中,至少以一個空白字符開頭的且后面存非空白字符的行
grep '[[:space:]]+[[:space:]]' /etc/grub2.cfg
6 、找出“netstat -tan” 命令的結果中以‘LISTEN’ 后跟任意多個空白字符結尾的行
netstat -tan | grep 'LISTEN[[:space:]]$'
7 、顯示CentOS7 上所有系統(tǒng)用戶的用戶名和UID
cut -d: -f1,3 /etc/passwd | grep '<[0-9]{1,3}>'|grep -v root
8 、添加用戶bash 、testbash 、basher 、sh 、nologin( 其shell為/sbin/nologin), 找出/etc/passwd 用戶名同shell 名的行
grep '^(.
):.\1$' /etc/passwd
grep '(^[[:alnum:]]+>).
\1$' /etc/passwd
9 、利用df 和grep ,取出磁盤各分區(qū)利用率,并從大到小排序

1 、顯示三個用戶root 、mage 、wang 的UID 和默認shell
egrep '^(danran|dan)' /etc/passwd | cut -d: -f 1,7
2 、找出/etc/rc.d/init.d/functions 文件中行首為某單詞(包括下劃線) 后面跟一個小括號的行
egrep '^([[:alnum:]]|)+()' -o /etc/rc.d/init.d/functions
grep -E -o '^[
[:alpha:]]+()' /etc/rc.d/init.d/functions
3 、使用egrep 取出/etc/rc.d/init.d/functions 中其基名
echo /etc/rc.d/init.d/functions | egrep -o '[^/]+$'
echo '/mnt/sdc' | grep -o -E '[^/]+?$'
4 、使用egrep 取出上面路徑的目錄名‘
echo /etc/rc.d/init.d/functions | egrep -o '.<'
echo /etc/rc.d/init.d/functions | egrep -o '^/.
/'
echo '/mnt/sdc' | grep -o -E '/.*/[ ]' | egrep -o '^/./'
5 、統(tǒng)計last 命令中以root 登錄的每個主機IP 地址登錄次數
last | egrep -o '^root>.
[0-9].[0-9]{1,3}' |tr -s ' ' | cut -d' ' -f3|sort -n | uniq -c
last | egrep '^root>.*[0-9].[0-9]{1,3}' | egrep -o '([0-9]{1,3}.){3}[0-9]{1,3}'| sort -n | uniq -c
6 、利用擴展正則表達式分別表示0-9 、10-99 、100-199、 、200-249 、250-255

7 、顯示ifconfig 命令結果中所有IPv4 地址
ifconfig | egrep -o '([0-9]{1,3}.){3}[0-9]{1,3}'
8 、將此字符串:welcome to magedu linux 中的每個字符去重并排序,重復次數多的排到前面
echo 'welcome to danran' | grep -o '.' | sort | uniq -c | sort

1 、復制/etc/profile 至/tmp/ 目錄,用查找替換命令刪除/tmp/profile 文件中的行首的空白字符
2 、復制/etc/rc.d/init.d/functions 文件至/tmp 目錄,用查找替換命令為/tmp/functions 的每行開頭為空白字符的行的行首添加一個#號
3、在vim 中設置tab 縮進為4 個字符
4 、復制/etc/rc.d/init.d/functions 文件至/tmp 目錄,替換/tmp/functions 文件中的/etc/sysconfig/init 為/var/log
5 、刪除/tmp/functions 文件中所有以# 開頭,且# 后面至少有一個空白字符的行的行首的#號

20170608
1、編寫腳本/bin/per.sh,判斷當前用戶對指定的參數文件,是否不可讀并且不可寫
#!/bin/bash
# filename per.sh
# author:danran
# time is 2017-06-08
[ ! -r $1 -a ! -w $1 ] && echo "$1 file not read and not write"
2、編寫腳本/root/bin/excute.sh ,判斷參數文件是否為sh后綴的普通文件,如果是,添加所有人可執(zhí)行權限,否則提示用戶非腳本文件
#!/bin/bash
# filename excute.sh
# author:danran
# time is 2017-06-08
[ $# == 0 ] && read -p "please input fimename" name || name=$1
[ -f $name ] && [[ "$name" =~ .sh$ ]] && chmod a+x $name || echo "$name not scripts file"
3、查找/var目錄下屬主為root,且屬組為mail的所有文件
find /var -user root -group mail
4、查找/var目錄下不屬于root、lp、gdm的所有文件
-find /var ! ( -user root -a -user lp -a -user mail )
5、查找/var目錄下最近一周內其內容修改過,同時屬主不為root,也不是postfix的文件
find /var -ctime -7 -not ( -user root -a -user postfix )
6、查找當前系統(tǒng)上沒有屬主或屬組,且最近一個周內曾被訪問過的文件
find / -atime -7 -nouser -o -nogroup
7、查找/etc目錄下大于1M且類型為普通文件的所有文件
find /etc/ -size +1M -type f
8、查找/etc目錄下所有用戶都沒有寫權限的文件
find /etc -not -perm /222
9、查找/etc目錄下至少有一類用戶沒有執(zhí)行權限的文件
find /etc -not -perm -111
10、查找/etc/init.d目錄下,所有用戶都有執(zhí)行權限,且其它用戶有寫權限的文件
find /etc/init.d/ -perm -111 -perm -002

20170609
1、rm -f /usr/bin/tree,用兩種方法恢復之
方法一
rpm2cpio /mnt/Packages/tree* | cpio -tv 預覽查看tree包中的文件
rpm2cpio /mnt/Packages/tree* | cpio -id ./usr/bin/tree 單獨解壓./usr/bin/tree文件到當前目錄
cp usr/bin/tree /usr/bin



方法二:
rpm -ivh tree-1.6.0-10.el7.x86_64.rpm --replacepkgs 重新安裝tree包
2、/usr/bin/java來自哪個rpm包
rpm -q --whatprovides java


3、開機創(chuàng)鍵yum庫文件的腳本reset.sh

!/bin/bash

mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo << EOF
[base]
name=danran
baseurl=file:///mnt
gpgcheck=0
enabled=1
EOF

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • 轉載自:http://www.shiyanbar.com/questions/980系統(tǒng)信息 arch 顯示機器的...
    systeminfo閱讀 2,656評論 0 0
  • linux資料總章2.1 1.0寫的不好抱歉 但是2.0已經改了很多 但是錯誤還是無法避免 以后資料會慢慢更新 大...
    數據革命閱讀 13,216評論 2 33
  • groupadd,useradd,passwd,gpasswd,id,su groupadd image.png ...
    香吉矢閱讀 3,562評論 0 3
  • 正則表達式 關于正則表達式相信很多學計算機的人都聽說過 尤其是做編程行業(yè)的人 那什么是正則表達式 正則表達式,又稱...
    數據革命閱讀 992評論 0 1
  • 然后你又夢到了那個女人 幼獸一般純潔無害 沙漠中海市蜃樓一般變幻 追逐獵物一樣兇殘 朝露落于櫻桃上那樣誘人 薄霧朦...
    懸劍閣主閱讀 235評論 0 0

友情鏈接更多精彩內容