转自: http://www.tecmint.com/35-practical-examples-of-linux-find-command/

35 Practical Examples of Linux Find Command

  1. Part I: Basic Find Commands for Finding Files with Names
  2. Part II: Find Files Based on their Permissions
  3. Part III: Search Files Based On Owners and Groups
  4. Part IV: Find Files and Directories Based on Date and Time
  5. Part V: Find Files and Directories Based on Size
Part I – Basic Find Commands for Finding Files with Names

1. Find Files Using Name in Current Directory

Find all the files whose name is tecmint.txt in a current working directory.

# find . -name tecmint.txt./tecmint.txt

2. Find Files Under Home Directory

Find all the files under /home directory with name tecmint.txt.

# find /home -name tecmint.txt/home/tecmint.txt

3. Find Files Using Name and Ignoring Case

Find all the files whose name is tecmint.txt and contains both capital and small letters in/home directory.

# find /home -iname tecmint.txt./tecmint.txt
./Tecmint.txt

4. Find Directories Using Name

Find all directories whose name is Tecmint in / directory.

# find / -type d -name Tecmint/Tecmint

5. Find PHP Files Using Name

Find all php files whose name is tecmint.php in a current working directory.

# find . -type f -name tecmint.php./tecmint.php

6. Find all PHP Files in Directory

Find all php files in a directory.

# find . -type f -name "*.php"./tecmint.php
./login.php
./index.php
Part II – Find Files Based on their Permissions

7. Find Files With 777 Permissions

Find all the files whose permissions are 777.

# find . -type f -perm 0777 -print

8. Find Files Without 777 Permissions

Find all the files without permission 777.

# find / -type f ! -perm 777

9. Find SGID Files with 644 Permissions

Find all the SGID bit files whose permissions set to 644.

# find / -perm 2644

10. Find Sticky Bit Files with 551 Permissions

Find all the Sticky Bit set files whose permission are 551.

# find / -perm 1551

11. Find SUID Files

Find all SUID set files.

# find / -perm /u=s

12. Find SGID Files

Find all SGID set files.

# find / -perm /g+s

13. Find Read Only Files

Find all Read Only files.

# find / -perm /u=r

14. Find Executable Files

Find all Executable files.

# find / -perm /a=x

15. Find Files with 777 Permissions and Chmod to 644

Find all 777 permission files and use chmod command to set permissions to 644.

# find / -type f -perm 0777 -print -exec chmod 644 {} \;

16. Find Directories with 777 Permissions and Chmod to 755

Find all 777 permission directories and use chmod command to set permissions to 755.

# find / -type d -perm 777 -print -exec chmod 755 {} \;

17. Find and remove single File

To find a single file called tecmint.txt and remove it.

# find . -type f -name "tecmint.txt" -exec rm -f {} \;

18. Find and remove Multiple File

To find and remove multiple files such as .mp3 or .txt, then use.

# find . -type f -name "*.txt" -exec rm -f {} \;OR# find . -type f -name "*.mp3" -exec rm -f {} \;

19. Find all Empty Files

To file all empty files under certain path.

# find /tmp -type f -empty

20. Find all Empty Directories

To file all empty directories under certain path.

# find /tmp -type d -empty

21. File all Hidden Files

To find all hidden files, use below command.

# find /tmp -type f -name ".*"
Part III – Search Files Based On Owners and Groups

22. Find Single File Based on User

To find all or single file called tecmint.txt under / root directory of owner root.

# find / -user root -name tecmint.txt

23. Find all Files Based on User

To find all files that belongs to user Tecmint under /home directory.

# find /home -user tecmint

24. Find all Files Based on Group

To find all files that belongs to group Developer under /home directory.

# find /home -group developer

25. Find Particular Files of User

To find all .txt files of user Tecmint under /home directory.

# find /home -user tecmint -iname "*.txt"
Part IV – Find Files and Directories Based on Date and Time

26. Find Last 50 Days Modified Files

To find all the files which are modified 50 days back.

# find / -mtime 50

27. Find Last 50 Days Accessed Files

To find all the files which are accessed 50 days back.

# find / -atime 50

28. Find Last 50-100 Days Modified Files

To find all the files which are modified more than 50 days back and less than 100 days.

# find / -mtime +50 –mtime -100

29. Find Changed Files in Last 1 Hour

To find all the files which are changed in last 1 hour.

# find / -cmin -60

30. Find Modified Files in Last 1 Hour

To find all the files which are modified in last 1 hour.

# find / -mmin -60

31. Find Accessed Files in Last 1 Hour

To find all the files which are accessed in last 1 hour.

# find / -amin -60
Part V – Find Files and Directories Based on Size

32. Find 50MB Files

To find all 50MB files, use.

# find / -size 50M

33. Find Size between 50MB – 100MB

To find all the files which are greater than 50MB and less than 100MB.

# find / -size +50M -size -100M

34. Find and Delete 100MB Files

To find all 100MB files and delete them using one single command.

# find / -size +100M -exec rm -rf {} \;

35. Find Specific Files and Delete

