Mommy, I found it! — 15 Practical Linux Find Command Examples

机器人强化学习入门学习笔记 如果你追求高精度动力学仿真、用于强化学习或机器人研究,MuJoCo 是一个非常优秀的选择。如果需要快速实验、使用真实机器人模型,PyBullet 或 Gazebo可能更合适;如果你追求大规模并行训练,Isaac Gym 或 BraX会更高效。legged gym底层是​编辑isaacgym,基于gpu训练可以多环境并行训练,收敛到一个稳定行走的策略快。本视频MuJoCo基于cpu训练很慢。 阅读详情

 原文地址:http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/

Apart from the basic operation of looking for files under a directory structure, you can also perform several practical operations using find command that will make your command line journey easy.
In this article, let us review 15 practical examples of Linux find command that will be very useful to both newbies and experts.
First, create the following sample empty files under your home directory to try some of the find command examples mentioned below.

# vim create_sample_files.sh
touch MybashProgram.sh
touch mycprogram.c
touch MyCProgram.c
touch Program.c

mkdir backup
cd backup

touch MybashProgram.sh
touch mycprogram.c
touch MyCProgram.c
touch Program.c

# chmod +x create_sample_files.sh

# ./create_sample_files.sh

# ls -R
.:
backup                  MybashProgram.sh  MyCProgram.c
create_sample_files.sh  mycprogram.c      Program.c

./backup:
MybashProgram.sh  mycprogram.c  MyCProgram.c  Program.c

1. Find Files Using Name

This is a basic usage of the find command. This example finds all files with name — MyCProgram.c in the current directory and all it’s sub-directories.

# find -name "MyCProgram.c"
./backup/MyCProgram.c
./MyCProgram.c

2. Find Files Using Name and Ignoring Case

This is a basic usage of the find command. This example finds all files with name — MyCProgram.c (ignoring the case) in the current directory and all it’s sub-directories.

# find -iname "MyCProgram.c"
./mycprogram.c
./backup/mycprogram.c
./backup/MyCProgram.c
./MyCProgram.c

3. Limit Search To Specific Directory Level Using mindepth and maxdepth

Find the passwd file under all sub-directories starting from root directory.

# find / -name passwd
./usr/share/doc/nss_ldap-253/pam.d/passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd


Find the passwd file under root and one level down. (i.e root — level 1, and one sub-directory — level 2)

# find -maxdepth 2 -name passwd
./etc/passwd


Find the passwd file under root and two levels down. (i.e root — level 1, and two sub-directories — level 2 and 3 )

# find / -maxdepth 3 -name passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd


Find the password file between sub-directory level 2 and 4.

# find -mindepth 3 -maxdepth 5 -name passwd
./usr/bin/passwd
./etc/pam.d/passwd

4. Executing Commands on the Files Found by the Find Command.

In the example below, the find command calculates the md5sum of all the files with the name MyCProgram.c (ignoring case). {} is replaced by the current file name.

# find -iname "MyCProgram.c" -exec md5sum {} \;
d41d8cd98f00b204e9800998ecf8427e  ./mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/MyCProgram.c
d41d8cd98f00b204e9800998ecf8427e  ./MyCProgram.c

5. Inverting the match.

Shows the files or directories whose name are not MyCProgram.c .Since the maxdepth is 1, this will look only under current directory.

# find -maxdepth 1 -not -iname "MyCProgram.c"
.
./MybashProgram.sh
./create_sample_files.sh
./backup
./Program.c

6. Finding Files by its inode Number.

Every file has an unique inode number, using that we can identify that file. Create two files with similar name. i.e one file with a space at the end.

# touch "test-file-name"

# touch "test-file-name "
[Note: There is a space at the end]

# ls -1 test*
test-file-name
test-file-name


From the ls output, you cannot identify which file has the space at the end. Using option -i, you can view the inode number of the file, which will be different for these two files.

# ls -i1 test*
16187429 test-file-name
16187430 test-file-name


You can specify inode number on a find command as shown below. In this example, find command renames a file using the inode number.

# find -inum 16187430 -exec mv {} new-test-file-name \;

# ls -i1 *test*
16187430 new-test-file-name
16187429 test-file-name


You can use this technique when you want to do some operation with the files which are named poorly as shown in the example below. For example, the file with name — file?.txt has a special character in it. If you try to execute “rm file?.txt”, all the following three files will get removed. So, follow the steps below to delete only the “file?.txt” file.

# ls
file1.txt  file2.txt  file?.txt


Find the inode numbers of each file.

# ls -i1
804178 file1.txt
804179 file2.txt
804180 file?.txt


Use the inode number to remove the file that had special character in it as shown below.

# find -inum 804180 -exec rm {} \;

# ls
file1.txt  file2.txt
[Note: The file with name "file?.txt" is now removed]

