Linux 操作系统(二)搜索文件命令find、locate、which、whereis、grep、wc
以下命令均已在 Kali Linux 下验证。
1.find 命令
--1--
find /usr/share -name test.lst //精准搜索,文件名需要与-name后的内容一模一样包括后缀
--2--
find /usr/share -name "tes*" //通配符* 表示匹配所有
find /usr/share -name "test.???" //通配符? 表示匹配单个字符
--3--
find /usr/share -iname "test.lst" // -iname 参数,不区分文件名大小写
--4--
find /usr/share -size +1024 //按照文件大小查找; -size 参数 +n大于 -n小于 n等于; 1块=512k, 2048块=10M;
--5--
find /home -user root //按照所有者查找;
--6--
find /etc -mmin -30 //按时间属性查找,-amin访问时间
find /etc -cmin -30 //按时间属性查找,-cmi改变文件属性
find /etc -amin -30 //按时间属性查找,-amin改变文件内容
--7--
find /usr/share 条件1 -a 条件2 // -a 两个条件都需要满足
find /usr/share 条件1 -o 条件2 // -o 满足一个就可
如:
find /usr/share -name "test*" -a -type f //其中-type f文件 -type d 目录 -type l 软连接文件
--8--
find /usr/share -name "test.lst" -exec ls -l {} \; // -exec/-ok 把find命令的结果 用-exec/ok调用的命令2来处理;"{}"相当于占位符,作为find的查找结果。
注:
find 命令是直接在硬盘中进行搜索,如果指定的搜索范围过大,find命令就会消耗较大的系统资源,
导致服务器压力过大。所以,在使用 find 命令搜索时,尽量更精准的查找,这样消耗系统的资源少,
查找的速度快。命令所在路径:/bin/find.
示例:


- --1--
- root@hugboy:/home/hugboy# find /usr/share -name test.lst
- /usr/share/john/test.lst
- --2--
- root@hugboy:/home/hugboy# find /usr/share -name tes*
- /usr/share/postgresql-common/testsuite
- /usr/share/automake-1.16/test-driver
- /usr/share/icons/Flat-Remix-Blue-Dark/apps/scalable/teslagrad.svg
- /usr/share/perl5/Mail/Mailer/testfile.pm
- /usr/share/perl5/Sys/Hostname/testall.pl
- /usr/share/sqlmap/lib/core/testing.py
- /usr/share/sqlmap/lib/techniques/union/test.py
- ...
- root@hugboy:/home/hugboy# find /usr/share -name test.???
- /usr/share/john/test.lst
- /usr/share/wfuzz/wordlist/general/test.txt
- /usr/share/doc/node-normalize.css/examples/test.svg
- /usr/share/doc/p7zip/DOC/MANUAL/cmdline/commands/test.htm
- --3--
- root@hugboy:/home/hugboy# find /usr/share -iname test.lst
- /usr/share/john/TesT.lst
- /usr/share/john/test.lst
- --4--
- root@hugboy:/home/hugboy# find /usr/share -size +9999
- /usr/share/exploitdb/files_exploits.csv
- /usr/share/sqlmap/data/txt/wordlist.tx_
- /usr/share/proj/proj.db
- /usr/share/john/latin1.chr
- /usr/share/john/utf8.chr
- /usr/share/john/ascii.chr
- /usr/share/basemap/data/UScounties.shp
- /usr/share/basemap/data/shadedrelief.jpg
- ...
- --5--
- root@hugboy:/home/hugboy# find -user hugboy
- .
- ./.bash_logout
- ./.Xauthority
- ./CTF/sm.txt
- ./.msf4
- ./.msf4/plugins
- ./.msf4/logos
- ./.msf4/history
- ./.msf4/logs
- ./.msf4/logs/sessions
- ./.msf4/logs/scripts
- ./.msf4/logs/scripts/scraper
- ...
- --6--
- root@hugboy:/home/hugboy# find /usr/share -amin -30
- /usr/share
- /usr/share/mime/image/jpeg.xml
- /usr/share/mime/application/pdf.xml
- /usr/share/icons/Adwaita/cursors/col-resize
- /usr/share/icons/Adwaita/cursors/watch
- /usr/share/icons/Flat-Remix-Blue-Dark/apps/scalable/vulnhub.svg
- /usr/share/icons/Flat-Remix-Blue-Dark/apps/scalable/kali-web-application-trans.svg
- /usr/share/icons/Flat-Remix-Blue-Dark/apps/scalable/devhelp.svg
- /usr/share/icons/Flat-Remix-Blue-Dark/apps/scalable/accessories-text-editor.svg
- ...
- --7--
- root@hugboy:/home/hugboy# find /usr/share -name test.lst -a -type f
- /usr/share/john/test.lst
- --8--
- root@hugboy:/home/hugboy# find /usr/share -name test.lst -exec ls -l {} \;
- -rw-r--r-- 1 root root 85 4月 27 21:19 /usr/share/john/test.lst
2.locate 命令
--1--
locate test.lst //从数据库中搜索文件名
--2--
updatedb // 更新数据库
--3--
locate -i test.lst
注:
1) locate相比find速度更快,因为它是从已经建立好的数据库中搜索文件,消耗系统资源非常小。
2) 但是locate不会实时更新数据库,新建的文件会搜索不到,需要手动更新。(updatadb)
3) locate不收录临时目录tmp下的文件。
4) 命令所在路径:/usr/bin/locate.
示例:


