1.显示/var目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件或目录
[[email protected] ~]# 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}
[[email protected] ~]# 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}}
[[email protected] ~]# 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}}
[[email protected] ~]# tree ttt
ttt
├── dir3
├── dir4
└── dir5
├── dir3
└── dir4
1,将/etc/issue文件中的内容转换成打邂逅保存到/tmp/issue.out中
[[email protected] testdir]# cat /etc/issue | tr ‘a-z‘ ‘A-Z‘> /testdir/xx
[[email protected] 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
[[email protected] testdir]# w | tr ‘a-z‘ ‘A-Z‘> /testdir/xx.xx
[[email protected] testdir]# cat xx.xx
14:04:47 UP 3:11, 3 USERS, LOAD AVERAGE: 0.00, 0.01, 0.05
USER TTY FROM [email protected] 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!
[[email protected] ~]$ mail -s "help" root << eof
hi
i am `whoami`
the system version is here, please help me to chech it , thanks!
eof
4,将/root下文件列表 显示成一行,并文件名之间用空格隔开
[[email protected] 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计算出所有数字的总和
[[email protected] testdir]# echo "1 2 3 4 5 6 7 8 9 10" > xx
[[email protected] testdir]# cat xx
1 2 3 4 5 6 7 8 9 10
[[email protected] testdir]# cat xx | tr ‘ ‘ ‘+‘ | bc
55
6,处理字符串 xt.l 1 jr#!$mn 2 c*/fe 3 uz 4,只保留其中的数字
[[email protected] testdir]# cat kkkk
xt.l 1 jr#!$mn 2 c*/fe 3 uz 4
[[email protected] testdir]# cat kkkk | tr -d [^[:alpha:]] | tr -d [^[:punct:]]
1 2 3 4