find

>Usage

find is an utility used to search for files and directories based on various criteria such as name, type, size, and modification time. It's your go-to command for locating files across directories quickly and flexibly.

>Synopsis

find [path] [options] [expression]

>Options

-name

-name (search by file name): Searches for files that match the given name pattern.

Example 1:

Dots

-zsh

> find . -name "file.txt"


./documents/file.txt

-type

-type (file type): Searches based on file type. Options include f for regular files, d for directories, and l for symbolic links.

Example 2:

Dots

-zsh

> find /var -type d


/var/log
/var/tmp

-size

-size (file size): Finds files based on their size. Use + for greater than, - for less than, and no sign for exact size.

Example 3:

Dots

-zsh

> find . -size +1M


./largefile.txt

-mtime

-mtime (modification time): Searches for files based on the last modification time, in days. +N means older than N days, -N means newer than N days.

Example 4:

Dots

-zsh

> find /home -mtime -7


/home/user/recentfile.txt

-exec

-exec (execute command on found files): Runs a specified command on each file found. Use {} \; to represent each file.

Example 5:

Dots

-zsh

> find . -name "*.log" -exec rm {} \;


# (Deletes all .log files in the current directory)

-user

-user (search by file owner): Finds files owned by a specific user.

Example 6:

Dots

-zsh

> find /var -user root


/var/log/system.log

-perm

-perm (search by file permissions): Searches for files with specific permissions (e.g., 755).

Example 7:

Dots

-zsh

> find . -perm 644


./myfile.txt

-iname

-iname (case-insensitive name search): Similar to -name, but ignores case when matching file names.

Example 8:

Dots

-zsh

> find . -iname "README.md"


./docs/readme.md

-delete

-delete (remove found files): Deletes files that match the search criteria. Be careful, as this option is permanent!

Example 9:

Dots

-zsh

> find . -type f -name "*.tmp" -delete


(Deletes all .tmp files in the current directory)

>Quiz

Progress: Question ? out of ?

Question Title

Page written by Luca Fusetti