Linux常用命令之文件搜索命令

在Linux中查找文件命令的几种方法 要在Linux中查找文件,可以使用以下几种不同的实现方法 阅读详情

目录

1、find搜索命令

2、locate搜索命令

3、whereis搜索命令


1、find搜索命令

find命令是我们在Linux系统中用来进行文件搜索用的最多的命令,功能特别强大。但是我们要说的是尽量少用find命令去执行搜索任务,就算要搜索我们也应该尽量的缩小范围,也不要在服务器使用高峰期进行文件搜索,因为搜索也是很占系统资源的。这就需要我们在进行Linux文件整理的时候,尽量规范化,什么文件放在什么目录下都要有比较好的约定。

find命令几种最常用的用法

        a、命令名称:find

  b、英文原意:

  c、命令所在路径:/bin/find

  d、执行权限:所有用户

  e、功能描述:进行各种花式文件搜索

  f、语法:find【搜索范围】【匹配条件】  

【1】、根据 文件或目录名称 搜索
find 【搜索目录】【-name或者-iname】【搜索字符】:-name和-iname的区别一个区分大小写,一个不区分大小写

  1、find /etc -name init   (精准搜索,名字必须为 init 才能搜索的到)

  2、find /etc -iname init   (精准搜索,名字必须为 init或者有字母大写也能搜索的到)

  3、find /etc -name *init  (模糊搜索,以 init 结尾的文件或目录名) 

  4、find /etc -name init??? (模糊搜索,? 表示单个字符,即搜索到 init___)

        eg:find / -iname lxj-test-0.0.1-SNAPSHOT.jar(搜索jar包位置)

【2】、根据 文件大小 搜索
  比如:在根目录下查找大于 100M 的文件

          find / -size +204800

          这里 +n 表示大于,-n 表示小于,n 表示等于

          1 数据块 == 512 字节 ==0.5KB,也就是1KB等于2数据块

          100MB == 102400KB==204800数据块

【3】、根据 所有者和所属组 搜索

  1、在home目录下查询所属组为 root 的文件

    find /home -group root

  2、在home目录下查询所有者为 root 的文件

    find /home -user root

【4】、根据 时间属性 搜索
  find 【路径】【选项】【时间】

   选项有下面三种:-amin  访问时间

           -cmin   文件属性被更改

           -mmin  文件内容被修改

  时间:+n,-n,n分别表示超过n分钟,n分钟以内和n分钟

  范例:在 /etc 目录下查找5 分钟内被修改过属性的文件和目录

     find /etc -cmin -5

【5】、根据 文件类型或i节点 搜索
  -type 根据文件类型查找:f表示文件,d表示目录,l表示软链接

  范例:查找 /usr 目录下文件类型是目录的   find /usr -type l

  -inum 根据i节点查找

  范例:查找 /tmp 目录下i节点为400342的文件或目录  find /tmp -inum 400342

【6】、组合条件 搜索  
  这里有两个参数:

  1、-a  表示两个条件同时满足(and)

  2、-o  表示两个条件满足任意一个即可(or)

  范例:查找/etc目录下大于80MB同时小于100MB的文件

  find /etc -size +163840 -a -size -204800

2、locate搜索命令

        命令格式:locate [OPTION]... PATTERN...

        选项说明:

        

-A, --all
	只显示匹配所有模式的条目
-b, --basename
	只匹配文件的基本名。作用与选项 --wholename 相反
-c, --count
	只输出符合匹配模式的文件的数量
-d, --database DBPATH
	将默认数据库替换为 DBPATH。该选项可出现多次
-e, --existing
	只打印当前存在的文件
-L, --follow
	当检查文件是否存在时(如果选项 --existing 指定时),检查符号链接的目标文件(默认,相反的选项是 --nofollow)
-h, --help
	显示帮助信息并退出
-i, --ignore-case
	比较时忽略大小写
-l, --limit, -n LIMIT
	限制成功匹配的文件数为 LIMIT
-P, --nofollow, -H
	当检查文件是否存在时(如果选项 --existing 指定时),不检查符号链接的目标文件。作用与 --follow 相反
-0, --null
	在输出时使用 ASCII NUL 字符分隔条目,而不是将每个条目写在单独的行上。此选项是为了与 GNU xargs(1)的 --null 选项配合使用而设计的
-S, --statistics
	不搜索文件,而是显示每个数据库的统计信息
-q, --quiet
	不报告关于读取和处理数据库时遇到的错误的消息
-r, --regexp REGEXP
	使用正则表达式 REGEXP 进行搜索。该选项可出现多次
--regex
	将所有模式解释为扩展的正则表达式
-V, --version
	输出 locate 的版本和许可信息并退出
-w, --wholename
	仅将整个路径名与指定的模式匹配(默认)。如果只匹配文件基本名,可使用选项 --basename

        范例:

                1、查找文件名为 NAME 的文件。

                        locate -b '\NAME'
                2、查找配置文件 mlocate.db。

                        locate mlocate.db

