003. Linux基础三 P1(文件操作、文件通配符、touch)

时间:2020-11-16 13:02:08   收藏:0   阅读:15
1. 文件操作命令

2. wildcard pattern 文件通配符

1. 常见通配符

* 匹配0个或多个字符,但不匹配.开头的文件,即隐藏文件
? 匹配任何单个字符


~ 当前用户家目录
~mage 用户mage家目录
~+ OR . 当前工作目录
~- 前一个工作目录


[0-9] 匹配数字范围
[a-z] 小写字母
[A-Z] 大写字母
[xxx] 匹配列表中的任何的一个字符
[^xxx] 匹配列表中的所有字符以外的字符


2.预定义的字符类:man 7 glob
[:digit:]:任意数字,相当于0-9
[:lower:]:任意小写字母,表示 a-z
[:upper:]: 任意大写字母,表示 A-Z

[:alnum:]:任意数字或字母
[:blank:]:水平空白字符
[:space:]:水平或垂直空白字符
[:punct:]:标点符号
[:print:]:可打印字符
[:cntrl:]:控制(非打印)字符
[:graph:]:图形字符
[:xdigit:]:十六进制字符

通配符练习

1)显示/etc目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件或目录列表

[root@centos7 dir1]# touch /etc/lx93xx
[root@centos7 dir1]# ls /etc/l*[1-9]*[a-z]
/etc/lx93xx

2)显示/etc目录下以任意一位数字开头,且以非数字结尾的文件或目录列表

[root@centos7 dir1]# touch /etc/1xxxxx
[root@centos7 dir1]# ls /etc/[1-9]*[^1-9]
/etc/1xxxxx

3)显示/etc/目录下以非字母开头,后面跟了一个字母及其它任意长度任意字符的文件或目录列表

[root@centos7 dir1]# touch /etc/2a
[root@centos7 dir1]# touch /etc/2a1
[root@centos7 dir1]# ls /etc/[^[:alpha:][:alpha:]]*
/etc/1xxxxx  /etc/2a  /etc/2a1

4)显示/etc/目录下所有以rc开头,并后面是0-6之间的数字,其它为任意字符的文件或目录列表

[root@centos7 ~]#  ls /etc/rc[0-6]*  -d
/etc/rc0.d  /etc/rc1.d  /etc/rc2.d  /etc/rc3.d  /etc/rc4.d  /etc/rc5.d  /etc/rc6.d

5)显示/etc目录下,所有.conf结尾,且以m,n,r,p开头的文件或目录列表

[root@centos7 ~]# ls /etc/[m,n,r,p]*[.conf] -d
/etc/magic        /etc/mke2fs.conf  /etc/nsswitch.conf  /etc/resolv.conf  /etc/rsyslog.conf
/etc/man_db.conf  /etc/my.cnf       /etc/python         /etc/rpc

6)只显示/root下的隐藏文件和目录列表

[root@centos7 ~]# ls /.* -ad
/.  /..

* * *

[root@centos7 ~]# l. /etc
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  /etc  .lesshst  .tcshrc  .viminfo
[root@centos7 ~]# alias l.
alias l.=‘ls -d .* --color=auto‘

7)只显示/etc下的非隐藏目录列表

ls -d /etc/*/

3 创建文件和刷新时间

touch #创建文件 or 刷新时间
选项:
-a 仅改变 atime和ctime
-m 仅改变 mtime和ctime
-t [[CC]YY]MMDDhhmm[.ss] 指定atime和mtime的时间戳
-c 如果文件不存在,则不予创建

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!