- 顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其它字符)的文件或目錄。
[root@localhost tmp]# ls -d /var/l*[[:lower:]]
- 顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。
[root@localhost tmp]# ls -d /etc/[0-9]*[^0-9]
- 顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄。
[root@localhost tmp]# ls -d /etc/[^a-z][a-z]*
- 在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22。
[root@localhost tmp]# mkdir tfile-$(date +%Y-%m-%d-%H-%M-%S)
- 復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中。
[root@localhost ~]# cp -r /etc/p*[^0-9] /tmp/mysest1/ [root@localhost ~]# ls /tmp/mysest1/ pam.d passwd- plymouth popt.d ppp printcap profile.d python passwd pki pm postfix prelink.conf.d profile protocols
- 復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中。
[root@localhost ~]# cp -rv /etc/*.d /tmp/mysest2 [root@localhost ~]# ls /tmp/mytest2 bash_completion.d dracut.conf.d logrotate.d popt.d rc2.d rc.d sysctl.d binfmt.d grub.d modprobe.d prelink.conf.d rc3.d rsyslog.d tmpfiles.d chkconfig.d init.d modules-load.d profile.d rc4.d rwtab.d xinetd.d cron.d krb5.conf.d my.cnf.d rc0.d rc5.d statetab.d yum.repos.d depmod.d ld.so.conf.d pam.d rc1.d rc6.d sudoers.d
- 復制/etc/目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中。
[root@localhost ~]# cp -rv /etc/{l,m,n}*.conf /tmp/mytest3 ‘/etc/ld.so.conf’ -> ‘/tmp/mytest3/ld.so.conf’ ‘/etc/libaudit.conf’ -> ‘/tmp/mytest3/libaudit.conf’ ‘/etc/libuser.conf’ -> ‘/tmp/mytest3/libuser.conf’ ‘/etc/locale.conf’ -> ‘/tmp/mytest3/locale.conf’ ‘/etc/logrotate.conf’ -> ‘/tmp/mytest3/logrotate.conf’ ‘/etc/man_db.conf’ -> ‘/tmp/mytest3/man_db.conf’ ‘/etc/mke2fs.conf’ -> ‘/tmp/mytest3/mke2fs.conf’ ‘/etc/nsswitch.conf’ -> ‘/tmp/mytest3/nsswitch.conf’ [root@localhost ~]# ls /tmp/mytest3 ld.so.conf libuser.conf logrotate.conf mke2fs.conf libaudit.conf locale.conf man_db.conf nsswitch.conf
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/91798
看著沒問題,不過代碼中有些符號我看不出來是否正確