基础命令-文件操作03
报错信息
1.No such file or directory(参数或命令打错了) //没有这样的文件或者目录
2.invalid trailing option – . //无效的选项
3.command not found //命令未找到
simlar command is //相似的命令是
1.创建目录
#mkdir 目录名字
#mkdir -p //多级创建目录,递归创建目录
2.复制
#cp 复制的文件 目的目录
#cp -r //复制目录时加-r选项
#cp a b … 目的目录//复制多个文件
注意!:想创建或者复制多个目录或者文件时,
直接在touch和mkdir或cp后直接写文件名字加空格
3.移动
#mv 移动的文件 目的目录
#mv a.txt dachui/c.txt
//移动a.txt到dachui下,并重命名为c.txt
4.删除
#rm -rf //不问直接删除
5.压缩和解压缩:
#unzip xx.zip //解压缩
gzip bzip2
#gzip a.txt //压缩为a.txt.gz
#gzip -d dachui //解压
#bzip2 a.txt //压缩为a.txt.bz2
#bzip2 -d dachui //解压
注意!:都不能压缩目录
6.压缩和解压:
f 指定压缩包名字
#tar -xf 压缩包 //任何格式都可以解压
#tar -cf etc.tar /etc/ //将etc目录压缩为etc.tar
#tar -czf etc.tar.gz /etc/ //压缩
#tar -cjf etc.tar.bz2 /etc/
//压缩
#tar --delete /etc/hosts -f etc.tar
//从打包的文档中删除hosts文件
#tar -f etc.tar -r /root/install.log
//追加文件到打包文件
#tar -cf etc.tar /etc/ --remove-files
//打包压缩后删除源文件
#tar -xf etc.tar -C /tmp
//指定解压路径到/tmp下
7.统计文件或目录大小
#du
#du -h //以M为单位显示大小
#du -sh //仅显示总大小
8.搜索文件和目录
#find / -name hello.doc
//在根下找文件名字为hello.doc 的文件
#find / -type f (文件)
d (目录)
#find / -type f -a -name hello.doc
-empty 空文件
-size +10M 大于10M
-10M 小于10M
-mtime +5 5天前
-6 6天内
-iname 忽略文档名大小写
-group 按组
-user 按用户
-exec 对找到的文档执行特定的命令
-a 多个条件组合
-o 或
#find / -name a.txt -exec rm-r {}\;
//找到a.txt并删除
9.软链接和硬链接
软链接就相当于Windows里的快捷方式
1.软链接
#ln -s 源文件名字 链接文件名字
2.硬链接
#ln 源文件名字 链接文件名字
10.历史命令
#history(默认存1000条)
#history -C //清空历史命令
存放文件
/root/.bash_history
Linux哲学:一切皆文件
11.查找命令的存储位置
#which 命令