1. 文件和目录
- cd命令
1 | cd /进入系统根目录 |
- ls和pwd命令
1 | ls注意ls的参数 |
- mkdir命令
1 | mkdir /test在根目录下创建test目录 |
- cp命令
1 | cp file1 file2复制一个文件 |
- mv命令
1 | mv /opt/a /root/移动文件 |
- touch命令
1 | touch 1.txt创建文件 |
- file命令
1 | 查看文件的类型 |
- tree命令
1 | 显示文件和目录由根目录开始的树形结构 |
2. 文件搜素
- whereis和which命令
1 | 查找二进制文件 |
- find命令
按名称查找1
2
3
4# find /etc/ -name grub.conf
# find /etc/ -name "*.conf"
# find /etc/ -name ".*"
# find /test/ -iname Abc
按类型查找1
2
3
4
5
6
7# find / -type f
# find / -type b
# find / -type s
# find / -type c
# find / -type p
# find / -type d
# find / -type l
按大小查找1
2
3
4
5
6# find / -size +500M
# find / -size +1G
# find / -size +50k
# find / -size -1M
# find / -size +3c
# find / -size +80M -size -100M
按时间查找1
2
3
4
5
6
7
8
9
10
11
12
13
14
15# stat 1 |tail -3
Access: 2014-07-23 11:56:42.297572398 +0800 --atime 阅读过,用cat,tail,head,more,less命令等或者vi访问过,但没有修改;执行过也会改变
Modify: 2014-07-23 11:56:44.836572907 +0800--mtime 修改过内容,用vi修改过或者echo一个值重定向
Change: 2014-07-23 11:56:44.856885177 +0800 —ctime 改变过内容,属主,属组,权限,创建软链接,硬链接等
找出 3 天”以前”被改动过的文件(> 72 小时)
find /var/log/ -mtime +3 -type f
找出 3 天内被改动过的文件(0 ~ 72 小时内)
find /var/log/ -mtime -3 -type f
找出前第 3 天被改动过的文件(72 ~ 96 小时)
find /var/log/ -mtime 3 -type f
find /var/log/ -mtime +2 -mtime -4 -type f
在20-50天内修改过的文件
find ./ -mtime +20 -a -mtime -50 -type f
在2018-04-11当天修改的文件
find / -type f -newermt '2018-04-11 00:00' -a -not -newermt '2018-04-11 23:56'
- locate命令
速度快,通过系统带的一个数据库去查找,数据是非实时的。
速度快,通过系统带的一个数据库去查找,数据是非实时的。
系统每天自动更新一次,是通过时间任务执行的:/etc/cron.daily/mlocate.cron
/usr/bin/updatedb主要用来更新数据库,通过crontab自动完成的
/usr/bin/locate 查询文件位置
/etc/updatedb.confupdatedb的配置文件
/var/lib/mlocate/mlocate.db 存放文件信息的文件1
# locate passwd