The Linux find command is one of the most important and frequently used command-line utilities in Unix-like operating systems. The find command is used to search for and locate a list of files and directories based on the conditions you specify, matching the arguments.
The find command provides a wide array of options, allowing users to leverage it in diverse conditions. It empowers individuals to search for files based on a multitude of criteria, including permissions, users, groups, file types, dates, sizes, and various other parameters.
In this article, we will present you with 35 of the most commonly used examples of Find Commands in Linux. We have divided this section into five parts, covering the usage of the find command from basic to advanced levels.
Part I – Basic Find Commands for Finding Files with Names
When it comes to finding files with specific names, the find command offers a range of options to streamline the process. Here are some basic find commands for locating files based on their names.
1. Find Files Using Name in Current Directory
Find all the files whose name is tecmint.txt in a current working directory.
# find . -name tecmint.txt ./tecmint.txt
2. Find Files Under Home Directory
Find all the files under /home directory with the name tecmint.txt.
# find /home -name tecmint.txt /home/tecmint.txt
3. Find Files Using Name and Ignoring Case
Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory.
# find /home -iname tecmint.txt ./tecmint.txt ./Tecmint.txt
4. Find Directories Using Name
Find all directories whose name is Tecmint in / directory.
# find / -type d -name Tecmint /Tecmint
5. Find PHP Files Using Name
Find all php files whose name is tecmint.php in a current working directory.
# find . -type f -name tecmint.php ./tecmint.php
6. Find all PHP Files in the Directory
Find all php files in a directory.
# find . -type f -name "*.php" ./tecmint.php ./login.php ./index.php
Part II – Find Files Based on their Permissions
Here are some examples of find commands for finding files based on their permissions.
7. Find Files With 777 Permissions
Find all the files whose permissions are 777.
# find . -type f -perm 0777 -print
8. Find Files Without 777 Permissions
Find all the files without permission 777.
# find / -type f ! -perm 777
9. Find SGID Files with 644 Permissions
Find all the SGID bit files whose permissions are set to 644.
# find / -perm 2644
10. Find Sticky Bit Files with 551 Permissions
Find all the Sticky Bit set files whose permission is 551.
# find / -perm 1551
11. Find SUID Files
Find all SUID set files.
# find / -perm /u=s
12. Find SGID Files
Find all SGID set files.
# find / -perm /g=s
13. Find Read-Only Files
Find all Read-Only files.
# find / -perm /u=r
14. Find Executable Files
Find all Executable files.
# find / -perm /a=x
15. Find Files with 777 Permissions and Chmod to 644
Find all 777 permission files and use the chmod command to set permissions to 644.
# find / -type f -perm 0777 -print -exec chmod 644 {} \;
16. Find Directories with 777 Permissions and Chmod to 755
Find all 777 permission directories and use the chmod command to set permissions to 755.
# find / -type d -perm 777 -print -exec chmod 755 {} \;
17. Find and Remove Single File
To find a single file called tecmint.txt and remove it.
# find . -type f -name "tecmint.txt" -exec rm -f {} \;
18. Find and remove Multiple File
To find and remove multiple files such as .mp3 or .txt, then use.
# find . -type f -name "*.txt" -exec rm -f {} \; OR # find . -type f -name "*.mp3" -exec rm -f {} \;
[ You might also like: 4 Useful Tools to Find and Delete Duplicate Files in Linux ]
19. Find all Empty Files
To find all empty files under a certain path.
# find /tmp -type f -empty
20. Find all Empty Directories
To file all empty directories under a certain path.
# find /tmp -type d -empty
21. File all Hidden Files
To find all hidden files, use the below command.
# find /tmp -type f -name ".*"
Part III – Search Files Based On Owners and Groups
Here are some examples of find commands for finding files based on owners and groups:
22. Find Single File Based on User
To find all or single files called tecmint.txt under / root directory of owner root.
# find / -user root -name tecmint.txt
23. Find all Files Based on User
To find all files that belong to user Tecmint under /home directory.
# find /home -user tecmint
24. Find all Files Based on Group
To find all files that belong to the group Developer under /home directory.
# find /home -group developer
25. Find Particular Files of User
To find all .txt files of user Tecmint under /home directory.
# find /home -user tecmint -iname "*.txt"
Part IV – Find Files and Directories Based on Date and Time
Here are some examples of find commands for locating files and directories based on date and time.
26. Find Last 50 Days Modified Files
To find all the files which are modified 50 days back.
# find / -mtime 50
27. Find Last 50 Days Accessed Files
To find all the files which are accessed 50 days back.
# find / -atime 50
28. Find Last 50-100 Days Modified Files
To find all the files which are modified more than 50 days back and less than 100 days.
# find / -mtime +50 –mtime -100
29. Find Changed Files in Last 1 Hour
To find all the files which are changed in the last 1 hour.
# find / -cmin -60
30. Find Modified Files in Last 1 Hour
To find all the files which are modified in the last 1 hour.
# find / -mmin -60
31. Find Accessed Files in Last 1 Hour
To find all the files which are accessed in the last 1 hour.
# find / -amin -60
Part V – Find Files and Directories Based on Size
Here are some examples of find commands for locating files and directories based on size.
32. Find 50MB Files
To find all 50MB files, use.
# find / -size 50M
33. Find Size between 50MB – 100MB
To find all the files which are greater than 50MB and less than 100MB.
# find / -size +50M -size -100M
34. Find and Delete 100MB Files
To find all 100MB files and delete them using one single command.
# find / -type f -size +100M -exec rm -f {} \;
35. Find Specific Files and Delete
Find all .mp3 files with more than 10MB and delete them using one single command.
# find / -type f -name *.mp3 -size +10M -exec rm {} \;
That’s it, We are ending this post here, In our next article, we will discuss other Linux commands in-depth with practical examples. Let us know your opinions on this article using our comment section.
Countless examples that are EXACTLY THE SAME so this list of 35 could be condensed to a few examples. Then it’s missing in my opinion crucial searching based on patterns.
Most of the examples show super arbitrary parameters on which to search files and each command is repeated a few times with minor differences like
-perm 1664
,-perm 7777
– I GET IT that.I can search on different permissions. Very little general knowledge can be inferred from these examples.
Please stop confusing people find is not a Linux command else a GNU command, Linux is a Kernel, not the project that embraces find.
I want to find the default notification email address for my centreon NMS. I don’t know in which file it was configured.
How can I find
[email protected]
to change the email id, because my email server blocks it?Very useful page – find otherwise is a huge topic in itself: this page helps you to get on with find quickly. Just one request. Kindly also add examples illustrating the use of
"-maxdepth"
option to limit find to the desired number of directories.Thank you for giving very good and understandable examples. This made me be clear with the find command. thank you
Hello all,
Thanks in advance.
I’m trying to find all the files with specific text in the file and have a timestamp next to the file.
Below doesn’t work, I can use the find command but it doesn’t give me the timestamp
Thanks
Dave
34. Find and Delete 100MB Files
To find all 100MB files and delete them using one single command.
Does this command find files that are greater than 100 MB?
Yes, it finds all the files which are more than 100MB under the root, and it will delete that files.
+100M — > Means More than 100M files
-100M —-> Means Less than 100M files
100M —> Exact 100M files
Find files older than a prescribed number (e.g. 8) of newest files:
A little comment: Before you do something very worse with the find command, execute find without
-exec
, you see, if you do the find at the right directory or you check if find does the things expected.In this example with find / -type f -size +100M you first check, are these the files I want to delete?
Then you can add the -exec rm and so on
Excellent comment, thanks!
Thanks for these helpful examples of find command in Linux.
You should really remove this command from your example, or at least place a warning:
for sure someone unwarned might execute this and remove the directories on the root, since
rm -rf
don’t make distinction between files and directories.The correct usage would be:
since type
-f
select only the files, and removing the-r
(recursive) from rm.Still would warn about using this command, you have to be sure about running unspecific rm, even more on your root directory.
Even tho, makes no sense using rm, find already has
-delete
a tag.@Francisco,
I totally agree with you and updated as per your suggestions.
Thank you for this article it is so helpful for me
Thanks a lot please prove more article like this.
How to insert text into a already existing empty file?
You can do add content in the empty file as below
You can write anything you want.
All files have default 644 permission maximum 666 and for directory 777.
Please correct and don’t misguide people.
I’m not sure I follow. When you say default what context do you mean? The current environment umask setting affects what the ‘default‘ permissions are. Files certainly don’t have a maximum of 0666 since files can have 0777 permissions as well.
In the 13th command, the right command is
find / -perm u=r
.Thanks tecmint for exploring find command with attractive example
@Nitin,
Thanks for finding it useful, do share with your friends..
excellent info
Hello,
How to find the files that are created in particular year??
extraordinary site for learning Linux….:)
Sir,
Very much thankful for giving examples to find command, but how to find particuler date files give me examples.
Govardhan Raju
@Govardhan,
You mean find modified files by date? if yes, here is the article, take a quick look.
Find Recent or Today’s Modified Files in Linux
Nice bro, your articles are awesome for Linux users.
Best site I ever have seen for the commands. A great work by you sir. Thanks a lot for making Linux commands so easier.
Good extensive write up on Find Commands Ravi, keep up the good work !!!
@Razeen,
Thanks for finding it useful and thanks for appreciating my work..
Tecmint is life for linux people.
@Luvpreet,
Thanks for such kind words…:)
Hi all, i want to find particular word in all in my Unix box.
Please send me command…
@Raju,
You can use egrep with options to find the particular string in all files as shown:
Thanks tecmint for such a wonderful series of tutorial on Linux. it helps a lot to me as I am new to Linux.
@Bhavik,
Thanks a lot for finding our articles useful, and also good to hear that our articles helping you to learn Linux in an easy way..
Wonderful part of your blog is the way you chose to explain each part that impresses me. Thank you for this blog. :-)
Dear Ravi, I appreciate your work. This blog is very easy to read and understand. Please keep it up. All the best.
@Prabhakar,
Thanks for finding all our artifices very useful and easy in learning..
guys,
I m not able to login in to any of the user and getting the authentication failure, please help me on this
Error in the logs
Thanks, Ramachandra
Dear Ravi
Could you advise what does this {} \; parameter do in the command find / -size +100M -exec rm -rf {} \;
26.Find Last 50 Days Modified Files
To find all the files which are modified 50 days back.
# find / -mtime 50
i think it should be -50 for last 50 days
exact 50 days it should be 50
@Ravi Saive sir i am waiting for your answer…
@Srujan,
Yes, you almost right, I just tried it on My Ubuntu box, it should -50 for modified files..
What is the difference between “Changed” (29) and “Modified” (30)?
@Axel,
29. The command find / -cmin -60 will list the files status was last changed x minutes ago and,
30. The command find / -mmin -60 will list files data or content was last modified x minutes ago.
There’s a typo in:
“19. Find all Empty Files
To file all empty files under certain path.”
“To file” -> “To find”
@Axel,
Thanks for notifying us about that typo, yes, it should be ‘find’ not file, corrected in the writeup..
Dear Sir,
I want to search the hidden files for a particular duration of time.
Ex..I need to search and list all the hidden files for the period Jan-10-2016 to Oct-10-2016.
Please advise how to use the find command to search the above request.
@Ramachandra,
I think such requirement could be achieved via a shell script..
Can any one help me for using find command I want remove
.xml
or.jasons
all files but I can’t find any command. For example, I have directory /dev and with in sub directory’s and in sub directories I have may files but I want delete only.xml
or.jasons
files only.If any command to use one time delete files Recursively
@Khushal,
What an co-incident, just now we’ve published a article on the same, that says how to delete all files in a particular directory except few files or with file extensions using rm command, find command and using gloignore variable, go through it here: https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/
its really very useful.
perfect examples for find
thanks for the article, but there are a lot of other options, please explain them too.
one the important is ‘-maxdepth’ and ‘mindepth’
@Behrooz,
Thanks for finding it useful, but trust me its not possible to explain each option in the one single article, to know more about each option just do
man find
to know about it.thanks for good overview :)
how to search a file in the server and grep for a particular entry in that file and print only the output..?
is there any way where we can hide all the search that is happening and display only the required result
@Sindhu,
You can use egrep to achieve the same, the below command will find a entry or string in a given file in Linux.
How do I find file1.txt and somefile.json in single find command
@Datta,
Here is the command to multiple files using find command..
Q no 12 : I think there should be
g=s
instead of g+s
@Suryakant,
Yeah, that’s really good finding, yes that should be g=s, corrected in the writeup..
Very useful and handy little guide. -mtime is really invaluable for so many reasons.
Sir,
We need help for linux (RHEL4) command FIND. How to tar todays ie., only current day (17-04-2016) files . Please give me examples.
Thanking U sir,
S Govardhan Raju
T I R U P A T I
@Govardhan,
What you mean by “only current day” files? the whole system modification files in a particular day or any specific directory files you want to tar? Could you explain me more about your requirements so that I can help you out..
Sir
We are happy to inform you that we are understanding linux commands with your examples easlly.
Thank U very much Sir,
S Govardhna Raju
TIRUPATI
Thank you very much for great information about find command.
Thank you very much for providing valuable information.
I have a query. How to find a file/directory having maximum size in particular path?
@Santosh,
You mean to check out the largest file/directory space size? if yes, you can check out this article here Find Out Top 10 Files and Directories Disk Size in Linux.
How do I EXCLUDE a directory from a FIND search?
@Sean,
To exclude a directory from a find command while searching, use ‘prune’ option and -path switch as shown.
Hello everybody,
Thank’s for all people who make some articles to benifit others.
i have problem with the option prune of the find command, Could Someone explain thie option with some exmaples please ?
best regards
Very good tutorial. How come in some examples you use find . and other examples you use find /
@Debra,
The (
.
) means current working directory and I am using find command to search for files in current working directory, whereas/
means whole filesystem.Is there a way to display multiple results one page at a time? For example, if I execute: find / -name “grub*”, I get too many results and I can’t see the first ones, because they are gone from display
@Nick,
Use head, tail and cat commands to manage the output as explained in this article..
i create a file demo.txt
after that run this command # find / -mmin -60 (Find Modified Files in Last 1 Hour)
showing more file and how to find my file demo.txt
tell me.
@Gulab,
If you know the filename, you can use grep with find command to list the given filename as shown.
if i forgot file name
find / -type f -user gulab -mmin -60
well said manikanth.
I have a question “if I want to find a particular word in whole server and save into in a single path” what is the exactly commant .
@Sangam,
Your question is not clear, but I think you want to find a particular word in all system files and then save that word to a different file? is this right?
Brilliant!
Thanks guys
On the temporal find conditions you can do a creation date comparison with “find ~/ -newer $file_name”
Thanks!
Its really helpful
Hi ravi,
I am unable to integrate the Ldap with owncloud.Have you any document for that or blog ?
Thanks
Anil
@Anil,
Sorry no idea about LDAP and owncloud integration and never tried so far..and there isn’t any howto on this topic here.
Hi Ravi,
I got result in SSH with one of find syntax.
But I got too many results which I can not see all in SSH window.
Can you suggest any syntax using which I can store all search result in any text file or something and I can have look at that file later on when needed?
@Bharat,
Use following example command to store all data about find command on a file.
Hello sir,
Superb explantion. Very helpful. Many thanks
You can also use this
find . -type f -name “tecmint.txt” -delete
instead of this
find . -type f -name “tecmint.txt” -exec rm -f {} \;
The content is excellent at TecMint, but the pages cannot be saved/printed usefully. I save all web-urls in .pdf. Tecmint pages are useless to print.
@Neil,
Sorry for that, but we’re in process to add print option soon to the pages of all articles..
I think you can improve your Part IV with this: http://serverfault.com/a/122831
Another solution is :
find . -name -exec mv {} \;
quick question :-
How do we find a file and then we rename (mv) the same file with one command
Does -exec option work with it ?
Any Examples ?
@Sunny,
Yes, you can use both commands in one go…
Another solution could be :
find . -name oldFileName -exec mv {} newFileName \;
Dear Tecmints ,
i understand that this works for one of the files to find apply the execute the action on those files
$ find / -name “error_*.txt” -exec ls -lrathi ‘{}’ “;”
but can you please provide examples on multiple files how do we do it ?
Examples : – if there are “find_*.txt” “list_*.csv” and more
Dear techmint ,
I want to find and remove multiple files such as .mp3 or .txt, then use.
But first i want to list it first , so i fire the below command.
And i notice that when you try to find a pattern of files
Example : “*.txt” , “*.tar” , “*.csv”
as per the command All of them do not give me the out put
Where as only the last pattern “*.csv” , gives me the output .
Please advise , how i can get out put of : -“*.txt” , “*.tar” also in my find result
find / -type f -name “*.txt” -o -name “*.tar” -o -name “*.csv” -exec ls -larthi ‘{}’ “;”
1376260 -rw-r–r– 1 root root 118 Aug 17 2007 /usr/share/alsa/speaker-test/sample_map.csv
[root@localhost ~]#
Regards,
Sunny
find . -type f \( -name “*.txt” -o -name “*.tar” -o -name “*.csv” \) -print
./1.tar
./3.txt
./2.csv
./2.txt
./3.tar
./1.txt
./3.csv
./2.tar
./1.csv
Very Very Good information Find Commands.
I am very glad that you have describe the find command with examples. Thanks once again and Keep posted the linux related stuffs.
I have to move directory from which contain logs. Each dir created like 26022015 and i want to move dir except 3 days recent one.
Hi.
Great article.
How to find executables files on RHEL4 and Solaris 9 and 10?
I tried with
find / -executable -type f and
find / -perm /u=x,g=x,o=x -type f
but it worked only on RHEL6.
Thanks!
Good information
All at one place
thanks
HI , How to see the files in particular date, Suppose I want to see Jan 18 2015 files among all the files. I tried +mtime not working
find . -newermt 2015-01-18 -ls lrt
above one is not working for me, Please suggest something
@Sunny,
Try this.
Dera tecmint ,
I have tried the above solution to find the files based on date , it does not seems to work, please assist
find / -type f -newerat 2007-08-17 ! -newerat 2015-08-17
find: invalid predicate `-newerat’
[root@localhost ~]# date
Fri Aug 7 11:25:10 IST 2015
Dear techmint,
I have tried the below as well does not seem to be working
find -newerat “Mar 01 2008” ! -newerat “Mar 01 2014”
find: invalid predicate `-newerat’
[root@localhost ~]# find -newermt “Mar 01 2008” ! -newermt “Mar 01 2014”
find: invalid predicate `-newermt’
i am Unix Linux system .
uname -a
Linux localhost.localdomain 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:02 EDT 2007 i686 i686 i386 GNU/Linux
Regards,
Sunny
Great articles
Thanks !
Hello sir,
I am trying to find files in Linux using the find command. I need to search in an nfs mounted filesystem to list all the files owned by a certain user. Example:
drwxrwxr-x 2 afsharf staff 126976 Oct 9 14:20 trevor/
-rw-rw-r– 1 afsharf staff 22947599 Oct 9 08:52 troj.out
-rwxr-xr-x 1 camachoe staff 11752 Jun 25 2013 runtnav_beta_h*
-rwxr-xr-x 1 camachoe staff 11648 Jun 25 2013 runtnav_h*
I would like to find files owned by “camachoe” in the current and sub- directories . Any idea how to do that using find command? this is an nfs mounted filesystem.
Thank you in advance.
@Farid,
find . -user camachoe -ls
Hi Sir,
Is there a way to use find/locate on a list? example:
while read line
do
if locate “$line”
then
echo “Y: $line”
else
echo “N: $line”
fi
done < $1
on my case, this always returns N: (line), I think the locate command reads my variable as $line literally, also tried to use find command here, same result. any thoughts?? thank you in advance :)
How to find out the size of a any file using find command
I want to delete the files and print to output file with date,Time and Size.
Bharath, I think you should try this command.
Find all Files larger than 20M in Home Dir and show it sorted
find /home -type f -size +20M -exec du -h {} \; | sort -h
Hello sir,i am working on migration project,i have a few question sir how to migrate all users home directory data to new linux system using bash shell script.will u please provide me any script or idea for that.thanx in advance.
Dear Pravin,
We surely provide you a step-by-step instructions on how to migrate all Linux users from one server to another server using some command line tricks. Till then stay tuned for the updates.
it is very useful for me as i m new to shell commands.
thanks for posting articles…..
You know, with HTML you can turn a table of contents into links that take a reader straight to each section … just sayin’.
This is an incredibly useful building block, thanks!!
this is quite useful page and I used many of these commands after seeing your page .
thank you so much for such a wonderful collection of the commands with example.
All the best to you
How to delete a file in a directory which was created 13months back?
Amazing! very helpful!
how can i use this two as single command?
find -name ‘*.jpg’ -mtime +7 -exec jpegoptim {} \;
find -name ‘*.jpg’ -mtime +7 -exec chown www-data:www-data {} \;
thanks :)
How can we find the files inside a directory concerning date range and remove them.?
Example: I want to remove the files created between “1st Jan 2012 8 AM” and “5th Jan 2014 10 PM”
To find and remove files within a specific date range in a directory, you can use the find command in combination with the rm command as shown:
Locate User “username” regular files and save as /tmp/backup
find / -user username -type f -exec cp -a ………………. please complete this … needed earlier
In example 35 i think it should be rm instead of ls -l
Yes! it should be rm command. Thanks corrected now..
35. Find all .mp3 files with more than 10MB and delete them using one single command.
# find / -type f -name *.mp3 -size +10M -exec ls -l {} \; — but there is not command to delete the files.
1) how to list files in range (A001 to A090)suppose if there are log file which names are
starting with log.A001 to log.A00nth or may be more .
2)list out the files created in a certain date.
3)search the string pattern “xyz” in all files and count how many times the string is present in all the locations.
please help
Can you please publish the posts in PDF format ?
Thanks for the post :)
In example 22, the description should be ‘under the / root directory’ instead of ‘under /root directory’.
Thanks, corrected up in the article.
como recuperar los archivos eliminados con el comando # find / -type f -name *.mp3 -size +10M -exec ls -l {} \;
It is really helpful for beginners
thanks…
Can you explain this option to me, I am new to the command line – still learning.
#15 # find / -type f -perm 0777 -print -exec chmod 644 {} \;
the symbols {} and the \
I am a bit confused, any help/advice would be great.
@Mac, Please join us on Facebook at Linux Inside, you will get the answer for this.
The brackets are placeholders for the file that find, finds and the \ is so that the shell does not interpret the semicolon (;), which would normally end the command.
hi! glad i found your site and the informative articles. question re: “35 Practical Examples of Linux Find Command”:
in # 3. ‘ find /home -iname tecmint.txt’, what is proper way to filter results of this command such that the Uppercase results are sorted from the lowercase results?
ex.:
…….
Techmint.com
Techmint.com1
Techmint.com2 …….
techmint.com
techmint.com1
techmint.com2, etc., etc., etc.
Thanks again for all the good info. Have A Healthy, Prosperous Day!
—rob
Number 34 needs to have another 0 in the command. Its currently set to find files larger than 10MB not 100 as the description states.
@Ernesto,
Thanks, corrected now..
While this post is quite old. May I make two suggestions. 34) instead of running -exec rm -rf, the less cpu taxing option would be to add -delete to find. Would be good to note and using -print first to confirm what is being deleted or just the find command piped to head to confirm some of the files is a good step before using any additional command/options that would delete.
35) Pretty much the same as 34 as it is missing the deletion option.