find:

find命令是非常有用的linux命令,我们可以用它来根据指定的搜索条件来搜索整个文件系统来查找文件或目录。

基本的‘find file’命令

find . -name "foo.txt" -print  //'.'表示在当前目录下查找,‘-name’表示查找文件名。意思我在当前目录下查找文件名为foo.txt,并把查找结果打印出来。其中‘-print’为默认表达式,可省略。

find / -name "*.txt"   // '/'表示根目录,‘*’为通配符,‘*.txt’表示文件格式为txt的文件或目录。

多目录查找

find /web1 /web2 /web3 -name foo.html //在web1, web2, web3的目录下搜索文件名为foo.html的文件或目录

不区分大小写搜索

find . -iname foo -type d   //'-type d'表示只搜索目录(dirs)不搜索文件。所以整个表示在当前目录下搜索目录名转换成小写为‘foo’的所有目录

多个扩展名搜索

find home/page -type f  \( -name "web*" -o -name "*.c" \)
//'-type f'表示只搜索文件名(file)。\(\)对()进行转义。‘-o’表示‘or’,
-name "web*" -o -name "*.c"表示文件名为web开头的文件或者.c文件。 home/page表示查找目录。

搜索不包含指定名

find .  -not -name '*.html'  //'-not'表示不包含搜索条件的其他文件或目录。 所以这句就表示搜索不包含名称后五位为‘.html’的文件或目录

find+grep通过text来搜索文件

find . -type f -name '*.html' -exec grep -l 'function load' {} \; //搜索包含
function load字符,并且是html文件

find + chmod 搜索文件并修改权限

find /user -name '*.html' -type f -exec chmod 644 {} \;   //搜索/user目录下的html文件,并将其权限修改为 -rw-r--r--(644)

find + copy

find . -type f -name '*.mp3' -exec cp {} /tmp/MusicFiles \;     //将当前目录的mp3文件copy到/tmp/MusicFiles目录下

find + delete

find . -type f -name 'foo*' -exec rm {} \;   //删除当前目录下以foo开头的文件

linux -- 查找(find)命令 一的更多相关文章

  1. Linux 查找文件命令 find whereis locate

    Linux 有三个查找文件的命令:find, whereis, locate 其中find 不常用,whereis与locate经常使用,因为find命令速度较慢,因为whereis与locate是利 ...

  2. LINUX 查找替换命令 总结

    find /var/ -name "*.php" > /home/tmp 在/var/目录下查找 所有以.php后缀结尾的文件  结果很多,就 > 输出结果到/home ...

  3. Linux查找字符串命令grep(转)

    Linux grep命令用于查找文件里符合条件的字符串. grep指令用于查找内容包含指定的范本样式的文件,如果发现某文件的内容符合所指定的范本样式,预设grep指令会把含有范本样式的那一列显示出来. ...

  4. linux查找某个命令属于哪个rpm包

    我们拿pip命令来举例 方法一: 确认命令的路径 # which pip      /usr/bin/pip 用yum命令查找pip属于哪个rpm包 # yum whatprovides /usr/b ...

  5. linux 查找文件命令

    find -name 文件名    在当前目录下查找 find -name nginx.conf

  6. linux查找文件命令find

    http://blog.csdn.net/ydfok/article/details/1486451 find 路径 -name'文件名' 如:find / -name '*dhcp*'

  7. linux查找文件命令

    (2)find /etc -name httpd.conf #在/etc目录下文件httpd.conf

  8. linux查找历史命令

    1.ctr+r  输入搜索关键词 2.&history 3.上箭头翻看

  9. linux上的那些查找的命令

    由于工作的需要,少不得要在linux系统上查找各种各样的文件,关于在linux查找的命令有不少,这里小小的总结下. 简单介绍下各个命令的用途: find:实际搜索硬盘查询文件名称: whereis:查 ...

  10. Linux下的文件查找类命令(转载)

    如何快速有效的定位文件系统内所需要查找的文件呢?Linux为我们提供了一些文件查找类的命令,我们需要掌握以下几个命令: http://blog.csdn.net/sailor201211/articl ...

随机推荐

  1. solr亿万级索引优化实践-自动生成UUID

    solr亿万级索引优化实践(三) 原创 2017年03月14日 17:03:09        本篇文章主要介绍下如何从客户端solrJ以及服务端参数配置的角度来提升索引速度. solrJ6.0提供的 ...

  2. [异常]undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x16529f8 @example=nil>

    在进行Rspec 编译测试: bundle exec rspec spec/requests/static_pages_spec.rb 提示错误: FF Failures: 1) Static pag ...

  3. Java 8新特性--Lambda表达式作为返回值

    lambda表达式作为方法的返回值:

  4. [牛客网试题] Test.main() 函数执行后的输出是()

    public class Test { public static void main(String [] args){ System.out.println(new B().getValue()); ...

  5. 解决Unsupported major.minor version 51.0报错问题

    问题产生原因:计算机环境变量的jdk版本与eclipse使用的jdk版本不一致 解决方法: 1.查看计算机环境变量的jdk版本 2.查看eclipse项目java compiler的方法:在项目点右键 ...

  6. How to install Eclipse?

    http://askubuntu.com/questions/26632/how-to-install-eclipse How to install Eclipse? up vote113down v ...

  7. 洛谷 P2935 [USACO09JAN]最好的地方Best Spot

    题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...

  8. nginx 编译某个模板的问题./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library stati

    root@hett-PowerEdge-T30:/usr/local/src/nginx-1.9.8# ./configure --prefix=/usr/local/nginx  --add-mod ...

  9. Google Colab的一些注意事项

    1.执行命令行前面加! 当我们使用python解释器时,我们需要不停地在命令行和IDE 之间切换,当我们需要使用命令行工具时.不过,Jupyter Notebook给了我们在notebook中运行sh ...

  10. 理想路径——双向BFS

    题目 给n个点m条边(2 ≤ n ≤ 100000,1 ≤ m ≤ 200000)的无向图,每条边上都涂有一种颜色.求从结点1到结点n的一条路径,使得经过的边数尽量的少,在此前提下,经过边的颜色序列的 ...