githubEdit

rectangle-terminalfind

πŸ” find Command in Linux

The find command is used to search for files and directories within a directory hierarchy. Below is a reference for common options and use cases.


🧰 Common Options

Option
Description

-name

Search for files by name

-iname

Search for files by name (case-insensitive)

-type

Search by file type (e.g., file, directory, symlink)

-size

Search for files by size

-mtime

Search for files by modification time

-perm

Search for files by permissions

-exec

Execute commands on found files

-maxdepth

Limit the depth of the search

-prune

Exclude directories from the search


πŸ“‹ Basic Syntax

find [path] [expression]
  • path: Directory or path to search (use . for current directory).

  • expression: Search criteria, like file name, type, permissions, etc.


πŸ“ Common Commands

Search by File Name

Search by File Type

  • Regular files:

  • Directories:

  • Symbolic links:

Search by Size

  • Files larger than 1GB:

  • Files smaller than 100KB:

Search by Modification Time

  • Modified within the last 7 days:

  • Modified more than 30 days ago:

Search by Permissions

  • Files with specific permissions (e.g., 755):


πŸ“€ Execute Commands on Found Files

Run Command on Found Files

  • Example: Delete all .log files

  • Example: Print the list of files

Use + for Efficient Execution

  • This will group the found files and run the command only once, rather than for each file.


βš™οΈ Combining Multiple Conditions

Find files that are .txt or .md

Find files with size greater than 10MB and modified in the last 7 days


πŸ’‘ Additional Tips

  • find can be slow if searching large directories. Combine with -prune to skip certain directories.

  • Use -maxdepth to limit the search depth.


Last updated