Find all .mp3 files with more than 10MB and delete them using one single command.

# find / -type f -name *.mp3 -size +10M -exec rm {} \;

That’s it, We are ending this post here, In our next article we will discuss more about other Linux commands in depth with practical examples. Let us know your opinions on this article using our comment section.

Linux命令Find实例相关推荐

  1. linux命令diff实例,举例说明Linux diff 命令

    在比较文件的时候,通常会用基于GUI的软件.很少有人真正会为了这个目的使用命令行工具.虽然说使用命令行来比较文件/目录并不像一件小事儿那样容易,但是如果你是一个Linux使用者,那么我想你应该知道如何 ...

  2. c 实现linux命令wc,实例分析linux常见命令之wc命令用法。

    Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出.其主要功能是统计指定文件中的字节数.字数.行数,并将统计结果显示输出.该命令统计指定 ...

  3. Linux命令和实例大全

    目  录 引言    1 一.安装和登录    2

  4. 华为手机怎么下载linux命令,在linux命令

    REMOTE_DIR为将根证书上传到弹性云服务器的文件目录. Windows操作系统下,请使用远程连接工具上传根证书. 连接数据库实例. 方式一:通过Linux命令连接实例 ./mongo --hos ...

  5. flac3d命令流实例大全_如何在Linux上使用xargs命令

    大家好,我是良许. 在使用 Linux 时,你是否遇到过需要将一些命令串在一起,但是其中一个命令不接受管道输入的情况呢?在这种情况下,我们就可以使用 xargs 命令.xargs 可以将一个命令的输出 ...

  6. Linux命令行抓包及包解析工具tshark(wireshark)使用实例解析

    在Linux下,当我们需要抓取网络数据包分析时,通常是使用tcpdump抓取网络raw数据包存到一个文件,然后下载到本地使用wireshark界面网络分析工具进行网络包分析. 最近才发现,原来wire ...

  7. php java执行linux_java_java执行Linux命令的方法,本文实例讲述了java执行Linux命 - phpStudy...

    java执行Linux命令的方法 本文实例讲述了java执行Linux命令的方法.分享给大家供大家参考.具体实现方法如下: public class StreamGobbler extends Thr ...

  8. 实例解说Linux命令行uniq

    Linux命令uniq的作用是过滤重复部分显示文件内容,这个命令读取输入文件,并比较相邻的行.在正常情况下,第二个及以后更多个重复行将被删去,行比较是根据所用字符集的排序序列进行的.该命令加工后的结果 ...

  9. oracle登录日志查看_last命令详解--查看Linux 登录日志+实例说明

    概述 前面分享了一个脚本来记录登录用户的操作历史,今天主要是介绍last命令来查看linux登录日志,附实例说明. last命令介绍 1.查看Linux 登录日志: last 命令输入字段解释: 第一 ...

最新文章

  1. java判断一个对象是否为空_Java中判断对象是否为空的方法的详解
  2. 数据处理程序语言中的基本数据类型
  3. php 一行代码解决二维数组去重
  4. openacc的Linux安装教程,科学网—opensuse 13.1 系统 openACC编译器使用及GPU并行编程环境配置 - 马小军的博文...
  5. 变形版汉诺塔:LeetCode:70爬楼梯
  6. Android 数据库(SQLite)【简介、创建、使用(增删改查、事务、实战演练)、数据显示控件(ListView、Adapter、实战演练-绿豆通讯录)】
  7. PHP中Header函数和PHP_AUTH_USER做用户验证
  8. python列表求平均值_python与统计概率思维
  9. C-Lodop回调函数的触发
  10. CSS,让100%的宽度,自动减10,让100%的高度,自动减10,可以加减乘除
  11. arduino倾斜开关python语言_Arduino小白的学习记录:倾斜开关实验
  12. [转载]虚拟机磁盘空间已满的发现和解决
  13. python无法使用decode,Python处理文件名或路径名中无法decode代码问题
  14. .NET 指南:属性与方法之间的选择
  15. linux硬盘格式哪个好,linux使用哪种硬盘分区格式会比较好
  16. 在linux上压缩文件,Linux上压缩文件的 5 种方法
  17. C相关笔试题或者面试题中的概念以及技巧题2
  18. 关于XML的pull解析的小发现
  19. 系统管理之Systemd详解(centos7)
  20. 猿辅导python面试_猿辅导西安少儿编程班主任面试:为什么选择猿辅导 猿辅导是一个 - 职朋职业圈...

热门文章

  1. Win2003_IIS6服务器设置排错解答
  2. 承载网络开启后显示无法连接到Internet,已解决
  3. [CSS] Use CSS Counters to Create Pure CSS Dynamic Lists
  4. 【Spring-AOP-1】AOP相关概念
  5. ASP.NET MVC 3: Razor视图引擎中 @: 和text 语法【转载】
  6. Sharepoint 2010使用手记(1)
  7. 服务器与客户端的文件传输报告,网络文件传输设计报告.doc
  8. access中总计为first_用Access开发生产管理系统
  9. Github用户注册流程
  10. 多个div并排居中显示