1、显示/var目录下所有以l开头,以一个小写字母结尾,且中间至少出现一位数字(可以有其它字符)的文件或目录。
ls -d /var/l*[0-9]*[[:lower:]]或ls -d /var/l*[[:digit:]]*[[:lower:]]
命令测试结果
[[email protected] Desktop]# touch /var/l0a /var/la1Ab /var/lAB2abc [[email protected] Desktop]# ls -d /var/l*[0-9]*[[:lower:]] /var/l0a /var/la1Ab /var/lAB2abc [[email protected] Desktop]# ls -d /var/l*[[:digit:]]*[[:lower:]] /var/l0a /var/la1Ab /var/lAB2abc
2、显示/etc目录下,以任意一个数字开头,且以非数字结尾的文件或目录。
ls -d /etc/[0-9]*[^0-9]或ls -d /etc/[[:digit:]]*[^[:digit:]]
命令测试及结果
[[email protected] Desktop]# touch /etc/[email protected] /etc/1#Bb [[email protected] Desktop]# ls -d /etc/[0-9]*[^0-9] /etc/[email protected] /etc/1#Bb [[email protected] Desktop]# ls -d /etc/[[:digit:]]*[^[:digit:]] /etc/[email protected] /etc/1#Bb
3、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录。
ls -d /etc/[^a-zA-Z][a-zA-Z]*或ls -d /etc/[^[:alpha:]][[:alpha:]]*
命令测试及结果
[[email protected] Desktop]# touch /etc/[email protected] /etc/#z3c4D [[email protected] Desktop]# ls -d /etc/[^a-zA-Z][a-zA-Z]* /etc/[email protected] /etc/[email protected] /etc/#z3c4D [[email protected] Desktop]# ls -d /etc/[^[:alpha:]][[:alpha:]]* /etc/[email protected] /etc/[email protected] /etc/#z3c4D
4、在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile-2016-05-27-09-32-22。
touch /tmp/tfile-$(date +%F-%H-%M-%S)或touch /tmp/tfile-`date +%Y-%m-%d-%H-%M-%S`
命令测试及结果
[[email protected] Desktop]# touch /tmp/tfile-$(date +%F-%H-%M-%S) [[email protected] Desktop]# touch /tmp/tfile-`date +%Y-%m-%d-%H-%M-%S` [[email protected] Desktop]# ls /tmp/tfile* /tmp/tfile-2017-05-12-09-50-18 /tmp/tfile-2017-05-12-09-50-23
5、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
cp -r /etc/p*[^0-9] /tmp/mytest1或cp -r /etc/p*[^[:digit:]] /tmp/mytest1
命令测试及结果
[[email protected] Desktop]# mkdir -p /tmp/mytest1 ; cp -r /etc/p*[^0-9] /tmp/mytest1 ; ls /tmp/mytest1 pam.d pbm2ppa.conf plymouth popt.d prelink.conf.d profile.d purple passwd pinforc pm postfix printcap protocols passwd- pki pnm2ppa.conf ppp profile pulse [[email protected] Desktop]# rm -rf /tmp/mytest1 ; mkdir -p /tmp/mytest1 ; cp -r /etc/p*[^[:digit:]] /tmp/mytest1 ; ls /tmp/mytest1 pam.d pbm2ppa.conf plymouth popt.d prelink.conf.d profile.d purple passwd pinforc pm postfix printcap protocols passwd- pki pnm2ppa.conf ppp profile pulse
6、复制/etc目录下所有以.d结尾的文件或目录至/tmp/mytest2目录中。
cp -r /etc/*.d /tmp/mytest2
命令测试及结果
[[email protected] Desktop]# mkdir -p /tmp/mytest2 ; cp -r /etc/*.d /tmp/mytest2 ; ls /tmp/mytest2 bash_completion.d ipsec.d profile.d rwtab.d binfmt.d ld.so.conf.d rc0.d sane.d chkconfig.d libibverbs.d rc1.d setuptool.d cron.d logrotate.d rc2.d statetab.d depmod.d modprobe.d rc3.d sudoers.d dnsmasq.d modules-load.d rc4.d sysctl.d dracut.conf.d my.cnf.d rc5.d tmpfiles.d exports.d oddjobd.conf.d rc6.d usb_modeswitch.d gdbinit.d pam.d rc.d xinetd.d grub.d popt.d request-key.d yum.repos.d init.d prelink.conf.d rsyslog.d
7、复制/etc/目录下所有以l或m或n开头,以.conf结尾的文件至/tmp/mytest3目录中。
cp -r /etc/[lmn]*.conf /tmp/mytest3或cp -r /etc/{l,m,n}*.conf /tmp/mytest3
命令测试及结果
mkdir -p /tmp/mytest3 ; cp -r /etc/[lmn]*.conf /tmp/mytest3 ; ls /tmp/mytest3 ld.so.conf locale.conf mke2fs.conf nsswitch.conf libaudit.conf logrotate.conf mtools.conf numad.conf libuser.conf man_db.conf nfsmount.conf rm -rf /tmp/mytest3 ; mkdir -p /tmp/mytest3 ; cp -r /etc/{l,m,n}*.conf /tmp/mytest3 ; ls /tmp/mytest3 ld.so.conf locale.conf mke2fs.conf nsswitch.conf libaudit.conf logrotate.conf mtools.conf numad.conf libuser.conf man_db.conf nfsmount.conf