GO KALI FREE
Search Commands

find Linux Command

Searches for files and directories in a directory hierarchy by name, type, size, etc.

What does find do?

Searches for files and directories in a directory hierarchy by name, type, size, etc.

Syntax

find [path] [expression]

Practical example

find /home -name '*.txt' -size +1M

Questions about find

How do I find files by name?

Use `find /path -name 'filename'` to search by exact name, or `find /path -iname 'filename'` for case-insensitive matching.

How do I find files by type?

Use `find /path -type f` for regular files, `-type d` for directories, or `-type l` for symbolic links. The type filter is essential for narrowing results.

How do I find files modified in the last 7 days?

Use `find /path -mtime -7` to find files modified in the last 7 days. Use `-mtime +7` for files older than 7 days.

How do I find files by size?

Use `find /path -size +100M` for files larger than 100MB. Use `-size -10M` for files smaller than 10MB, and `k` for kilobytes.

How do I find and execute a command on found files?

Use `find /path -name '*.log' -exec rm {} \;` to delete all .log files. The `{}` is replaced with each found file path.

How do I find empty files or directories?

Use `find /path -empty` to find both empty files and empty directories. Add `-type f` or `-type d` to specify which one.

How do I find files with specific permissions?

Use `find /path -perm 755` for exact permissions, or `-perm /u+x` for files executable by the owner.

How do I find files and delete them safely?

First test with `find /path -name '*.tmp' -print` to see what will be deleted, then run with `-delete` instead of `-print`.

Related Search Commands

xargs

Builds and executes command lines from standard input (useful with pipes).

grep

Searches for patterns (text or regex) inside files and prints matching lines.

tr

Translates, deletes, or squeezes characters from standard input.

locate

Quickly finds files by name using a pre-built database (run updatedb to refresh).

cut

Extracts specific columns/fields from each line of a file.

which

Shows the full path of the executable that would run for a given command.