3 Commands to Search for a File on Raspberry Pi (And Find It!)
On Raspberry Pi OS (especially the Lite edition), there’s no fancy tool to find a file on your SD card. And yet, it would be quite useful! No worries, you can do everything with a few commands that I will introduce in this tutorial.
Find, locate, and grep are three useful commands to search for a file on Raspberry Pi.
They have interesting options to quickly locate any file on the Raspberry Pi file system.
In this post, I’ll explain the command syntax for each one, and give you a few examples, so you can use them correctly. I will also give you a bonus tip at the end 🙂
If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!
Find
‘Find’ is the command that most people will suggest when you ask them how to find a file on Linux.
It’s powerful and can save you a lot of time because you can add many criteria to filter the results you’re interested in. Unfortunately, it also mean many options to remember when you try to use it.
I will try to keep this simple, and give you the most useful parameters only.
Check this: Need a clear GPIO pinout diagram? Here's mine.
Basic Find Example
The ‘find’ syntax is generally formatted as:find [path] [options]
You can remove the path to search in the current directory (recursively), or the options (to display all files), but most of the time you will use both.
If you are searching for a file in the entire file system, don’t forget to use sudo to get access to everything.
You can get answers from real experts in minutes.
Get help with your setup
Here is a simple example to clarify:sudo find /var -name journal
And the result is:
This is perfect if you know the exact name of a file and want to find it, but it won’t work if you only have part of the name.
If you also want files that contain the word you specify in the parameter, you can use asterisks (*) as a wildcard. For example:sudo find /var -name *journal
sudo find /var -name journal*
sudo find /var -name *journal*
The first command is for files ending with “journal”, the second for the ones starting with “journal” and the last one containing “journal” anywhere in their path.

Quick tip: you can use the “-iname” option rather than “-name”.sudo find /var -iname *journal*It will display the results using case insensitive matching. So if a file is named “JouRnAL” somewhere, using -name won’t find it but using -iname will.
You might also like: Probably one of the best Raspberry Pi workstations (review)
Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.
Date Option
Okay, so the name/iname option is cool, but what if I don’t know the name of the files I’m looking for? Well, find has other options to help you in this case.
The ‘find’ command allows you to search for files based on their creation, last access, or modification date.
Bonus tip: If the terminal still feels confusing, I made a simple cheat sheet with 74 commands explained in plain English. You can grab it here for free..
If you want a clearer path than jumping from tutorial to tutorial, my book gives you a step-by-step roadmap to really understand your Raspberry Pi.
Check the book hereAll these options work the same way, so I’ll give you all the options at once:
- -cmin: Difference in minutes from the creation date.
- -ctime: Difference in days from the creation date.
- -mmin: Same thing for the modification minutes.
- -mtime: And modification days.
- -amin: This one is for access time elapsed in minutes.
- -atime: Or days.
For each of these options, you can specify a threshold, and say if it should be above or that threshold. A few examples will be clearer 🙂
- Find files in your home directory created less than 60 minutes ago:
find /home/pat -cmin -60
- Look for files in /var/log that have not been modified in the last 3 days:
sudo find /var/log -mtime +3
This is very useful when you want to clean up your system or find a file you recently created or modified but can’t remember where you put it.
Size Option
Another option you can try is to look for specific file sizes. It’s also useful when you want to free disk space on your SD card.
Check this: Need a clear GPIO pinout diagram? Here's mine.
It works almost the same as the previous one, so I’ll directly give you two examples:
- Find files bigger than 100MB on your system:
sudo find / -size +100M
- Or smaller than 100M:
sudo find / -size -100M - Or even empty files:
sudo find / -size 0
Excellent command to find the biggest files on a system or share, and remove them 🙂
Going Further
As I mentioned at the beginning, the idea here is not to master the ‘find’ command, as there are so many possibilities.
But with these main options, you can already find files in most cases.
I will add two tips to these before switching to the next tool.
- You can combine several options in the files command. For example:
sudo find /var/log -size +100M -mtime +30
Will list all log files over 100M and not modified in the last month. - You can look at the manual page if you are interested in other options:
man find
For example, you can execute a command on the results, display files only, disable recursive mode, etc.
Locate
Let’s go over the ‘locate’ command next.
Locate is a command that is easier to use for beginners.
I remember using it all the time in my early days on Linux, as I never remembered the find command options.
The difference with find, is that locate will create a index regularly to find files quickly (instead of having to look all files every time you make a request).
Installation
On recent releases, it’s not longer included in the system by default, so you have to start by installing a package for it.
Here is the command to install it on Raspberry Pi OS:sudo apt install plocate

