标签:linux文件管理命令
回顾:
/boot
/home/chaitc
/root
/etc /etc/profile.d/env.sh /etc/profile HISTSIZE /etc/issue /etc/motd /etc/DIR_COLORS /etc/centos-release
/dev sda sr0 zero null random
/bin /sbin
/media /mnt 挂载
/var/log/
/var/www/html
/var/spool/mail
/tmp
/proc 内存
/sys 硬件
/usr
/lib
/lib64
/opt
/srv
/selinux selinux

文件通配符

    • 匹配零个或多个字符
  • ?匹配任何单个字符
  • ~ 当前用户家目录
  • ~chaitc 用户chaitc家目录
  • ~+ 当前工作目录
  • ~- 前一个工作目录
  • [0-9] 匹配数字范围
  • [a-z] [A-Z]:字母
  • [chai] 匹配列表中的任何一个字符
  • [^chai]匹配列表中所有字符以外的字符


  • 预定义的字符类:man 7 glob

[:digit:]:任意数字,相当于0-9
[:lower:]:任意小写字母
[:upper:]:任意大写字母
[:alpha:]:任意大小写字母
[:alnum:]:任意数字或字母
[:blank:]:水平空白字符
[:space:]:水平或垂直空白字符
[:punct:]:标点符号
[:print:]:可打印字符
[:cntrl:]:控制(非打印)字符
[:graph:]:图形字符
[:xdigit:]:十六进制字符

练习

1、显示/var目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件或目录
ls -d /var/I[[:digit:]]image.gif[[:lower:]]image.gif
2、显示/etc目录下以任意一个数字开头,且以非数字结尾的文件或目录
ls -d /etc/[0-9]
[^[:digit:]]
3、显示/etc/目录下以非字母开头,后面跟了一个字母及其它任意长度任意字符的文件或目录
ls -a /etc/[^[:alpha:]][a-Z]
4、显示/etc/目录下所有以rc开头,并后面是0-6之间的数字,其它为任意字符的文件或目录
ls -d /etc/rc[0-6]

5、显示/etc/目录下,所有以.d结尾的文件或目录
ls -d /etc/.d
6、显示/etc目录下,所有.conf结尾,且以m,n,r,p开头的文件或目录
ls -d /etc/[mnrp]
.conf
7、只显示/root下的隐藏文件和目录
ls -d /root/. 忽略 不是 . 开头的文件剩下的就是 .开头的文件 ls -aI “[^.]“ l.
8、只显示/etc下的非隐藏目录
ls -d /etc/*/

关闭防火墙:

centos7
systemctl stop firewalld 关闭防火墙
systemctl disable firewalld 设为开机不启动

centos6
service iptables stop
chkconfig iptables off

创建空文件和刷新时间

  • touchu命令
  • 格式:touch [OPTION]… FILE…

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

touch 2020-02-21.log
touch date +%F.log
[root@Centos6 ~]#ll anaconda-ks.cfg
-rw———-. 1 root root 1480 Feb 15 23:22 anaconda-ks.cfg
[root@Centos6 ~]#ll —time=atime anaconda-ks.cfg
-rw———-. 1 root root 1480 Feb 15 23:51 anaconda-ks.cfg
[root@Centos6 ~]#ll —time=ctime anaconda-ks.cfg
-rw———-. 1 root root 1480 Feb 15 23:23 anaconda-ks.cfg
[root@Centos6 ~]#sta
stap-merge stapsh start_kdeinit start-statd stat
stap-report start start_kdeinit_wrapper start_udev states
staprun startkde start-pulseaudio-x11 startx status
[root@Centos6 ~]#stat anaconda-ks.cfg
File: anaconda-ks.cfg'<br /> Size: 1480 Blocks: 8 IO Block: 4096 regular file<br />Device: 802h/2050d Inode: 407399 Links: 1<br />Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)<br />Access: 2020-02-15 23:51:08.640090384 +0800<br />Modify: 2020-02-15 23:22:58.769999336 +0800<br />Change: 2020-02-15 23:23:04.792999333 +0800<br />[root@Centos6 ~]#touch anaconda-ks.cfg <br />[root@Centos6 ~]#stat anaconda-ks.cfg <br /> File:anaconda-ks.cfg’
Size: 1480 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 407399 Links: 1
Access: (0600/-rw———-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-02-22 12:17:10.311998074 +0800
Modify: 2020-02-22 12:17:10.311998074 +0800
Change: 2020-02-22 12:17:10.311998074 +0800
[root@Centos6 ~]#date
Sat Feb 22 12:17:33 CST 2020