7. Find file based on the File-Permissions

Following operations are possible.

  • Find files that match exact permission
  • Check whether the given permission matches, irrespective of other permission bits
  • Search by giving octal / symbolic representation


For this example, let us assume that the directory contains the following files. Please note that the file-permissions on these files are different.

# ls -l
total 0
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all
-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read
---------- 1 root root 0 2009-02-19 20:31 no_for_all
-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file
-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read
----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read


Find files which has read permission to group. Use the following command to find all files that are readable by the world in your home directory, irrespective of other permissions for that file.

# find . -perm -g=r -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 0 2009-02-19 20:30 ./everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 ./all_for_all
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read
-rw-r----- 1 root root 0 2009-02-19 20:27 ./others_can_also_read


Find files which has read permission only to group.

# find . -perm g=r -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read


Find files which has read permission only to group [ search by octal ]

# find . -perm 040 -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read

8. Find all empty files (zero byte file) in your home directory and it’s subdirectory

Most files of the following command output will be lock-files and place holders created by other applications.

# find ~ -empty


List all the empty files only in your home directory.

# find . -maxdepth 1 -empty


List only the non-hidden empty files only in the current directory.

# find . -maxdepth 1 -empty -not -name ".*"

9. Finding the Top 5 Big Files

The following command will display the top 5 largest file in the current directory and it’s subdirectory. This may take a while to execute depending on the total number of files the command has to process.

# find . -type f -exec ls -s {} \; | sort -n -r | head -5

10. Finding the Top 5 Small Files

Technique is same as finding the bigger files, but the only difference the sort is ascending order.

# find . -type f -exec ls -s {} \; | sort -n  | head -5


In the above command, most probably you will get to see only the ZERO byte files ( empty files ). So, you can use the following command to list the smaller files other than the ZERO byte files.

# find . -not -empty -type f -exec ls -s {} \; | sort -n  | head -5

11. Find Files Based on file-type using option -type

Find only the socket files.

# find . -type s


Find all directories

# find . -type d


Find only the normal files

# find . -type f


Find all the hidden files

# find . -type f -name ".*"


Find all the hidden directories

# find -type d -name ".*"

12. Find files by comparing with the modification time of other file.

Show files which are modified after the specified file. The following find command displays all the files that are created/modified after ordinary_file.

# ls -lrt
total 0
-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read
----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read
-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file
-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all
---------- 1 root root 0 2009-02-19 20:31 no_for_all

# find -newer ordinary_file
.
./everybody_read
./all_for_all
./no_for_all

13. Find Files by Size

Using the -size option you can find files by size.

Find files bigger than the given size

# find ~ -size +100M


Find files smaller than the given size

# find ~ -size -100M


Find files that matches the exact given size

# find ~ -size 100M


Note: – means less than the give size, + means more than the given size, and no symbol means exact given size.

14. Create Alias for Frequent Find Operations

If you find some thing as pretty useful, then you can make it as an alias. And execute it whenever you want.


Remove the files named a.out frequently.

# alias rmao="find . -iname a.out -exec rm {} \;"
# rmao


Remove the core files generated by c program.

# alias rmc="find . -iname core -exec rm {} \;"
# rmc

15. Remove big archive files using find command

The following command removes *.zip files that are over 100M.

# find / -type f -name *.zip -size +100M -exec rm -i {} \;"

Remove all *.tar file that are over 100M using the alias rm100m (Remove 100M). Use the similar concepts and create alias like rm1g, rm2g, rm5g to remove file size greater than 1G, 2G and 5G respectively.

# alias rm100m="find / -type f -name *.tar -size +100M -exec rm -i {} \;"
# alias rm1g="find / -type f -name *.tar -size +1G -exec rm -i {} \;"
# alias rm2g="find / -type f -name *.tar -size +2G -exec rm -i {} \;"
# alias rm5g="find / -type f -name *.tar -size +5G -exec rm -i {} \;"

# rm100m
# rm1g
# rm2g
# rm5g

Find Command Examples Second Part

If you liked this Mommy article on find command, don’t forget to check-out the Daddy article of the find command — Daddy, I found it!, 15 Awesome Linux Find Command Examples (Part2)

Awesome Linux Articles

Following are few awesome 15 examples articles that you might find helpful.

【四足机器人项目实战】四足机器人嵌入式硬件设计 系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言一、电源管理板设计及制作二、通讯中继板设计及制作三、力控无刷电机驱动板设计及制作1.磁场定向控制FOC控制原理2.电机转子位置、速度检测原理3.硬件CAN通讯原理 前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对四足机器人–嵌入式硬件设计做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章 提示:以下是本篇文章正文内容 一、电 阅读详情

相关推荐

储能逆变器动态无功补偿:从原理到算法实现