3、whereis搜索命令

        命令格式:whereis [OPTIONS] [-BMS DIRECTORY... -f] NAME...

        选项说明

        

-b
	只搜索二进制文件
-m
	只搜索 man 手册
-s
	只搜索源代码
-u
	只展示有相关特殊文件(二进制程序、源代码文件、man 手册)的命令名称
-B LIST
	指定二进制文件查找目录,使用空格分隔
-M LIST
	指定 man 手册查找目录,使用空格分隔
-S LIST
	指定源代码文件查找目录,使用空格分隔
-f
	在使用 -S 、–M、-B 选项时,必须使用这个选项,用于表示目录的结束,命令名的开始
-l
	输出正在使用的有效查找路径

        范例:

        查看命令 which 的二进制文件与帮助手册的路径。

whereis which
which: /usr/bin/which /usr/share/man/man1/which.1.gz

Linux查找文件内容的命令 Linux查看文件内容的常用命令 阅读详情

相关推荐

Linux全局搜索命令

它们提供了灵活的搜索选项和强大的搜索功能,可以帮助用户快速定位所需的文件或文本内容。在Linux系统中,有许多强大的命令和工具可用于全局搜索文件内容、目录和文件名。这些工具可以帮助用户快速定位特定的文件或搜索特定的文本模式。ack命令是一个功能强大的代码搜索工具,专门用于在源代码中进行搜索。locate命令可以快速搜索系统中已建立的文件索引数据库。它的搜索速度非常快,但可能不会显示最新创建或修改的文件。其中,路径表示要搜索的目录路径,选项用于指定搜索条件,操作用于指定对搜索结果的进一步处理。

JqlScala的博客 2507

Linux:文件查询命令

Linux:文件或内容操作(grep,sed,awk,find,locate)

weixin_70127381的博客 1万+

反向代理的隐形陷阱:为何你的HTTPS请求会降级为HTTP?

本文深入探讨了Nginx反向代理中HTTPS降级为HTTP的隐形陷阱及其安全风险,分析了五大降级诱因,包括协议信息丢失、重定向配置错误等,并提供了完整的防御性配置方案和实战指南,帮助开发者确保Web应用的安全性。

kotlin6android的博客 453

Linux下查找文件(find、grep命令)

linux中一切皆文件的思想是重中之重,那么查找文件是学习Linux必须要掌握的技能。 一、find命令 1.按文件名 使用参数 -name ...

GG_Bruse的博客 22万+

生物信息学新手必看:MAFFT多序列比对从安装到实战(附参数优化技巧)

本文为生物信息学新手提供了MAFFT多序列比对工具的完整指南。从Linux环境下的安装部署,到核心算法策略(如FFT-NS-i、L-INS-i)的选择逻辑,再到空位罚分等关键参数的深度解析与优化技巧,手把手教你完成从原始序列到高质量比对结果的实战流程,为后续进化树构建等分析奠定坚实基础。

weixin_29230773的博客 485

Jetson Orin边缘语音AI实战:用Riva ASR/TTS + Llama 2打造离线智能语音助手

本文详细介绍了如何利用NVIDIA Jetson Orin的边缘计算能力,结合Riva ASR/TTS语音引擎和Llama 2大语言模型,构建完全离线的智能语音助手。通过硬件优化、量化部署和性能调优,实现在网络不稳定环境下的高效语音交互,适用于智能家居、车载系统等场景。

weixin_29053383的博客 242

linux常用文件搜索命令,Linux常用命令--4、文件搜索命令

