$ find . -type d -empty
Delete all empty files in a directory
$ find . -type f -empty -delete
$ find . -type d -empty
Delete all empty files in a directory
$ find . -type f -empty -delete
$ find /opt /usr /var -name foo.scala -type f
Find files with multiple dirs
$ find . -type f \( -name "\*.sh" -o -name "\*.txt" \)
Find files with .sh
and .txt
extensions
Find single file based on user
$ find / -user root -name tecmint.txt
Find all files based on user
$ find /home -user tecmint
Find all files based on group
$ find /home -group developer
Find particular files of user
$ find /home -user tecmint -iname "\*.txt"
Find the files whose permissions are 777.
$ find . -type f -perm 0777 -print
Find the files without permission 777.
$ find / -type f ! -perm 777
Find SUID set files.
$ find / -perm /u=s
Find SGID set files.
$ find / -perm /g=s
Find Read Only files.
$ find / -perm /u=r
Find Executable files.
$ find / -perm /a=x
Find files using name in current directory
$ find . -name tecmint.txt
Find files under home directory
$ find /home -name tecmint.txt
Find files using name and ignoring case
$ find /home -iname tecmint.txt
Find directories using name
$ find / -type d -name tecmint
Find php files using name
$ find . -type f -name tecmint.php
Find all php files in directory
$ find . -type f -name "\*.php"
-size b |
512-byte blocks (default) |
-size c |
Bytes |
-size k |
Kilobytes |
-size M |
Megabytes |
-size G |
Gigabytes |
-size T |
Terabytes (only BSD) |
-size P |
Petabytes (only BSD) |
-type d |
Directory |
-type f |
File |
-type l |
Symbolic link |
-type b |
Buffered block |
-type c |
Unbuffered character |
-type p |
Named pipe |
-type s |
Socket |
Option | Example | Description |
---|---|---|
-type |
find . -type d | Find only directories |
-name |
find . -type f -name "*.txt" | Find file by name |
-iname |
find . -type f -iname "hello" | Find file by name (case-insensitive) |
-size |
find . -size +1G | Find files larger than 1G |
-user |
find . -type d -user jack | Find jack's file |
-regex |
find /var -regex '.*/tmp/.*[0-9]*.file' | Using Regex with find. See regex |
-maxdepth |
find . -maxdepth 1 -name "a.txt" | In the current directory and subdirectories |
-mindepth |
find / -mindepth 3 -maxdepth 5 -name pass | Between sub-directory level 2 and 4 |
$ find [path...] [options] [expression]
Wildcard
$ find . -name "\*.txt"
$ find . -name "2020\*.csv"
$ find . -name "json\_\*"