1.touch: 用于创建空白文件或设置文件的时间
举例: 使用 ls 命令查看一个文件的修改时间, 然后修改这个文件, 最后再通过 touch 命令把修改后的文件时间设置成修改之前的时间(很多黑客就是这样做的):
- [[email protected] test]# ll
- total 8
- -rw-r--r--. 1 root root 91 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- [[email protected] test]# echo You can you up, no can no bebe>> A.txt
- [[email protected] test]# ll
- total 8
- -rw-r--r--. 1 root root 122 Aug 4 16:36 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- [[email protected] test]# touch -d 14:53 A.txt
- [[email protected] test]# ll
- total 8
- -rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
注: 用 stat 代替 ll 发现 touch 命令只能修改 access time 和 modify time, 而不能修改 change time.
2.mkdir: 用于创建空白的目录.
结合 - p 参数来递归创建出具有嵌套叠层关系的文件目录.
- [[email protected] test]# mkdir xinghen1216
- [[email protected] test]# ll
- total 8
- -rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
- [[email protected] test]# mkdir -p a/b/c
- [[email protected] test]# ll
- total 8
- drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
- -rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
- [[email protected] test]# cd a
- [[email protected] a]# ll
- total 0
- drwxr-xr-x. 3 root root 15 Aug 4 16:47 b
- [[email protected] a]# cd b
- [[email protected] b]# ll
- total 0
- drwxr-xr-x. 2 root root 6 Aug 4 16:47 c
- [[email protected] b]# cd c
- [[email protected] c]# ll
- total 0
3.cp: 复制文件或目录. 格式为 "cp [选项] 源文件 目标文件"
1)如果目标文件是目录, 则会把源文件复制到该目录中;
2)如果目标文件也是普通文件, 则会询问是否要覆盖它;
3)如果目标文件不存在, 则执行正常的复制操作.
- [[email protected] test]# cp A.txt a.txt
- [[email protected] test]# ll
- total 12
- drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
- -rw-r--r--. 1 root root 122 Aug 4 16:58 a.txt
- -rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
4.mv: 剪切文件或将文件重命名, 格式为 "mv [选项] 源文件 [目标路径 | 目标文件名]"
如果在同一个目录中对一个文件进行剪切操作, 其实也就是对其进行重命名:
- [[email protected] test]# mv a.txt aa.txt
- [[email protected] test]# ll
- total 12
- drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
- -rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
- -rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
5.rm: 删除文件或目录, 格式为 "rm [选项] 文件".
-f 表示跳过询问确认直接删除
-r 表示删除目录
- [[email protected] test]# ll
- total 12
- drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
- -rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
- -rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
- [[email protected] test]# rm -rf a
- [[email protected] test]# ll
- total 12
- -rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
- -rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
- -rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
- drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
6.dd: 按照指定大小和个数的数据块来复制文件或转换文件
Linux 系统中有一个名为 / dev/zero 的设备文件这个文件不会占用系统存储空间, 但却可以提供无穷无尽的数据, 因此可以使用它作为 dd 命令的输入文件, 来生成一个指定大小的文件.
例如我们可以用 dd 命令从 / dev/zero 设备文件中取出一个大小为 560MB 的数据块, 然后保存成名为 560_file 的文件.
- [[email protected] test]# dd if=/dev/zero of=560_file count=1 bs=560M
- 1+0 records in
- 1+0 records out
- 587202560 bytes (587 MB) copied, 0.82832 s, 709 MB/s
- [[email protected] test]# ll
- total 573444
- -rw-r--r--. 1 root root 587202560 Aug 4 17:21 560_file
- -rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
直接使用 dd 命令来压制出光盘镜像文件, 将它编程一个可立即使用的 iso 镜像:
- [[email protected] test]# dd if=/dev/cdrom of=CentOS-server-7.4.iOS
- 8830976+0 records in
- 8830976+0 records out
- 4521459712 bytes (4.5 GB) copied, 111.594 s, 40.5 MB/s
7.file: 查看文件的类型, 格式为 "file 文件名".
- [[email protected] test]# file aa.txt
- aa.txt: ASCII text
- [[email protected] test]# file xinghen1216
- xinghen1216: directory
- [[email protected] test]# file /dev/sda
- /dev/sda: block special
8.tar 对文件进行打包压缩或解压
常用: 使用 "tar -czvf 压缩包名称. tar.gz 要打包的目录" 命令把指定的文件进行打包压缩; 相应的解压命令为 "tar -xzvf 压缩包名称. tar.gz"
- [[email protected] test]# tar -czvf etc.tar.gz /etc
- /etc/sane.d/hp5400.conf
- /etc/sane.d/hpsj5s.conf
- /etc/sane.d/leo.conf
- ...
- [[email protected] test]# ll
- total 11384
- -rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
- -rw-r--r--. 1 root root 11651868 Aug 4 17:52 etc.tar.gz
- drwxr-xr-x. 2 root root 6 Aug 4 17:42 xinghen1216
- [[email protected] test]# cd ..
- [[email protected] ~]# mkdir test01
- [[email protected] ~]# tar -xzvf /root/test/etc.tar.gz -C /root/test01/
- etc/smartmontools/smartd.conf
- etc/smartmontools/smartd_warning.d/etc/sudoers.d/
- etc/wgetrc
- ...
9. 在文本中执行关键词搜索, 并显示匹配的结果
在 Linux 系统中,/etc/passwd 文件是保存着所有的用户信息, 而一旦用户的登录终端被设置成 / sbin/nologin, 则不再允许登录系统, 因此可以使用 grep 命令来查找出当前系统中不允许登录系统的所有用户信息:
- [[email protected] etc]# grep -n /sbin/nologin /etc/passwd
- 2:bin:x:1:1:bin:/bin:/sbin/nologin
- 3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
- 4:adm:x:3:4:adm:/var/adm:/sbin/nologin
10.find: 按照指定条件来查找文件, 格式为 "find [查找路径] 寻找条件操作"
"-exec {} \;" 参数, 其中的 {} 表示 find 命令搜索出的每一个文件, 并且命令的结尾必须是 "\;".
举例: 1)获取到 / etc 目录中所有以 host 开头的文件列表
- [[email protected] etc]# find /etc -name "host*" -print
- /etc/host.conf
- /etc/hosts
- /etc/hosts.allow
- /etc/hosts.deny
- /etc/selinux/targeted/active/modules/100/hostname
- /etc/hostname
- /etc/avahi/hosts
2)在整个系统中搜索权限中包括 SUID 权限的所有文件
- [[email protected] etc]# find / -perm -4000 -print
- find: '/proc/84104/task/84104/fd/6': No such file or directory
- find: '/proc/84104/task/84104/fdinfo/6': No such file or directory
- find: '/proc/84104/fd/6': No such file or directory
- find: '/proc/84104/fdinfo/6': No such file or directory
- /usr/bin/fusermount
- /usr/bin/passwd
- /usr/bin/chfn
3)在整个文件系统中找出所有归属于 linuxprobe 用户的文件并复制到 / root/findresults 目录
[[email protected] etc]# find / -user CentOS -exec cp -a {} /root/findresults/ \;
来源: http://www.bubuko.com/infodetail-3653467.html