The first thing to do after the installation is to create the database.
Here is the command:sudo updatedb
I think that this command is automatically done daily on your system, but you can schedule a task if you want to program it as you want.
Simple Search
Once installed, you can now use ‘locate’ directly.
The main goal with locate is to quickly find a file based on its name.
There are a few options, but it’s really simpler than find.
So, the syntax is always something like:locate [OPTION] [SEARCH]
You never need sudo with this command, as the database is already created and updated with it.
Here are three examples of what you can do:
- Find all file name containing your search pattern:
locate syslog.1
There’s no wildcard here, so this command finds any filename containing the word “syslog”:locate syslog
- Ignore case in your search with:
locate -i syslog - Filter the results to only show files that match the string (so excludes path matches):
locate -b syslog
That’s the main options you’ll use (and probably only the first one).
As you can see, ‘locate’ is perfect when you know the file name and want a quick result, but not so useful in other cases.
Filter with grep
‘Locate’ is limited in options, but you can still filter the results with other Linux commands, for example: grep.
I’ll give more details about grep in the next part, but for the moment, just remember that ‘grep’ is a command that you can use to search for an expression. So we can use it after locate to display only the lines we want.
Bonus tip: If the terminal still feels confusing, I made a simple cheat sheet with 74 commands explained in plain English. You can grab it here for free..
The syntax will be:locate [FILE] | grep [EXPRESSION]

For example:locate syslog | grep man
My ‘locate’ command will give me too many results, but if I’m only interested in the files with “man” in their path or names, I can filter the results containing only that.
Still stuck after following this guide? Drop your question in the RaspberryTips Community — real Pi users answer fast. Post your question here.
Grep
The last command you can use to search for files is ‘grep’.
I already give you the general idea, but it can do much more than that.
You already learned many ways to find a file since you’re reading this, but to be absolutely complete, there are a few things that are missing.
Grep is a powerful tool to search for strings in a text or in a file.
I already explained the basics of this command that you can combine with any other one to filter the results but what is fascinating is to look inside files.
Use Grep to Search Inside File Contents
Here is an example of why I use it so often.
Let’s say you have a folder with all your source code, maybe /home/pat/code.
You’re looking for all files using a function you just changed, let’s say “send_email()”.
You can’t do this with ‘find’ or ‘locate’, as they search file names or attributes, not inside the file contents.
But ‘grep’ can do this!
The syntax we’ll use is:(sudo) grep [OPTIONS] [SEARCH] [PATH]
sudo can be added if you are looking in system folders.
Then there are many options you can add (check the man page), and finally the search string and path are similar to what we have seen previously.
Let’s take another example: I want to update my Raspberry Pi OS version, but I don’t know where are the apt files to edit to change the repository name.
I can do a search on the entire system with:sudo grep --color -nHr 'bookworm' *

So the files I’m looking for are in /etc/apt, and I have their names, so I can edit them easily.
Here are the options I used:
You might also like: 25 project ideas you can try at home with Raspberry Pi
- –color: put file name and string matches in colors
- -n: display the line number for each match
- -H: display the file name for each match
- -r: use a recursive search
- ‘bookworm’: the string I’m looking for in any file
- *: I’m searching in any file under my current path (“/etc/apt“)
As always, “man <command>” will give you every option you might need in your case.
I often use -v (list files that doesn’t match the search expression), and -A/-B/-C to display lines around the match.
Want to learn more? Check out our guide below.
That’s all! If you remember these 3 commands, you should be able to find any file on your Raspberry Pi.
In fact, these are common commands on any Linux system, so it may help you a lot in other situations. That’s really commands I’m using almost every day at work.
Also, I promised a bonus at the end, but I actually have three for you 🙂
- Another command that can be useful in some cases is “whereis”.
It will give you the location of a binary file.
For example:whereis syslogWill only display the service location, not all the logs and documentations files. - If you are on desktop, there are also graphical tools that you can use as a search engine.
For example, you can try Tracker or Recoll, both available in the default repository. - And finally, remember that you can mix these 3 commands with most other Raspberry Pi commands. If you are interested in this, read my selection here of the most useful commands on Raspberry Pi (and get a free cheat sheet to remember them ^^)
By the way, if you are on a traditional PC with Ubuntu, there are other great options you can use to find a file quickly. Check this article for more details.
Not getting the same result?
Even when you follow every step, small differences in OS version, hardware or config can change the outcome. Instead of wasting time guessing, get help from people who have already fixed the same kind of issue.
- Get help on your exact issue
- Access step-by-step videos for tricky setups
- Browse the website without ads
