首页 > 代码库 > linux文件摘选
linux文件摘选
显示/var目录下所有以1开头,以一个小写字母结尾,且中间至少出现一位数字(可以由其他字符)的文件或目录。
命令: ls -d /var/1*[0-9]*[a-z]
[root@foundation0 ~]# ls -d /var/1*[0-9]*[a-z]
ls: cannot access /var/1*[0-9]*[a-z]: No such file or directory
[root@foundation0 ~]# clear
[3;J
[root@foundation0 ~]# ls -d /var/1*[0-9]*[a-z]
ls: cannot access /var/1*[0-9]*[a-z]: No such file or directory
[root@foundation0 ~]# touch /var/1sfsfsfas
[root@foundation0 ~]# ls -d /var/1*[0-9]*[a-z]
ls: cannot access /var/1*[0-9]*[a-z]: No such file or directory
[root@foundation0 ~]# touch /var/1sfsf4sfas
[root@foundation0 ~]# ls -d /var/1*[0-9]*[a-z]
/var/1sfsf4sfas
-----------------------------------------------------------------------------------
显示/etc目录下,以任意一个数字开头,且以非数字结尾的文件或目录。
命令:ls -d /etc/[[:digit:]]*[^[:digit:]]
[root@foundation0 ~]# touch /etc/4dadasfas
[root@foundation0 ~]# ls -d /etc/[[:digit:]]*[^[:digit:]]
/etc/4dadasfas
-----------------------------------------------------------------------------------
显示/etc目录下。以非字母开头,后面跟了一个字母以及其他任意长度任意字符的文件或目录。
命令:ls -d /etc/[^[:alpha:]][[:alpha:]]*
[root@foundation0 ~]# ls -d /etc/[^[:alpha:]][[:alpha:]]*
ls: cannot access /etc/[^[:alpha:]][[:alpha:]]*: No such file or directory
[root@foundation0 ~]# touch /etc/{4sdsafs,44ssadsf}
[root@foundation0 ~]# ls -d /etc/[^[:alpha:]][[:alpha:]]*
/etc/4sdsafs
-----------------------------------------------------------------------------------
在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile-2016-05-27-09-32-22.
命令: touch /tmp/tfile-`date +%Y-%m-%d-%H-%M-%S`
[root@foundation0 ~]# touch /tmp/tfile-`date +%Y-%m-%d-%H-%M-%S`
[root@foundation0 ~]# ll /tmp/
total 4
-rw-r--r--. 1 root root 0 Sep 25 23:35 a_c
-rw-r--r--. 1 root root 0 Sep 25 23:35 a_d
-rw-r--r--. 1 root root 0 Sep 25 23:35 b_c
-rw-r--r--. 1 root root 0 Sep 25 23:35 b_d
drwxr-xr-x. 14 root root 4096 Sep 25 23:40 mylinux
-rw-r--r--. 1 root root 0 Sep 26 01:14 tfile-2016-09-26-01-14-20
-----------------------------------------------------------------------------------
复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mufile目录中。
命令: mkdir /tmp/mytest1 && cp -r /etc/p*[^[:digit:]] /tmp/mytest1
[root@foundation0 ~]# mkdir /tmp/mytest1 && cp -r /etc/p*[^[:digit:]] /tmp/mytest1
[root@foundation0 ~]# ls /tmp/mytest1/
pam.d pinforc pm ppp profile pulse
passwd pki popt.d prelink.conf.d profile.d purple
passwd- plymouth postfix printcap protocols
-----------------------------------------------------------------------------------
复制/etc目录下所有以.d结尾的文件或目录至/tmp.mytest2目录中。
命令:mkdir /tmp/mytest2 && cp -r /etc/*.d /tmp/mytest2
[root@foundation0 ~]# mkdir /tmp/mytest2 && cp -r /etc/*.d /tmp/mytest2
[root@foundation0 ~]# ls /tmp/mytest2/
auto.master.d init.d profile.d sane.d
bash_completion.d ipsec.d rc0.d setuptool.d
binfmt.d ld.so.conf.d rc1.d statetab.d
cgconfig.d libibverbs.d rc2.d sudoers.d
chkconfig.d logrotate.d rc3.d sysctl.d
cron.d modprobe.d rc4.d tmpfiles.d
depmod.d modules-load.d rc5.d usb_modeswitch.d
dnsmasq.d my.cnf.d rc6.d virt-who.d
dracut.conf.d oddjobd.conf.d rc.d xinetd.d
exports.d pam.d request-key.d yum.repos.d
gdbinit.d popt.d rsyslog.d
grub.d prelink.conf.d rwtab.d
-----------------------------------------------------------------------------------
复制/etc目录下所有以1或m或n开头,以.conf结尾的文件至/tmp/mytest3目录。
命令:mkdir /tmp/mytest3 && cp -r /etc/[l,m,n]*.conf /tmp/mytest3
[root@foundation0 ~]# mkdir /tmp/mytest3 && cp -r /etc/[l,m,n]*.conf /tmp/mytest3
[root@foundation0 ~]# ls /tmp/mytest3
ld.so.conf libuser.conf man_db.conf named.conf numad.conf
libaudit.conf locale.conf mke2fs.conf nfsmount.conf
libguestfs-tools.conf logrotate.conf mtools.conf nsswitch.conf
linux文件摘选