本文深入解析了储能逆变器动态无功补偿的核心原理与算法实现。通过四象限运行与解耦控制技术,储能逆变器可在充放电的同时,快速、精准地调节无功功率,有效提升电网电能质量与功率因数。文章详细阐述了从相位调节、容量限制到PI控制算法的完整技术路径,并结合工程实践,探讨了其在光伏/储能系统中的协同控制策略与进阶应用价值。

weixin_29216353的博客 207

find xargs指令浅尝

1、find命令的一般形式为; find pathname -options [-print -exec -ok ...] 2、find命令的参数; pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。

614

Python+Selenium实战:5分钟搞定快手评论区数据采集(附完整代码)

本文详细介绍了如何使用Python和Selenium快速采集快手评论区数据,提供完整的代码实现和优化方案。通过动态加载处理和智能等待策略,5分钟内即可构建高效的评论采集工具,适用于用户行为分析和内容挖掘等场景。

weixin_30415113的博客 344

【Linux】 find指令(文件查找)

每一种操作系统都有成千上万的文件组成,对于linux这样“一切皆文件”的操作系统来说更不例外,大家应该都能很轻松使用windows下的文件查找功能,但是对linux这一功能可能并不是很熟悉,其实想玩linux的你更要牢牢掌握这个命令,因为linux不像windows那样有固定的文件名后缀,并且因为linux阵营下百家争鸣的特性,一个相同的文件在不同的发行版,可能会有不同...

weixin_34124939的博客 643

如何对TBSS的结果进行统计学的分析,已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析??

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值。

**My Coding Family** 1439

华为OD技术面真题 - 计算机网络 - 1

汇总华为OD技术面八股文计算机网络相关八股文,高频技术真题并提供详细解答。

qq_45776114的博客 1327

linux find命令使用教程

find是用来在文件系统上查找复合条件的文件find命令有非常强大的灵活性,可以指定丰富的搜索条件(如文件权限属主属组文件类型日期和大小等)来定位系统中的文件和目录,同时还支持对对搜索的结果进行命令操作。

叶新东老师的博客 963

petalinux2022.2启动文件编译配置

petalinux2021之前的版本里,导入目录components/yocto/下的“environment-setup-aarch64-xilinx-linux” 和 “layers/core/oe-init-build-env”的环境,能使用Yocto的devtool工具。(加入下面内容,先petalinux-build下载完成后才能有源码)制作 BOOT.BIN 启动文件:petalinux-package --boot --fsbl --fpga --u-boot --force。

wangjie36的博客 1389

linux-find command(transferred)

一、find 命令格式1、find命令的一般形式为;2、find命令的参数;3、find命令选项;4、使用exec或ok来执行shell命令;二、find命令的例子;1、查找当前用户主目录下的所有文件;2、为了在当前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件;3、为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径;4、查找/var/logs...

200

网络流量异常信息分析方法研究

本课题针对网络安全中网络流量异常的分析方法进行研究,提出一种基于机器学习和深度学习的异常检测算法。该算法采用卷积神经网络(CNN)和长短时记忆神经网络(LSTM)结合的方式,通过训练得到二分类模型,从而实现对网络流量异常的检测。随着互联网的飞速发展,网络攻击事件日益增多,网络安全问题成为了亟待解决的问题之一。常见的网络攻击手段包括 DDoS 攻击、SQL 注入、XSS 攻击等,这些攻击手段可能导致网络系统发生异常,给网络运维、数据安全带来极大的挑战。

肥晨开发的学习之路 1035

筑牢上线前安全防线:安全运维服务中的检测实践与深化

在日益严峻的网络安全形势下,将漏洞扫描、渗透测试和基线核查有机结合的上线前安全检测,是保障信息系统安全、稳定、合规上线的基石。通过专业、严谨、协作的检测实践,乙方安全团队能够有效协助甲方在系统生命周期的起点就构筑起坚固的安全防线,为业务的顺利开展和用户的信任保驾护航,真正实现“安全赋能业务”的价值。这道“守门人”的职责,是数字时代企业稳健前行的不可或缺的保障。专业的安全服务提供商(乙方)需要与甲方(系统所有者/运营方)建立紧密、透明、协作的伙伴关系,实现风险的闭环管理,甚至推动甲方安全能力的长期提升。

huluang的专栏 183

Linux系统-find命令

find命令用来在指定目录下查找文件。任何在参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件(递归遍历文件夹)。并且将查找到的子目录和文件全部进行显示。

m0_58341177的博客 2356

2026 拉勾网:JA4+指纹绕过 + sign逆向 + 动态城市参数,月采集10万+数据实战

