一、文件属性
- 权限位:
- 表示文件
d 表示目录
l 表示软连接
b 表示接口存储设备文件
c 表示串行端口设备
- 文件的时间属性
[root@web02 ~]# ll /etc/passwd ####默认显示的时间属性为mtime(modification time)文件内容变更时间 -rw-r--r-- 1 root root 1381 4月 30 22:54 /etc/passwd [root@web02 ~]# ll --time=atime /etc/passwd #####atime(access time)文件被访问时间 -rw-r--r-- 1 root root 1381 5月 28 09:57 /etc/passwd [root@web02 ~]# ll --time=ctime /etc/passwd #####ctime(status time)文件状态时间,文件属性被修改会更改这个属性 -rw-r--r-- 1 root root 1381 4月 30 22:54 /etc/passwd
- 权限对于文件的意义
r(read):可读取文件的实际内容
w(write):可以编辑、新增或修改文件的内容(但不能删除)
x(execute):可以被系统执行
- 权限对于目录的意义
r:表示具有读取目录结构的权限,如:可以用ls查看目录内容
w:表示可以新增、删除、更改、移动该目录下的文件或目录
x:表示可以进入该目录
- 文件与目录得默认权限
[root@web01 tmp]# umask 0022 若使用者创建为『文件』则默认『没有可运行( x )权限』,亦即只有 rw 这两个权限,也就是最大为 666 若使用者创建为『目录』,则由于 x 与是否可以进入此目录有关,因此默认为所有权限均开放,亦即为 777 umask值,是创建文件和目录时需要减掉得权限,所以创建文件时权限为644,目录为755
- 文件隐藏属性
[root@web01 tmp]# chattr +i passwd.bk ######## +i属性,不能删除,不能更改 [root@web01 tmp]# lsattr passwd.bk ----i--------e- passwd.bk [root@web01 tmp]# chattr -i passwd.bk [root@web01 tmp]# chattr +a passwd.bk ####### +a属性,只能添加内容,不能删除内容 [root@web01 tmp]# >passwd.bk -bash: passwd.bk: 不允许的操作 [root@web01 tmp]# lsattr passwd.bk -----a-------e- passwd.bk
二、命令操作
- 创建目录
[root@web01 tmp]# ll 总用量 0 [root@web01 tmp]# mkdir test [root@web01 tmp]# ls test [root@web01 tmp]# mkdir test/test1/test2 ####不能直接创建多层目录 mkdir: 无法创建目录"test/test1/test2": 没有那个文件或目录 [root@web01 tmp]# mkdir -p test/test1/test2 #####-p 递归创建目录 [root@web01 tmp]# ll 总用量 4 drwxr-xr-x 3 root root 4096 5月 29 16:55 test [root@web01 tmp]# mkdir -m 711 test1 ####-m 创建目录时,给予属性 [root@web01 tmp]# ll 总用量 8 drwxr-xr-x 3 root root 4096 5月 29 16:55 test drwx--x--x 2 root root 4096 5月 29 16:56 test1
- 创建文件
[root@web01 tmp]# ll 总用量 8 -rw-r--r-- 1 root root 0 5月 29 17:11 file.txt drwxr-xr-x 3 root root 4096 5月 29 17:11 test drwx--x--x 2 root root 4096 5月 29 16:56 test1
- 复制文件或目录
[root@web01 tmp]# cp -p /etc/passwd passwd #####连同文件得属性一起复制(备份常用) [root@web01 tmp]# ll /etc/passwd passwd -rw-r--r-- 1 root root 1813 5月 29 14:40 /etc/passwd -rw-r--r-- 1 root root 1813 5月 29 14:40 passwd [root@web01 tmp]# cp /etc/ssh/ test cp: 略过目录"/etc/ssh/" [root@web01 tmp]# cp -r /etc/ssh/ test ####递归复制,用于目录得复制 [root@web01 tmp]# ll test 总用量 8 drwxr-xr-x 2 root root 4096 5月 29 17:16 ssh drwxr-xr-x 3 root root 4096 5月 29 16:55 test1 [root@web01 tmp]# cp -a /var/log/wtmp wtmp.bk ###相当于-pdr -d为复制链接文件属性,而非文件实体 [root@web01 tmp]# ll /var/log/wtmp wtmp.bk -rw-rw-r--. 1 root utmp 76032 5月 29 15:22 /var/log/wtmp -rw-rw-r--. 1 root utmp 76032 5月 29 15:22 wtmp.bk
- 移动文件或目录
[root@web01 tmp]# mv -u /etc/passwd passwd ####如果目标文件存在,当源文件比较新得时候才会移动 [root@web01 tmp]# mv -f /etc/passwd passwd #####如果目标存在,强制覆盖
- 删除文件或目录
[root@web01 tmp]# rm file.txt rm:是否删除普通空文件 "file.txt"?n [root@web01 tmp]# ll 总用量 92 -rw-r--r-- 1 0 root 0 5月 29 17:11 file.txt -rw-r--r-- 1 0 root 1948 5月 29 17:35 passwd drwxr-xr-x 4 0 root 4096 5月 29 17:16 test drwx--x--x 2 0 root 4096 5月 29 16:56 test1 -rw-rw-r--. 1 0 utmp 76032 5月 29 15:22 wtmp.bk [root@web01 tmp]# rm -f file.txt ######强制删除 [root@web01 tmp]# ll 总用量 92 -rw-r--r-- 1 0 root 1948 5月 29 17:35 passwd drwxr-xr-x 4 0 root 4096 5月 29 17:16 test drwx--x--x 2 0 root 4096 5月 29 16:56 test1 -rw-rw-r--. 1 0 utmp 76032 5月 29 15:22 wtmp.bk [root@web01 tmp]# rm -f test rm: 无法删除"test": 是一个目录 [root@web01 tmp]# rm -rf test ########递归删除,删除目录 [root@web01 tmp]# ll 总用量 88 -rw-r--r-- 1 0 root 1948 5月 29 17:35 passwd drwx--x--x 2 0 root 4096 5月 29 16:56 test1 -rw-rw-r--. 1 0 utmp 76032 5月 29 15:22 wtmp.bk
[root@web01 tmp]# ll test1/
总用量 0
[root@web01 tmp]# rmdir test1/ ########删除空目录
[root@web01 tmp]# ll
总用量 84
-rw-r--r-- 1 0 root 1948 5月 29 17:35 passwd
-rw-rw-r--. 1 0 utmp 76032 5月 29 15:22 wtmp.bk
- 文件名变更
[root@web01 tmp]# ll 总用量 88 -rw-r--r-- 1 0 root 1948 5月 29 17:35 passwd drwxr-xr-x 2 0 root 4096 5月 29 17:44 test -rw-rw-r--. 1 0 utmp 76032 5月 29 15:22 wtmp.bk [root@web01 tmp]# mv passwd passwd.bk #######同路径为改名 [root@web01 tmp]# mv test test1 [root@web01 tmp]# ll 总用量 88 -rw-r--r-- 1 0 root 1948 5月 29 17:35 passwd.bk drwxr-xr-x 2 0 root 4096 5月 29 17:44 test1 -rw-rw-r--. 1 0 utmp 76032 5月 29 15:22 wtmp.bk
- 查看文件
[root@web01 tmp]# cat passwd.bk root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin [root@web01 tmp]# cat -n passwd.bk 1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bin:/bin:/sbin/nologin 3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@web01 tmp]# more passwd.bk ####以一页一页显示内容,不可向上翻
[root@web01 tmp]# less passwd.bk ####以一页一页像是内容,可向上翻
[root@web01 tmp]# head -1 passwd.bk ######从头开始显示一行
root:x:0:0:root:/root:/bin/bash
[root@web01 tmp]# tail -1 passwd.bk #####从末尾开始显示一行
test112:x:1014:1014::/home/test112:/bin/bash
- 查找文件
[root@web01 tmp]# whereis ifconfig ####查找数据库中得数据 ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz [root@web01 tmp]# locate ifconfig #####从数据库中查找数据 /sbin/ifconfig /usr/sbin/pifconfig /usr/share/man/de/man8/ifconfig.8.gz /usr/share/man/fr/man8/ifconfig.8.gz /usr/share/man/man8/ifconfig.8.gz /usr/share/man/man8/pifconfig.8.gz /usr/share/man/pt/man8/ifconfig.8.gz
[root@web01 tmp]# updatedb ####更新locate数据库
[root@web01 tmp]# find / -mtime 0 ######将/目录下,24小时内更改过得文件列出
[root@web01 tmp]# find / -mtime -4 #####将/目录下,小于等于4天以内更改过的文件列出
[root@web01 tmp]# find / -mtime 4 #####将/目录下,4-5那一天变动得文件列出
[root@web01 tmp]# find / -mtime +4 #####将/目录下,大于等于5天前变动得文件列出
[root@web01 tmp]# find /tmp -name passwd.bk #######查找/tmp目录下文件名为passwd.bk的文件
/tmp/passwd.bk
[root@web01 tmp]# find /tmp -type f ######查找/tmp目录下的文件
/tmp/passwd.bk
/tmp/wtmp.bk
[root@web01 tmp]# find /tmp -type d #####查找/tmp目录的目录
/tmp
/tmp/.ICE-unix
/tmp/test1
[root@web01 tmp]# find /tmp -size +50k #####查找/tmp目录下大于50k的文件
/tmp/wtmp.bk
[root@web01 tmp]# find /tmp -size -50k #####查找/tmp目录下小于50k的文件
/tmp
/tmp/.ICE-unix
/tmp/passwd.bk
/tmp/test1