The Find command is one of the most used command-line utility in Linux. This command uses for searching files and folders with different parameters like name, permission, extension, etc.

In this article, we will learn different uses of find command in Linux distributions.

Find command execute in the following manner:

$ find [target directory]
[expression determines what to find] [-options] [what to find]

Find command in Linux with examples

1. Find Files in Current Directory by using file name

It will search all files contain namestring in the file name.

# find . -name filename.txt

./filename.txt

2. Find Directories Using Name

It will search all directories with name “netzole”

# find / -type d -name netzole
./netzole 

3. Find all html Files in Directory

It will search all files with .html extention

# . -type f -name "*.html"

./netzole.html
./indext.html
./sample.html

4. Find Files With Permissions

It will search all files with 644 permission

# find . -type f -perm 0644 -print

5. Find Files Without 644 Permissions

It will search all files without 644 permission

# find / -type f ! -perm 644

6. Find empty files and directories

It will find all empty files and directories

$ find ./ -empty 

7.  Find and remove single File

It will find and delete the file with name sample.txt

# find . -type f -name "sample.txt" -exec rm -f {} \;

8. Find and remove Files contain specific extension

This command search all files with .mp3 extension in target directory and delete all of them.

# find . -type f -name "*.mp3" -exec rm -f {} \; 

9. Find all Hidden Files

It will search all hidden files

# find / -type f -name ".*" [php]
<h2>10. Find Last 30 Days Modified Files</h2>
This command find all files modified in last 30 days,

[php] # find / -mtime 30

 

Pin It on Pinterest

Shares
Share This