Forrest logo
tool overview
On this page you find all important commands for the CLI tool find. If the command you are looking for is missing please ask our AI.

find

The find program searches a directory tree to find a file or group of files. It traverses the directory tree and reports all occurrences of a file matching the user's specifications. The find program includes very powerful searching capability.

Articles in our magazine for find:

How to find files on the command line?

Sometimes it is important to find certain files. Be it particularly large ones or ones that contain certain information. All this is just a command away on the command line.

List of commands for find:

  • cpio:tldr:7e278 cpio: Copy all files and directories in a directory and add them [o]nto an archive, in [v]erbose mode.
    $ find ${path-to-directory} | cpio -ov > ${archive-cpio}
    try on your machine
    explain this command
  • files:delete:extension Delete all files with the given extension
    $ find ${directory} -type f -name '*.${extension}' -delete
    try on your machine
    explain this command
  • find:tldr:0bc58 find: Find files matching multiple path/name patterns.
    $ find ${root_path} -path '${**-path-**-*-ext}' -or -name '${*pattern*}'
    try on your machine
    explain this command
  • find:tldr:1d82c find: Run a command for each file (use `{}` within the command to access the filename).
    $ find ${root_path} -name '${*-ext}' -exec ${wc -l {} }\;
    try on your machine
    explain this command
  • find:tldr:1e3af find: Find files matching a given pattern, excluding specific paths.
    $ find ${root_path} -name '${*-py}' -not -path '${*-site-packages-*}'
    try on your machine
    explain this command
  • find:tldr:35c1a find: Find files matching a given size range, limiting the recursive depth to "1":.
    $ find ${root_path} -maxdepth 1 -size ${+500k} -size ${-10M}
    try on your machine
    explain this command
  • find:tldr:4b725 find: Display lines that do not contain the specified string.
    $ find "${string}" ${path\to\file_or_directory} /v
    try on your machine
    explain this command
  • find:tldr:4fca5 find: Display line numbers with the list of lines.
    $ find "${string}" ${path\to\file_or_directory} /n
    try on your machine
    explain this command
  • find:tldr:8efff find: Find empty (0 byte) files and delete them.
    $ find ${root_path} -type ${f} -empty -delete
    try on your machine
    explain this command
  • find:tldr:9da7a find: Find files modified in the last 7 days.
    $ find ${root_path} -daystart -mtime -${7}
    try on your machine
    explain this command
  • find:tldr:b06eb find: Find lines that contain a specified string.
    $ find "${string}" ${path\to\file_or_directory}
    try on your machine
    explain this command
  • find:tldr:d74c9 find: Find directories matching a given name, in case-insensitive mode.
    $ find ${root_path} -type d -iname '${*lib*}'
    try on your machine
    explain this command
  • find:tldr:e5430 find: Display the count of lines that contain the specified string.
    $ find "${string}" ${path\to\file_or_directory} /c
    try on your machine
    explain this command
  • fzf:tldr:46b60 fzf: Select multiple files with `Shift + Tab` and write to a file.
    $ find ${path-to-directory} -type f | fzf --multi > ${filename}
    try on your machine
    explain this command
  • fzf:tldr:fc1f8 fzf: Start fzf on all files in the specified directory.
    $ find ${path-to-directory} -type f | fzf
    try on your machine
    explain this command
  • linux:files:count:directory Return the number of sub-directories in a given path
    $ find ${directory_to_count_in} -type d | wc -l
    try on your machine
  • linux:files:count:files Return the number of files in a given path
    $ find ${directory_to_count_in} -type f | wc -l
    try on your machine
  • linux:files:find:big Find all files that are larger than a given size.
    $ find ${path_to_check} -type f -size +${size_in_mega_byte}M
    try on your machine
    explain this command
  • linux:files:find:empty Find all empty files under a certain path
    $ find ${directory} -type f -empty
    try on your machine
  • linux:files:find:modified Find all files which are modified in a given timespan.
    $ find ${directory} -mmin -${time_in_minutes}
    try on your machine
  • linux:files:find:name Find all files with a given name.
    $ find ${dir_to_search_in} -name ${filename}
    try on your machine
  • linux:files:find:older Find all files that are older than a given period.
    $ find ${dir_to_search_in} -mtime +${number_on_days} -print
    try on your machine
  • pbcopy:tldr:61937 pbcopy: Place the results of a specific command in the clipboard.
    $ find . -type t -name "*.png" | pbcopy
    try on your machine
    explain this command
  • peco:tldr:9a45b peco: Start peco on all files in the specified directory.
    $ find ${path-to-directory} -type f | peco
    try on your machine
    explain this command
  • shell:warp:99fb0 Search for specified file types and run a certain command for each file
    $ find -E ${path} -iregex ".*\.(${extensions})" -print | xargs -n1 -I _item ${command} _item
    try on your machine
    explain this command
  • sk:tldr:21cd6 sk: Select multiple files with `Shift + Tab` and write to a file.
    $ find ${path-to-directory} -type f | sk --multi > ${filename}
    try on your machine
    explain this command
  • sk:tldr:d1259 sk: Start skim on all files in the specified directory.
    $ find ${path-to-directory} -type f | sk
    try on your machine
    explain this command
  • xargs:tldr:67693 xargs: Delete all files with a `.backup` extension (`-print0` uses a null character to split file names, and `-0` uses it as delimiter).
    $ find . -name ${'*-backup'} -print0 | xargs -0 rm -v
    try on your machine
    explain this command
  • xe:tldr:ef9aa xe: Delete all files with a `.backup` extension.
    $ find . -name ${'*-backup'} | xe rm -v
    try on your machine
    explain this command
tool overview