EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Software Development Software Development Tutorials Unix Tutorial Find Command in Unix

Find Command in Unix

Updated May 30, 2023

Find Command in Unix

Introduction to Find Command in Unix

The Find Command in Unix Shell Scripting is a command-line utility for maintaining a file hierarchy system. The find command is used to find out the files and directories in the system and execute the following operations on the files. This command helps to support to search a file, name, folder, modification date, permissions of a file, and owner of a file.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The Find Command is the most frequent and useful command for searching and locating the file list and directories based on the requirement for a file matching the argument passed as the input. It is also used in many conditions to help find files by their user names, permissions, groups, date, file type, and many available possibilities.

What can we do from Find Command?

Below are the options that are used in Unix with Find Command:

The tabular structure shows the option and its function:

-inum N Used to search the files with an inode number.
-links N Used to search files with links.
-name demo Searches the files with the name ‘demo’.
-newer file Checks for the files based on creation or modification date.
-perm octal Checks the permission of the file to see if it is octal or not.
-print Used to print the filenames that are given in the input criteria.
-empty Searches for empty files or directories.
-user name It is used to search the files owned by a user’s ID.
! expr It returns false if ‘expr’is true.
\(expr \) This option is used for grouping criteria along with OR or AND. It returns true if the ‘expr’value is true.

Syntax:

Find Command Syntax in Unix Shell Scripting is given below:

find [from where to start the search] [what to find] [options] [what to find]

Examples of Find Command in Unix

Let us consider there are a few files under the test directory.

Below is the file name list that is listed under the current directory.

Code:

ll

Output:

Find Command in Unix 1

Example #1 – Finding files using the name option in the current directory.

We can search for files in the current directory using the option ‘name’ as shown below.

Syntax:

find . -name filename.txt

Code:

ll
-name namelist.txt

Output:

Find Command in Unix 2

Example #2 – Finding files using the name option in the home directory.

We can search for files in the home directory using the option ‘name’ as shown below.

Syntax:

find /home -name filename.txt

Code:

find /home -name namelist.txt

Output:

Find Command in Unix 3

Example #3 – Finding files ignoring case.

We can search for the files in the system by ignoring the case using -iname.

Syntax:

find . -iname filename.txt

Code:

find . -iname Namelist.txt

Output:

Find Command in Unix 4

Example #4 – Finding directories using the name option.

We can find the directories using the option ‘name’ in the / directory.

Syntax:

find / -type d -name directory_name

Code:

find / -type d -name dir_name

Output:

Find Command in Unix 5

Example #5 – Option -perm.

We can find the files with permissions as 777 and print them.

Syntax:

find . -type d -perm 0777 -print

Code:

find .  -type d -prem 0777 -print

Output:

Find Command in Unix 7

Example #6 – Option! Perm.

We can find the files with no permissions as 777 and print them as well.

Syntax:

find . -type f ! -perm 0777 -print

Code:

find .  -type f ! -prem 0777 -print

Output:

Find Command in Unix 8

Example #7 – Finding read-only files.

We can find the files with read-only options in current directories, as shown below.

Syntax:

find . -perm /u=r -print

Code:

find .  -prem /u=r -print

Output:

read only files.

Example #8 – Option -empty.

We can also find all empty files in the system and whichever folder you want.

Syntax:

find . -type f -empty -print

Code:

find .  -type f -empty -print

Output:

Option -empty

Example #9 – Option -empty.

We can also find all empty directories in the system and whichever folder you want.

Syntax:

find . -type d -empty -print

Code:

find .  -type d -empty -print

Output:

Find Command in Unix 11

Example #10 – Finding hidden files.

We can also find hidden files or directories using Unix’s find command by the syntax below.

Syntax:

find . -type f -name “.*”

Code:

find .  -type f -name ".*"

Output:

Find Command in Unix 12

Example #11 – Finding files based on user.

We can find the users based on the user it belongs to, either under the current directory or home directory, as shown below.

Syntax:

find . -user user_name

Code:

find . -user user

Output:

Find Command in Unix 13

Example #12 – Finding files modified in the last 50 days.

Finding files modified in the last 50 days can be shown below.

Syntax:

find / -mtime 50

Code:

find / -mtime 50

Output:

files that has been modified in last 50 days

Example #13 – Finding files accessed in the last 50 days.

Finding files accessed in the last 50 days can be shown below.

Syntax:

find / -atime 50

Code:

find / -atime 50

Output:

files that has been accessed in last 50 days

Example #14 – Finding changed files in the last 15 mins.

We can find files that have been changed in the last 15 minutes, as shown in the syntax below.

Syntax:

find . /cmin 15

Code:

find . -cmin -15

Output:

Finding changed files in last 15 mins

Example #15 – Finding modified files in the last 1 hour.

We can find files modified in the last 15 min as shown in the syntax below.

Syntax:

find / -mmin -60

Code:

find . -mmin -60

Output:

Find Command in Unix 17

Example #16 – Option -size.

We can use option -size for various criteria like less than size or more than size by the given syntax below. In this case, we check for files with sizes less than 10MB.

Syntax:

find . -size -size

Code:

find . -size -10M

Output:

Option -size

Example #17 – Find and delete a file.

We can find and delete a file using the find command in Unix. When we enter the below syntax, it will ask you for confirmation if we want to delete the file or not; type ‘Y or y’ to confirm.

Syntax:

find . -name filename -exec rm -i {} \;

Code:

find . -name namelist.txt -exec rm -i {} \;

Output:

Find Command in Unix 19

Recommended Articles

We hope that this EDUCBA information on “Find Command in Unix” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. For Loop in Unix
  2. Array in Unix
  3. Unix Architecture
  4. Uses of Unix
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
All in One Software Development Bundle5000+ Hours of HD Videos | 149 Learning Paths | 1050+ Courses | Verifiable Certificate of Completion | Lifetime Access
Financial Analyst Masters Training Program2000+ Hours of HD Videos | 43 Learning Paths | 550+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more