chatter:用于设置文件的隐藏权限
- 格式为:chattr [参数] 文件
参数 | 作用 |
---|---|
i | 无法对文件进行修改,若对目录设置后则仅能修改子文件而不能新建或删除。 |
a | 仅允许补充(追加)内容.无法覆盖/删除(Append Only)。 |
S | 文件内容变更后立即同步到硬盘(sync)。 |
s | 彻底从硬盘中删除,不可恢复(用0填充原文件所在硬盘区域)。 |
A | 不再修改这个文件的最后访问时间(atime)。 |
b | 不再修改文件或目录的存取时间。 |
D | 检查压缩文件中的错误。 |
d | 当使用dump命令备份时忽略本文件/目录。 |
c | 默认将文件或目录进行压缩。 |
u | 当删除此文件后依然保留其在硬盘中的数据,方便日后恢复。 |
t | 让文件系统支持尾部合并(tail-merging)。 |
X | 可以直接访问压缩文件的内容。 |
使用示例:
[root@guox ~]# echo this is test! > py_shell
[root@guox ~]# chattr +a py_shell
[root@guox ~]# rm py_shell
rm:是否删除普通文件 “py_shell”?y
rm: 无法删除”py_shell”: 不允许的操作
[root@guox ~]# ll py_shell
-rw-r–r–. 1 root root 14 9月 24 21:22 py_shell
[root@guox ~]# echo hello >> py_shell
[root@guox ~]# cat py_shell
this is test!
hello
chgrp: 修改文件或目录所属组
- 格式为:chgrp [所属组] 文件/目录
使用示例:
[root@guox ~]# ll py_shell
-rw-r–r–. 1 root root 20 9月 24 21:30 py_shell
[root@guox ~]# chgrp guox py_shell
[root@guox ~]# ll py_shell
-rw-r–r–. 1 root guox 20 9月 24 21:30 py_shell
chmod:修改文件或目录的权限
- 格式为:chmod [参数] 权限 文件/目录
-R 递归修改
参数 | 说明 |
---|---|
a | 所有用户 |
u | 所属者 |
g | 所属组 |
o | 除了所属者和所属组之外的用户 |
- | 清除权限 |
+ | 增加权限 |
= | 设置唯一的权限 |
使用示例:
[root@guox ~]# ll py_shell
-rw-r–r–. 1 root guox 20 9月 24 21:30 py_shell
[root@guox ~]# chmod g+w py_shell
[root@guox ~]# ll py_shell
-rw-rw-r–. 1 root guox 20 9月 24 21:30 py_shell
chown:修改文件或目录的所属主与所属组
- 格式为:chown [参数] 所属主:所属组 文件/目录
- R 递归修改
使用示例:
[root@guox ~]# ll py_shell
-rw-rw-r–. 1 guox guox 20 9月 24 21:30 py_shell
[root@guox ~]# chown root:root py_shell
[root@guox ~]# ll py_shell
-rw-rw-r–. 1 root root 20 9月 24 21:30 py_shell
cp:复制文件或目录
-
格式为:cp [选项] 源文件 目标文件
-p 保留原始文件的属性
-d 若对象为”链接文件”,则保留该”链接文件”的属性
-r 递归持续复制(用于目录)
-i 若目标文件存在则询问是否覆盖
-a 相当于-pdr(p,d,r为上述的参数)
使用示例:
[root@guox ~]# cp py_shell /home/test
[root@guox ~]# cat /home/test
this is test!
hello
diff:比较文件的差异信息
- 格式为:diff [参数] 文件
– brief 判断文件是否相同
-c 详细比较文件的差异之处
使用示例:
[root@guox ~]# echo hello this is one > a.txt
[root@guox ~]# echo hello this is two > b.txt
[root@guox ~]# diff –brief a.txt b.txt
文件 a.txt 和 b.txt 不同
[root@guox ~]# diff -c a.txt b.txt
* a.txt 2016-09-24 22:42:13.701943737 +0800
— b.txt 2016-09-24 22:42:31.866943416 +0800 *** 1 ***
! hello this is one --- 1 ----
! hello this is two
find:查找文件
- 格式为:find [查找路径] 寻找条件 操作
参数 | 作用 |
---|---|
-name | 匹配名称 |
-perm | 匹配权限(mode为完全匹配,-mode为包含即可) |
-user | 匹配所有者 |
-group | 匹配所有组 |
-mtime -n +n | 匹配修改内容的时间(-n指n天以内,+n指n天以前) |
-atime -n +n | 匹配访问文件的时间-n指n天以内,+n指n天以前 |
-ctime -n +n | 匹配修改权限的时间-n指n天以内,+n指n天以前 |
-nouser | 匹配无所有者的文件 |
-nogroup | 匹配无所有组的文件 |
-newer f1 !f2 | 匹配比文件f1新却比f2旧的文件 |
–type b/d/c/p/l/f | 匹配文件类型(块设备、目录、字符设备、管道、链接文件、文件文件) |
-size | 匹配文件的大小(+50k查找超过50k的文件,而-50k则代表查找小于50k的文件) |
-prune | 忽略某个目录 |
-exec {} \; | 后面可接对搜索到结果进一步处理的命令 |
使用示例:
[root@guox ~]# find /etc/ -name “host*” -print
/etc/selinux/targeted/modules/active/modules/hostname.pp
/etc/host.conf
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/avahi/hosts
/etc/hostname
ln:链接文件
- 格式为:ln [参数] 原文件 目标
-s 创建软连接,相当于创建了快捷方式。
-b 创建硬链接,相当于备份了文件。
使用示例:
[root@guox ~]# ln -s ln01 /home/ln02
[root@guox ~]# ll /home/ln02
lrwxrwxrwx. 1 root root 4 9月 24 23:09 /home/ln02 -> ln01
[root@guox ~]# ln -b ln01 /home/ln03
[root@guox ~]# ll /home/ln03
-rw-r–r–. 2 root root 18 9月 24 22:42 /home/ln03
lsattr:显示文件的隐藏权限
- 格式为:lsattr [参数] 文件
-a 显示所有文件和目录。
-l 显示隐藏属性的全称(默认简写成一个字母)。
-R 递归处理,将指定目录下的所有文件及子目录一并处理。
-d 若目标文件为目录,请加此参数。
使用示例:
[root@guox ~]# !37
chattr +a py_shell
[root@guox ~]# rm -f py_shell
rm: 无法删除”py_shell”: 不允许的操作
[root@guox ~]# ll py_shell
-rw-rw-r–. 1 root root 20 9月 24 21:30 py_shell
[root@guox ~]# lsattr py_shell
—–a———- py_shell
[root@guox ~]# chattr -a py_shell
[root@guox ~]# rm -f py_shell
mkdir:创建目录
- 格式为:mkdir [选项] 目录
-p 递归创建具有嵌套叠层关系的文件目录。
使用示例:
[root@guox ~]# mkdir -p a/b/c/d
[root@guox ~]# ll -R a
a:
总用量 0
drwxr-xr-x. 3 root root 14 9月 24 23:42 b
a/b:
总用量 0
drwxr-xr-x. 3 root root 14 9月 24 23:42 c
a/b/c:
总用量 0
drwxr-xr-x. 2 root root 6 9月 24 23:42 d
a/b/c/d:
总用量 0
mv:移动文件或改名
- 格式为:mv [选项] 源文件 [目标路径|目标文件名]
使用示例:
[root@guox ~]# cat py_shell
this is test!
hello
[root@guox ~]# mv py_shell test.txt
[root@guox ~]# cat test.txt
this is test!
hello
rm:删除文件或目录
- 格式为:rm [选项] 文件/目录
-f 强制删除。
-r 递归删除。
使用示例:
[root@guox test]# touch aa
[root@guox test]# ls
aa
[root@guox test]# rm -rf aa
[root@guox test]# ls
[root@guox test]#
rmdir:删除空目录
- 格式为:rm [选项] 目录
-p 删除指定目录后,若该目录的上层目录已变成空目录,则将其一并删除.
使用示例:
[root@guox ~]# mkdir -p /test/a/b/c
[root@guox ~]# rmdir -p /test/a/b/c
scp:远程拷贝文件
- 格式为:scp [选项] 源文件/目标文件
-1:使用ssh协议版本1;
-2:使用ssh协议版本2;
-4:使用ipv4;
-6:使用ipv6;
-B:以批处理模式运行;
-C:使用压缩;
-F:指定ssh配置文件;
-l:指定宽带限制;
-o:指定使用的ssh选项;
-P:指定远程主机的端口号;
-p:保留文件的最后修改时间,最后访问时间和权限模式;
-q:不显示复制进度;
-r:以递归方式复制。
使用示例:
[root@guox ~]# scp -r root@192.168.1.123:/nfs/test.txt /test
stat: 显示文件的所有信息(包括访问、修改文件时间等)
- 格式为:stat [选项] 文件
-L:支持符号连接;
-f:显示文件系统状态而非文件状态;
-t:以简洁方式输出信息;
–help:显示指令的帮助信息;
–version:显示指令的版本信息。
使用示例:
[root@guox ~]# ll py_shell
-rw-r–r–. 1 root root 20 9月 24 23:23 py_shell
[root@guox ~]# stat py_shell
文件:”py_shell”
大小:20 块:8 IO 块:4096 普通文件
设备:fd01h/64769d Inode:70105994 硬链接:1
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2016-09-24 23:50:11.862010876 +0800
最近更改:2016-09-24 23:23:39.344899735 +0800
最近改动:2016-09-25 00:23:08.117975892 +0800
创建时间:-
[root@guox ~]# stat -f py_shell
文件:”py_shell”
ID:fd0100000000 文件名长度:255 类型:xfs
块大小:4096 基本块大小:4096
块:总计:4576768 空闲:3756367 可用:3756367
Inodes: 总计:18317312 空闲:18205249
touch:创建空白文件与设置文件的各种时间
- 格式为:touch [选项] 文件
-a 仅修改“访问时间”(atime)
-m 仅修改“更改时间”(mtime)
-d 同时修改atime与mtime。
使用示例:
[root@guox ~]# touch test
[root@guox ~]# stat test
文件:”test”
大小:0 块:0 IO 块:4096 普通空文件
设备:fd01h/64769d Inode:70105991 硬链接:1
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2016-09-25 00:28:49.710969845 +0800
最近更改:2016-09-25 00:28:49.710969845 +0800
最近改动:2016-09-25 00:28:49.710969845 +0800
创建时间:-
[root@guox ~]# touch -d “2020-01-01 01:23:00” test
[root@guox ~]# stat test
文件:”test”
大小:0 块:0 IO 块:4096 普通空文件
设备:fd01h/64769d Inode:70105991 硬链接:1
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2020-01-01 01:23:00.000000000 +0800
最近更改:2020-01-01 01:23:00.000000000 +0800
最近改动:2016-09-25 00:29:52.594968731 +0800
创建时间:-
tree:以树状图列出目录的内容
- 格式为:*tree [选项]
-a:显示所有文件和目录;
-A:使用ASNI绘图字符显示树状图而非以ASCII字符组合;
-C:在文件和目录清单加上色彩,便于区分各种类型;
-d:先是目录名称而非内容;
-D:列出文件或目录的更改时间;
-f:在每个文件或目录之前,显示完整的相对路径名称;
-F:在执行文件,目录,Socket,符号连接,管道名称名称,各自加上”*”,”/”,”@”,”|”号;
-g:列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码;
-i:不以阶梯状列出文件和目录名称;
-l:<范本样式> 不显示符号范本样式的文件或目录名称;
-l:如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录;
-n:不在文件和目录清单加上色彩;
-N:直接列出文件和目录名称,包括控制字符;
-p:列出权限标示;
-P:<范本样式> 只显示符合范本样式的文件和目录名称;
-q:用“?”号取代控制字符,列出文件和目录名称;
-s:列出文件和目录大小;
-t:用文件和目录的更改时间排序;
-u:列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码;
-x:将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该目录予以排除在寻找范围外。
man文档的详细参数:
TREE(1) TREE(1)
tree - list contents of directories in a tree-like format.
SYNOPSIS
tree [-adfghilnopqrstuvxACDFNS] [-L level [-R]] [-H baseHREF] [-T
title] [-o filename] [–nolinks] [-P pattern] [-I pattern] [–inodes]
[–device] [–noreport] [–dirsfirst] [–version] [–help] [–filelimit
#] [directory …]
使用示例:
[root@guox ~]# tree /root
/root
├── a
│ └── b
│ └── c
│ └── d
├── {a
│ └── b
│ └── c
│ └── d}
├── anaconda-ks.cfg
├── b
├── b.txt
├── c
├── initial-setup-ks.cfg
├── ln01
├── py_shell
├── test
├── \345\205\254\345\205\261
├── \346\250\241\346\235\277
├── \350\247\206\351\242\221
├── \345\233\276\347\211\207
├── \346\226\207\346\241\243
├── \344\270\213\350\275\275
├── \351\237\263\344\271\220
└── \346\241\214\351\235\242
18 directories, 6 files
END