- root@hugboy:/usr# touch ilovelisa
- root@hugboy:/usr# locate ilovelisa
- root@hugboy:/usr# updatedb
- root@hugboy:/usr# locate ilovelisa
- /usr/ilovelisa
3.which 命令
--1--
which cp //列出命令cp所在路径,和命令的别名(如果存在的话)
注:
所在路径:/usr/bin/which.
示例:


- root@hugboy:/usr# which find
- /usr/bin/find
- root@hugboy:/usr# which cp
- /usr/bin/cp
- root@hugboy:/usr#
4.whereis 命令
--1--
whereis cp //查找二进制命令,源文件和帮助文档的命令
注:
所在路径:/usr/bin/whereis.
示例:


- root@hugboy:/usr# whereis cp
- cp: /usr/bin/cp /usr/share/man/man1/cp.1.gz
5.grep 命令
--1--
grep "this" test.lst //存在内容"test"的行
--2--
grep -i "this" test.lst //忽略大小写
--3--
grep -v "this" test.lst //反转查找,不存在内容"test"的行
--4--
grep "^string" test.lst //以string开头
grep "string$" test.lst //以string结尾
grep "^$" test.lst //空行
注:
所在路径:/bin/grep.
示例:


- root@hugboy:/usr/share/john# cat test.lst
- This a test to proof linux order.
- and my love Godness is Lisa hahah...
- Just a Test.
- this all,Bye~
- --1--
- root@hugboy:/usr/share/john# grep "this" test.lst
- this all,Bye~
- --2--
- root@hugboy:/usr/share/john# grep -i "this" test.lst
- This a test to proof linux order.
- this all,Bye~
- --3--
- root@hugboy:/usr/share/john# grep -v "this" test.lst
- This a test to proof linux order.
- and my love Godness is Lisa hahah...
- Just a Test.
- --4--
- root@hugboy:/usr/share/john# grep "...$" test.lst
- This a test to proof linux order.
- and my love Godness is Lisa hahah...
- Just a Test.
- this all,Bye~
- root@hugboy:/usr/share/john# grep "^$" test.lst
- root@hugboy:/usr/share/john# grep -n "^$" test.lst
- 2:
6.wc 统计
--1--
wc -l test.lst // 行数
wc -w test.lst // 单词数
wc -c test.lst // 字节数
注:
命令所在路径:/usr/bin/wc.
示例:


