LINUX 拥有遍历文件夹功能的 查找关键字 文件、文件夹

查找文件:

[[email protected] admin]# find . -type f -name "a.txt"
./Downloads/hadoop-2.10.0/a.txt

拥有遍历文件夹功能的 查找关键字 文件、文件夹:

[[email protected] admin]# vi a
[[email protected] admin]# find /home/admin/ -type f | xargs grep "i like apple"
Binary file /home/admin/.cache/tracker/meta.db matches
Binary file /home/admin/.cache/tracker/meta.db-wal matches
grep: /home/admin/.cache/yelp/WebKitCache/Version: No such file or directory
grep: 14/salt: No such file or directory
grep: /home/admin/Downloads/hadoop-2.10.0/share/hadoop/yarn/webapps/ui2/assets/images/datatables/Sorting: No such file or directory
grep: icons.psd: No such file or directory
/home/admin/a:i like apple  (把包含i like apple 那一行取出, 如果是i like apple too, 这里显示的就是i like apple too)
[[email protected] admin]# 

[[email protected] admin]# cat a
i like apple
hahahaha

 

grep:查找指定目录/home/admin及其子目录(如果存在子目录的话)下所有文件中包含字符串"i like apple too"的文件,并打印出该字符串所在行的内容,使用的命令为:

[[email protected] admin]# grep -r "i like apple" /home/admin
Binary file /home/admin/.cache/tracker/meta.db matches
/home/admin/a:i like apple too

原文地址:https://www.cnblogs.com/watermarks/p/12681641.html

时间: 2024-08-28 05:17:10

LINUX 拥有遍历文件夹功能的 查找关键字 文件、文件夹的相关文章

Ubuntu 查找文件夹中内容包含关键字的文件,路径为当前文件夹

From CSDN http://blog.csdn.net/lizhenmingdirk/article/details/44834997 grep -rl "keyword" ./ 1. find / -name '*' | xargs grep 'route' 在根文件夹下查找含有关键字route的文件,列出文件名和route所在行. 2. find / -name '*.txt' | xargs grep 'route' 在根文件夹下查找后缀名为txt且含有关键字route的文

文件载入功能

文件载入功能 1)项目Common文件载入 在./Application/Common/Common文件夹下创建funciton.php文件,当系统运行时会自动加载该function.php文件. 在任何前后台模块下都可以使用tree函数,如下图所示: 2)自定义文件载入 路径:./Application/Common/Common/func.php文件 在config.php配置文件中,使用参数LOAD_EXT_FILE来加载func.php文件 3)按需加载(针对模块而言) 路径:./App

开启Nginx的目录文件列表功能

nginx默认是不允许列出整个目录的.如何开启Nginx的目录文件列表功能?打开nginx.conf文件,在location server 或 http段中加入 autoindex on;另外两个参数最好也加上去:autoindex_exact_size on;显示出文件的确切大小,单位是bytes.改为off后,显示出文件的大概大小,单位是kB或者MB或者GBautoindex_localtime on;默认为off,显示的文件时间为GMT时间.改为on后,显示的文件时间为文件的服务器时间 配

超大文件中查找关键字

一个有10亿条记录的文本文件,已按照关键字排好序存储.请设计算法,可以快速的从文件中查找指字关键字的记录. 因为已经排好序了,可以使用 二分查找方法检索. 又因为文件过于庞大,可以将文件File分成1000份子记录集即读入10000次,每次读入10亿/10000条记录: 每次 读入一次 10亿/10000 条记录时,记作,将其关键字保存于Records数组中 , 当读入一个子记录集时,说明关键字key>=Records[0],故只需将关键字key与Records[i]最后一条记录关键字key'比

linux下遍历文件夹---opendir等用法

首先要说肯定是头文件,#include <sys/types.h>   #include <dirent.h> linux下遍历文件夹需要用到以下几个函数,其中有三个是必须的,其它几个是可选的. DIR* opendir(const char * name);   失败返回NULL.成功返回DIR结构体.注意DIR前面没有struct,如果加上编译器会warning struct dirent *readdir(struct DIR* dir);   失败返回NULL. void

linux c遍历文件夹的方法

linux c遍历文件夹的方法比较简单,使用c来实现 #include <iostream> #include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <sys/dir.h> #include <sys/stat.h> ... enum{    DT_UNKNOWN = 0,     //未知类型    DT_FIFO = 1,        //管道

Ant步步为营(5)用for和foreach的方法遍历一个文件夹,查找到某个文件并删除

今天有个任务是要删除VM上的某个文件夹下的两个jar包.不过这个任务没有分配给我,而是分配给俺的师傅,哈哈.不过我还是自己动手写了一些脚本在本地模拟一下删除某个指定文件. build.xml <?xml version="1.0"?>    <project name="ForTest" default="build" >    <property file="build.properties"&

Linux下的C程序,遍历文件夹并统计其中各个类型文件所占百分比

递归遍历一个目录下的所有文件和文件夹,统计各个类型文件所占的百分比 程序代码a.cpp(编译命令:g++ a.cpp -o a) #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <dirent.h> #include <string.h> stru

shell学习之查找当前目录下文件以及文件夹大小-&#39;du&#39;命令和&#39;df&#39;命令

经过前几天的磁盘写满的事件之后,发现自己对du这个命令完全不知道,所以下决心要学习一番. 我就当一盘搬运工吧,外网找到一个教程 'du'就是查找文件夹的大小 du Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the tot