Top 10 examples of find command in unix and linux


Best Find command examples in linux and unix:-

find command is one of frequent command used in linux and unix operating systems. find command is used by unix/linux users to search the specific files in directory as well as sub directories.

 find command examples in unix and linux

I use this command as part of my programming development with java for searching logs as well as java files in linux operating system.

In windows enviornment, users have the ability to search the any files directly using windows explore. But in Linux/Unix, we have to use command based options to search files.

Most of the people working on development projects, need to know the basics of find command, because they need to search source code files as well as applicaiton logs where the errors occured.

Find command can be combined with grep and other file related commans to make the powerful search in linux/unix.

So i am listing down the some of the find commands that i use daily as part of my software project development.

Find command options in unix and linux:- usuall find command syntax is as follows.

find {directorytosearch} {options}

The following are the options to be given to find command. 1.File name to be search in the list of files. 2. directory or list of files to be specified where search for file name is to find. 3. type of files or directories

1.how to list all the files in the directory and subdirectories?:-

find . or find . -print
./directory2
./directory2/HelloWorld.java
./dir
./dir/file.txt
./kiran
./kiran/HelloWorld.java

```. represents the all the files in the current directory as well as sub directory.
this command shows all the files in the directory and sub directories to the console.

2\. how to find files using name in the current directory:-

find . -name “HelloWorld.java” ./directory2/HelloWorld.java ./kiran/HelloWorld.java

and print the file name to console.

#### 3.How to execute last executed find command

!find find . -name HelloWorld.java ./directory2/HelloWorld.java ./kiran/HelloWorld.java

This ! can be used with any linux command to executed the last specified command.

#### 4\. Find all files that are owned by specific user?

$find /directory -user kiran ./directory2 ./directory2/HelloWorld.java ./dir ./dir/file.txt ./kiran ./kiran/HelloWorld.java



#### 5 how to find file search using name ignoring case sensitive :-

$ find . -iname helloworld.java ./directory2/HelloWorld.java ./kiran/HelloWorld.java


6\. Find the files which are modified in the last one day:-

$ find . -mtime 0 ./directory2 ./directory2/HelloWorld.java ./kiran ./kiran/HelloWorld.java




#### 7\. How to find the files which are modified in the last 10 mins in unix.

find . -mmin 10

and few more examples for finding the modified files between 10 and 20 minutes in the linux

find . -mmin +9 -mmin -21


#### 8.How to list only the subdirectories and directories in file system.

find . -type d ./directory2 ./kiran ./kiran/subdir


#### 9.How to find file names in subdirectory that is one level down current directory?

find -maxdepth 2 -name “HelloWorld.java” ./directory2/HelloWorld.java ./kiran/HelloWorld.java

if we want to find the files in the current directory , we have to use -maxdepth 1 with find command.


#### 10.find all files based on file types?

normally, with find command, we search files only. with find command by providing -type option, we can search directories and symlinks in linux
1.Find regular files in linux

find . -type f ./directory2/HelloWorld.java ./kiran/HelloWorld.java

find . -type d ./directory2 ./dir ./kiran ./kiran/subdir


find . -type s

I hope you understand the basics of find command with examples.
I will write one article about advanced usage of find command in linux and unix.

Please share your comments .
---
### Comments:
#### Thanks for the post. It is really helpful. I'm...
[Computer Repair In Leicester](http://maps.google.co.uk/maps/place?cid=833098980241595943 "noreply@blogger.com") - <time datetime="2012-03-02T11:35:55.206-08:00">Mar 6, 2012</time>

Thanks for the post. It is really helpful. I'm customising my linux and as a newbie it is a stepping stone for me. Many Thanks.
<hr />
Similar Posts