linux學習-練習2

1.顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間出現至少一位數字的文件或目錄


[root@CentOS7 ~]# ls -d /var/l*[[:digit:]]*[[:lower:]]

/var/l33a

2.顯示/etc目錄下以任意一位數字開頭,且以非數字結尾的文件或目錄


ls -d /etc/[[:gidit:]][^[:gidit:]]



3.顯示/etc目錄下以非字母開頭,後面跟了一個字母及其他任意長度任意字符的文件或目錄


ls -d /etc/[^[:alpha:]][[:alpha:]]*


4.顯示/etc目錄下所有以m開頭以非數字結尾的文件或目錄 


ls /etc/m*[^[:gidit:]]


5.顯示/etc目錄下,所有以.d結尾的文件或目錄


ls -d /etc/*.d


6.顯示/etc目錄下,所有.conf結尾,且以m,n,r,p開頭的文件或目錄


ls -d /etc/[mnrf]*.conf


1,使用別名命令,每日將/etc目錄下所有文件,備份到/testdir/下獨立日的新目錄下,並要求新目錄格式爲backupYYYY-mm-dd,備份過程可見


alias cpetc='cp -vrp /etc/ /testdir/date`date+%F`

alias cpetc='cp -vrp /etc/ /testdir/date&(date+%F)


2,先創建/testdir/rootdir目錄,在複製/root所有下文件到該目錄內,並要求保留原有權限


cp -rp /root/ /testdir/rootdir



1,如何創建/testdir/dir1/x,/testdir/dir1/y,/testdir/dir1/x/a,/testdir/dir1/x/b,/testdir/dir1/y/a,/testdir/dir1/y/b


mkdir -p /dir1/{x,y}/{a,b}

[root@CentOS7 ~]# tree dir1/

dir1/

├── x

│   ├── a

│   └── b

└── y

   ├── a

   └── b



2, 如何創建/testdir/dir2/x,/testdir/dir2/y,/testdir/dir2/x/a,/testdir/dir2/x/b


mkdir -p /testdir/dir2/{x/{a,b},y}

mkdir -p /testdir/dir2/{x,y/{a,b}}

[root@CentOS7 ~]# tree dir2

dir2

├── x

└── y

   ├── a

   └── b



3, 如何創建/testdir/dir3,/testdir/dir4,/testdir/dir5,/testdir/dir5/dir3,/testdir/dir5/dir4


mkdir -p /testdir/dir{3,4,5/dir{3,4}}

[root@CentOS7 ~]# tree ttt

ttt

├── dir3

├── dir4

└── dir5

   ├── dir3

   └── dir4



1,將/etc/issue文件中的內容轉換成打邂逅保存到/tmp/issue.out中


[root@Centos7 testdir]# cat /etc/issue | tr 'a-z' 'A-Z'> /testdir/xx

[root@Centos7 testdir]# cat xx


\S

KERNEL \R ON AN \M


THE HOSTNAME IS \N

LOGIN TERMINAL IS \L

THE TIME IS \T



2,將當前系統登錄用戶的信息轉換成大寫後保存到/tmp/who.out


[root@Centos7 testdir]# w | tr 'a-z' 'A-Z'> /testdir/xx.xx

[root@Centos7 testdir]# cat xx.xx 

14:04:47 UP  3:11,  3 USERS,  LOAD AVERAGE: 0.00, 0.01, 0.05

USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

ROOT     :0       :0               10:54   ?XDM?   1:58   0.40S GDM-SESSION-WORKER [PAM/GDM-AUTOLOGIN]

ROOT     PTS/0    :0               10:55    3:09M  0.06S  0.06S /BIN/BASH

ROOT     PTS/1    10.1.250.42      10:56    7.00S  0.84S  0.06S W



3,一個linux用戶給root發郵件,要求郵件標題爲“help”,郵件內容 HELLo,i am 用戶名 ,the system version is here, please help me to chech it , thanks!


[xhb88@Centos7 ~]$ mail -s "help" root  << eof

hi

i am `whoami`

the system version is here, please help me to chech it , thanks!

eof



4,將/root下文件列表 顯示成一行,並文件名之間用空格隔開


[root@Centos7 testdir]# ls -1 /root | tr '\n' ' '

anaconda-ks.cfg bc Desktop Documents Downloads file1 -h initial-setup-ks.cfg Music Pictures Public Templates tr Videos xx xx1 xx2 


5,file1文件內容爲: 1 2 3 4 5 6 7 8 9 10計算出所有數字的總和


[root@Centos7 testdir]# echo "1 2 3 4 5 6 7 8 9 10" > xx

[root@Centos7 testdir]# cat xx

1 2 3 4 5 6 7 8 9 10

[root@Centos7 testdir]# cat xx | tr ' ' '+' | bc

55


6,處理字符串 xt.l 1 jr#!$mn 2 c*/fe 3 uz 4,只保留其中的數字

       

        [root@Centos7 testdir]# cat kkkk 

xt.l 1 jr#!$mn 2 c*/fe 3 uz 4

[root@Centos7 testdir]# cat kkkk | tr -d [^[:alpha:]] | tr -d [^[:punct:]]

1  2  3  4


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