Linux常用命令使用方法,linux常用命令


Linux常用命令使用方法


【find】

格式:find <指定目录> <指定条件> <指定动作>
 '>

1、根据文件属性查找:
-name 按照文件名查找 -iname 根据文件名查找,但是不区分大小写 -prune 不在当前指定的目录中查找 -depth 在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找
 '>
示例:删除home目录及子目录下以txt为后缀的文件:

        '> find /home -depth -name "*.txt" -delete
 '>

2、根据文件类型来查找文件: -type [查找某一类型的文件 ]

文件类型:
1. f 普通文件
2. d 目录
3. l 符号链接文件
4. c 字符设备文件
5. p 管道文件
6. b 块设备文件
7. s socket文件

  '>
示例:查找home目录下的普通文件:
        '> find /home -type f
 '>

3、与管道共用

【-print0 和 xargs -0 详细说明请点击此处】

删除当前目录及子目录下以【.o】为后缀的文件
find ./ -depth -iname '*.o' -print0 | xargs -0 rm 删除当前目录及子目录下以【.o】和【.txt】为后缀的文件
find ./ \( -iname "*.o" -o -iname "*.txt" \) -print0 | xargs -0 rm

相关内容