find

Linux · Files · available in the simulator

What it does

Searches for files in a directory hierarchy based on various criteria. Supports logical operators with -a (and), -o (or), and ! (not).

Syntax

find [ruta...] [expresión]

Options and parameters

  • -name

    Searches by file name (case-sensitive).

    find . -name "*.log"
  • -iname

    Searches by file name (case-insensitive).

  • -path/-ipath

    matches against full path

  • -size

    Filters by size; +10M matches files greater than 10 megabytes.

    find . -size +10M
  • -type

    Filters by type: f for regular file, d for directory, l for symbolic link.

    find /etc -type f
  • -user/-group

    filters by owner/group

  • -amin/-mmin/-cmin

    accessed/modified/changed in minutes

  • -atime/-mtime/-ctime

    accessed/modified/changed in days

  • -exec ... {} \;

    executes a command for each file

  • -exec ... {} +

    executes the command with all files combined

  • -mtime

    Filters by days since last modification.

    find . -mtime -7
  • -mmin

    Filters by minutes since last modification.

  • -user

    Filters by file owner.

  • -perm

    Filters by file permissions.

  • -maxdepth

    Limits the directory depth searched.

    find . -maxdepth 1 -type d
  • -delete

    Deletes found files.

  • -exec

    Executes a command for each matched file; terminated by \;.

    find . -name "*.tmp" -exec rm {} \;
  • -print0

    Separates results with a null character; useful with xargs -0.

Usage examples

  • find /dev -amin -30
  • find /home/smr1 -size +10M
  • find /etc -size +100k -a -size -1M
  • find /home/smr1 -name "*documento*.docx"
  • find /home/smr1 -ipath "*Linux*"
  • find /boot -user root
  • find /home/smr1/sistemas -type f
  • find /home/smr1 -type f -size +0 -exec du -h {} \;
  • find /home/smr1 -type f -size +0 -exec du -h {} +
  • find . -name '*.log'
  • find /tmp -type f -mtime +7 -delete
  • find . -name "*.log"
  • find /etc -type f
  • find . -size +10M
  • find . -mtime -7
  • find . -maxdepth 1 -type d
  • find . -name "*.tmp" -exec rm {} \;
Practise find

Related commands