- root@hugboy:/usr/share/john# wc -l test.lst
- 5 test.lst
- root@hugboy:/usr/share/john# wc -w test.lst
- 19 test.lst
- root@hugboy:/usr/share/john# wc -c test.lst
- 99 test.lst
- root@hugboy:/usr/share/john#
7.参考文章
Linux 操作系统(二)搜索文件命令find、locate、which、whereis、grep、wc的更多相关文章
- Linux下相关查找文件命令(find locate which whereis type)
以下内容摘自:http://blog.csdn.net/jessica1201/article/details/8139249 标注的内容为自己的补充: 我们经常需要在系统中查找一个文件,那么在lin ...
- [转载] Linux中的搜索文件命令
搜索文件用处很大,我们往往需要知道一个文件存放在什么地方,我们又知道Linux是命令强大的一个系统,所以也有好多非常优秀的搜索命令.通常find不常用,因为速度慢,耗费硬盘空间.通常我们先使用wher ...
- linux笔记:搜索命令find,locate,which,whereis,grep
命令名称:find功能:文件搜索命令所在路径:/bin/find用法:find 搜索范围 匹配条件其他:举例:find /root -name initfind /root -size +1024fi ...
- Linux下的搜索查找命令的详解(whereis)
2.whereis 和find相比,whereis查找的速度非常快,这是因为linux系统会将 系统内的所有文件都记录在一个数据库文件中,当使用whereis和下面即将介绍的locate时,会从数据 ...
- S5 Linux信息显示与搜索文件命令
5.1-5 uname.hostname.dmesg.stat.du 5.6 date:显示与设置系统时间 5.7 echo:显示一行文本 5.8-12 watch.which.whereis.loc ...
- Linux下搜索文件find、which、whereis、locate
Linux下搜索文件find.which.whereis.locate: - which 寻找“执行文件” - -a 将所有可找到的命令均列出,而不仅仅列出第一个找到的命令名称 - whereis 寻 ...
- linux中其他搜索命令(locate/which/whereis/grep)
目录 locate which whereis grep locate 解释 命令名称:locate 命令所在路径:/usr/bin/locate 执行权限:所有用户 功能描述:在文件资料库中查找文件 ...
- linux执行sh脚本文件命令
linux执行sh脚本文件命令 很多时候需要多个命令来完成一项工作,而这个工作又常常是重复的,这个时候我们自然会想到将这些命令写成sh脚本,下次执行下这个脚本一切就都搞定了,下面就是发布代码的一个脚本 ...
- Linux操作系统中打开文件数量的查看方法
Linux操作系统中打开文件数量的查看方法ulimit -n 4096也就是限制用户的最大文件打开数为4096个 在网上查了关于怎么查看文件打开数的文章大致有两种说法/proc/sys/fs/file ...
随机推荐
- sunny图表——NABCD分析
项目 内容 这个作业属于哪个课程 2021春季计算机学院软件工程(罗杰 任健) 这个作业的要求在哪里 团队选题 我在这个课程的目标是 初步获得软件工程师的能力 这个作业在哪个具体方面帮助我实现目标 选 ...
- PAT A1052 Linked List Sorting
题意:给出N个结点的地址address.数据域data以及指针域next,然后给出链表的首地址,要求把在这个链表上的结点按data值从小到大输出.样例解释:按照输入,这条链表是这样的(结点格式为[ad ...
- Java实现十个经典排序算法(带动态效果图)
前言 排序算法是老生常谈的了,但是在面试中也有会被问到,例如有时候,在考察算法能力的时候,不让你写算法,就让你描述一下,某个排序算法的思想以及时间复杂度或空间复杂度.我就遇到过,直接问快排的,所以这次 ...
- 「性能提升」扩展 Spring Cache 支持多级缓存
为什么多级缓存 缓存的引入是现在大部分系统所必须考虑的 redis 作为常用中间件,虽然我们一般业务系统(毕竟业务量有限)不会遇到如下图 在随着 data-size 的增大和数据结构的复杂的造成性能下 ...
- Java与Python中的‘%’运算符意义一样么?
1. 取余与取模 百度百科对于取模运算做了如下定义: 对于整型数a,b来说,取模运算或者求余运算的方法都是: 1.求 整数商: c = [a/b]; 2.计算模或者余数: r = a - c*b. 求 ...
- 9. resultMap 结果映射集
@Data public class CreditCard extends BankCard { /** * 消费额度 */ private String creditLine; } @Data pu ...
- Day05_25_Super关键字
Super关键字 Super关键字的所用 Super关键字的用法有三种: 在子类的成员方法中,访问父类的成员变量. 在子类的成员方法中,访问父类的成员方法. 在子类的构造方法中,访问父类的构造方法. ...
- P2P技术(一):NAT
1.NAT由来 NAT是一项神奇的技术,说它神奇在于它的出现几乎使IPv4起死回生.在IPv4已经被认为行将结束历史使命之后近20年时间里,人们几乎忘了IPv4的地址空间即将耗尽这样一个事实--在新技 ...
- 过 DNF TP 驱动保护(二)
过 DNF TP 驱动保护(二) 文章目录: 01. 博文简介: 02. 环境及工具准备: 03. 分析 TP 所做的保护: 04. 干掉 NtOpenProc ...
- hdu2489-DFS+最小生成树
题意: 给你n个点,和任意两点的距离,让你在这N个点中找到一个有m个点并且ratio最小的树. ratio = sum(edge) / su ...