文件查找
简介
which:命令查找
find:文件查找,针对文件名
locate:文件查找,依赖数据库
命令文件查找:
which
[root@localhost toy]# which ls
alias ls='ls --color=auto' //用于设置指令的别名,用户可利用 alias,自定指令的别名,alias 的效果仅在该次登入的操作有效
/usr/bin/ls
find [path...] [options] [expression] [action] 命令 路径 选项 表达式 动作
按文件名
[root@localhost toy]# find /etc -name hosts
[root@localhost toy]# find /etc -iname hosts // i 忽略大小写
[root@localhost toy]# find /etc -iname hos*
按文件大小
[root@localhost toy]# find /etc -size 5M
[root@localhost toy]# find /etc -size -5M
[root@localhost toy]# find /etc -size +5M
指定查找目录深度
[root@localhost toy]# find / -maxdepth 3 -a -name ifcfg-en
按文件属主属组
[root@localhost toy]# find /home -user alice
[root@localhost toy]# find /home -group hr
按文件类型
[root@localhost toy]# find /dev -type f //普通文件
[root@localhost toy]# find /dev -type d //设备文件
按文件权限
[root@localhost toy]# find ./ -perm 644 -ls(动作)
find语法中的动作
找到文件后拷贝内容
[root@localhost toy]# find /etc -name ifcfg* -ok cp -rvf {} /tmp \;
文件打包及压缩
简介
tar命令是unix/linux系统中备份文件的可靠方法,几乎可以工作在任何环境中,他的使用权限是针对所有用户。建议针对目录。
打包,压缩 tar 选项 压缩包名称 源文件
[root@localhost toy]# tar -cf a.tar ./a //打包
[root@localhost toy]# tar -czf a-gzip.tar.gz ./a //压缩
解压,解包
[root@localhost Desktop]# tar -xvf ../a-gzip.tar.gz
[root@localhost Desktop]# tar -xvf ../a-gzip.tar.gz -C /tmp
指定解压后存放位置