01.touch
创建文件
touch /root/test.txt #文件不存在,则在家目录下创建test.txt
#文件存在,则更新文件时间为当前系统时间
02.cp
复制文件或目录
cp /etc/hostname /root #复制文件hostname到/root下
cp /etc/hostname /root/host #复制文件hostname到/root并改名host
cp -r /var/log /root #复制目录log到/root
cp -a /etc/hosts /root #复制文件hosts,保留文档所有属性,权限,时间等
03.mv
移动或重命名文件或目录
mv /root/test.txt /root/a.txt #重命名test.txt为a.txt
mv /root/a.txt / #移动a.txt到/下
04.rm
删除
rm /root/hostname #删除/root下的hostname文件
rm -rf /root/log #删除目录且不提示
#选项:-f 不提示, -i 删除前提示, -r 递归删除目录及目录下所有内容
05.find
查找
#find 范围 选项 参数
find / -name hostname #查找/下名字为hostname的文件或目录
find / -iname Hostname #不区分大小写查找
find / -empty #查找空文件或目录
find / -group student #查找所属组为student的文件或目录
find / -mtime +5 #查找5天前被修改的文件或目录
find / -mtime -3 #查找3天内被修改的文件或目录
find / -mtime 2 #查找两天前当天修改的文件或目录
find / -size +20k #按大小查找
find / -type f #按类型查找 f文件,d目录,b块设备,c字符设备,l链接
find / -user student #查找用户student的文件及目录
find / -size +20k -exec ls -l {} \; #查找大于20k文件并列出详细信息
#其他选项 -a 逻辑且, -o 逻辑或, !逻辑非
06.du
统计文件或目录容量信息
du /root #查看目录及子目录容量信息
du -a /root
du -h /root #人性化显示容量信息
du -sh /root #查看磁盘空间总和