find && sed

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

find /etc -size +1M -type f

2、打包/etc/目錄下面所有conf結尾的文件,壓縮包名稱爲當天的時間,並拷貝到/usr/local/src目錄備份。

find /etc -type f -name "*conf" |xargs tar -zcvf /usr/local/src/`data +%F`.tar.gz

3、利用sed 取出ifconfig命令中本機的IPv4地址

ifconfig | sed -nr '2s/^.*inet\ ([1]?[0-9][0-9]\.[0-9]?[0-9][0-9]\.[0-9]?[0-9][0-9]\.([1]?[0-9][0-9]|[2][0-5][0-5])).*/\1/p'
ifconfig | sed -nr '2s/^.*inet\ (.*)\ netmask.*/\1/p'

4、刪除/etc/fstab文件中所有以#開頭,後面至少跟一個空白字符的行的行首的#和空白字符

sed -ri.bak 's/^#[ ]+(.*)/\1/' /etc/fstab

5、處理/etc/fstab路徑,使用sed命令取出其目錄名和基名

  • 目錄名:

    echo /etc/fstab |sed -nr 's#(.*)/(.*)#\1#p'

  • 基名:

    echo /etc/fstab |sed -nr 's#(.*)/(.*)#\2#p'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章