1、find①文件所在路径:/bin/find②执行权限:所有用户③语法:find [搜索范围] [匹配条件]④功能描述:文件搜索⑤常用选项:-name:按照文件名搜索(-iname不区分大小写)【支持通配符】”*“:匹配任意个字符例:find /etc -name *init*”?“:匹配单个字符例:find /etc -name init???-size:按照文件大小搜索(单位:数据块【1数据...

weixin_42565971的博客 183

Spark on Yarn 高可用模式部署流程

本文介绍了如何配置Spark和Yarn的高可用(HA)环境,以确保在大规模数据处理中避免单点故障。

xhaoDream的博客 1445

Linux常用命令——文件搜索命令

Linux常用命令——文件搜索命令 (一)权限管理命令:find 命令名称:find 命令所在路径:/bin/find 执行权限:所有用户 语法:find [搜索范围][匹配条件] 功能描述: 文件搜索 范例: 使用name来搜索: (1) $find /etc -name init     在目录/etc中查找文件init(精准搜索) (2) $find /etc -name 星号init星...

Auraros的博客 1054

从零开始:用摩尔线程S4000运行开源AI项目的完整流程

本文详细介绍了如何使用摩尔线程S4000 GPU从零开始运行开源AI项目的完整流程,包括硬件选择、驱动安装、容器化环境配置以及典型AI项目的实战部署。通过性能优化技巧,显著提升推理速度,适合开发者快速上手国产GPU的AI应用开发。

weixin_29231725的博客 581

AI赋能合同审查:构建租赁合同智能审核系统的全流程解析

在商业地产、设备租赁等场景中,合同审核效率直接影响业务流转速度。传统人工审核存在三大痛点:审核周期长(平均2-3个工作日)、合规风险高(条款遗漏率约15%)、人力成本居高不下。智能审核系统可将审核时间压缩至秒级,风险识别准确率提升至98%以上。

理论都是虚的,代码才是王道。 1356

Linux文件搜索命令有哪些?Linux常用命令之文件搜索命令find详解

本文介绍了几种文件搜索命令,其中find是用的最多的也是功能最强大的文件或目录搜索命令,和另一个搜索命令locate的区别是,find命令是全盘搜索,刚创建的文件也能搜索的到,而locate是在文件资料库中进行搜索,对比find命令搜索速度快很多,但是新创建的文件如果没有收录到文件资料库中,使用locate命令是搜索不到的,再就是/tmp目录是不收录到文件资料库的,也就是说使用locate命令搜索不到在/tmp目录下的文件。

我是飞飞啊,不一定温柔,但一定自由 1211

基于STM32单片机设计的智能水温控制系统

本项目研究并实现了一种基于STM32单片机的智能水温控制系统。系统以STM32F103RCT6作为主控制器,通过DS18B20温度传感器实时采集水温数据,利用PID控制算法精确调节5V直流防水型70W加热棒的功率输出,确保水温恒定在设定范围内。此外,采用OLED显示屏显示当前水温和预设上限阀值,并集成ESP8266-WiFi模块与自研Android手机APP进行远程通信和控制。用户可通过本地按键或手机APP设置温度阀值,实现实时监控与智能化管理。整个系统设计旨在提高水资源利用效率,提升生活及工业用水环境的舒

8790

【Linux】Linux常用命令——文件搜索命令

一、文件搜索命令find 二、其他搜索命令

qq_36926037的博客 1902

Sigrity Power SI 3D-EM Full Wave Extraction模式如何进行S参数提取和观测3D电磁场和远场实例分析(一)-差分过孔结构

Sigrity Power SI 3D-EM Full Wave Extraction模式如何进行S参数提取和观测3D电磁场和远场操作指导(一)详细介绍了3D-EM Full Wave Extraction全波S参数提取,下面以一个差分过孔结构进行实例分析,以下图为例。模式如何进行S参数提取和观测3D电磁场和远场实例分析(一)-差分过孔结构。是一个简单的4层板,top换层到bottom层的差分过孔结构。起始频率为100Mhz,截止频率为20Ghz,线性扫描。上面那根曲线是插损,下面那根线是回损。

weixin_54787054的博客 343

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【Linux】Linux的常用命令——文件处理命令、文件搜索命令、压缩与解压命令、关机和重启命令、查看用户信息命令、文件查看命令

linux常用命令 一、常见目录 - /根目录 - /boot 启动目录,启动相关文件 - /dev 设备文件 - /etc 配置文件 - /home 普通用户的家目录,可以操作 - /lib 系统库保存目录 - /mnt 移动设备挂载目录 - /media 光盘挂载目录 - /misc 磁盘机挂载目录 - /root 超级用户的家目录,可以操作 - /tmp 临时目录,可以操作 - /proc ...

2024路在何方 543

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

linux常用命令搜索,Linux常用命令——文件搜索命令

Linux常用命令——文件搜索命令Linux以#号开头的内容都是内容描述或配置项find描述:文件搜索语法:find [搜索范围] [范围条件].当前目录示例:[root@localhost test]# find . li*-name 根据文件名搜索*匹配任意字符示例:[root@localhost test]# find /etc/ -name *init*? 匹配单个字符示例:[root@...

weixin_39526564的博客 167

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Linux常用命令-文件搜索命令

1) which     语法: which [命令名称]       功能描述: 显示系统命令所在目录     范例:  which ls  2) find     语法: find  [搜索路径] [搜索关键字]     功能描述: 查找文件或目录     范例;  find  /etc  -name  init           在目录/etc中查找init        

du_minchao的专栏 470

Linux 常用命令 之 文件搜索

find 语法:find [搜索范围][匹配条件] 1、根据文件名搜索 -name -iname * ? find 目录 -name 条件 精准匹配 例如:find /etc -name fjl (在etc目录下所有名字为fjl的文件)精准查找 find /etc -name fjl* (在etc目录下所有名字为fjl的文件)模糊查找 find /etc -...

u012135425的博客 270

Linux常用命令--文件搜索命令

文件搜索命令find   文件搜索命令:find 命令名称:find 命令所在路径:/bin/find 执行权限:所有用户 语法:find[搜索范围] [匹配条件] 功能描述:文件搜索 范例:  $find /etc -name init     (精确查询)   在目录/etc中查找文件init   -iname不区分大小写  $find /etc -name *init*    (模糊查询) ...

喜三仔的世界 279
上一篇: Docker服务重启后让容器自动启动 | restart参数
下一篇: Docker安装Hadoop
Best_Liu~
博客等级 码龄7年 1万+粉丝 115原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值