2026年拉勾网反爬技术全面升级,采用JA4+ TLS指纹识别、动态sign签名等多维度防护体系。本文提供工业级爬虫解决方案,通过curl_cffi模拟浏览器指纹、逆向sign加密算法、动态生成城市参数三大核心技术,实现高效稳定的数据采集。系统采用分层架构设计,包含任务调度、签名生成、多线程引擎等模块,单月可获取10万+条招聘数据。重点解析了JA4+指纹识别原理、传统方法的局限性,以及通过HMAC-SHA256算法逆向sign参数的完整过程。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2393

Mommy, I found it! — 15 Practical Linux Find Command Examples(PART 1)

by SATHIYAMOORTHY on MARCH 4, 2009 Apart from the basic operation of looking for files under a directory structure, you can also perform several practical operations using find command

fengzei886的专栏 527

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Linux中find命令

1.find命令1.find命令Linux find 命令用于在指定目录下查找文件和目录。它可以使用不同的选项来过滤和限制查找的结果。2.基本语法find [⽂件路径] [选项选项的值-name *-type f|d。

weixin_69209121的博客 5933

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

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

linux系统查找文件夹命令,Linux系统文件查找命令find的基本使用及其高级用法

在Linux系统维护工作时,经常会查找文本文件。例如:假如:web服务器经常出现延迟,或者经常会出现一些参数的错误信息。1、考虑带宽问题2、考虑我的配置文件问题:例如:是不是被其它人更改过所造成的参数、延迟等信息,这样我们就会用到find命令来查找文件的相关信息,并加以修改。如果我们做系统运维这方面的工作时,会经常用到find命令来帮助我们完成文件的查找工作,所以我们要认真学习find命令的使用及...

weixin_35645077的博客 805

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

学习_Linux_Command_find_01

linux 命令 find 用法:find path -option [ -print ] [ -exec -ok command ] {} \; 使用说明: expression 中可使用的选项有二三十个之多,在此只介绍最常用的部分。 -exec:对搜索的结果执行指定的shell命令。注意格式要正确:"-exec 命令 {} \;"。注意“{}” 与\;之间有空格。 -mount,-x

221

linux command find

Linux commandfind 【Purpose】 Learning linux command nmon 【Eevironment】 Ubuntu 16.04 terminal 【Procdeure】 example1: find file size bigger than 50M find ./ -type f ...

weixin_30900589的博客 150

find(1) command

find 命令用于在指定目录查找文件。find 可以指定一些匹配条件,如按文件名、文件类型、文件属主甚至是时间戳来查找文件,默认递归查找。

Doublelv 的博客专栏。 2443

find command基本使用

find命令通常用于根据文件名查找文件,这是最基本用法。 find [path] -name/-iname [filename] path写要查找的路径,自动递归查找 filename写文件名,可以使用通配符*还有其他什么的表达式 具体细节请man find查阅文档。 ...

X 614

find command

find命令 -- 之查找指定时间内修改过的文件 比如我们要查找linux下指定时间内做过改动的文件,我们可以用find命令,其实find命令的功能十分强大,下面我们通过几个简单的例子来学习下find命令的简单用法: find /opt -iname "*" -atime 1 -type f 找出 /opt 下一天前访问过的文件 选项 OPTIONS 所有的选项都总是返回真值,它们总会被

弱水三千 只取一韶 1120

linux find command

linux find command

hellochenlian的专栏 910

win10解决l开机grub页面问题

关于win10启动后出现grub页面 出现原因:电脑非正常关机:死机/黑屏/强制关机等 eg: 笔者强制关机后 开机出现grub引导页面 因为之前安装过Linux所以grub可能被改变 考虑到开发机配置环境复杂选择查资料解决 grub1与grub2有区别 在grub2中没有root/rootnoverify等命令 所以开始解决找资料过程中 根据资料解决发现 grub can’t find … 其实...

qq_42239081的博客 1万+

linux指令 find指令详解

find查找 ,搜索具有即时性的特点,不需要数据库,相对会比较慢一些1、从指定路径下递归向下搜索文件2、支持按照各种条件方式搜索3、支持对搜索得到的文件进一步用指令语法: # find [路径] [参数] [表达式]常用参数-user可以根据文件拥有者来查找文件 # find /root -user root在root目录下查找...

weixin_33766805的博客 206

Linux find command

原贴:http://blog.chinaunix.net/u/19782/showart_374813.html     Linux find command

最实用的Linux博客 1827

(linux) find command

find命令的主要功能是在系统中查找文件或目录: find命令的一般形式为:find pathname -options [-print -exec -ok]print为对匹配文件输出到标准输出,默认为标准输出,故可不写exec为对匹配文件执行该参数给出的shell命令,形式为'command' {} \;ok与exec类似,更安全,每步需要用户确认。 1.-name 根据文件名匹配。例如:fin...

网络飞鸥 246
上一篇: 15 Practical Grep Command Examples In Linux / UNIX
下一篇: Unix Sed Tutorial: Printing File Lines using Address and Patterns
jackie_gnu
博客等级 码龄16年 3粉丝 114原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值