- How To Find a File in Linux using Find?
- How To Find a File in Linux using Locate?
- How To Find a File in Linux using Grep?
Using Linux on PC isn’t a complicated thing as it offers tons of features. The only thing anyone must understand while dealing with Linux PC is to have a clear knowledge of using the command lines. Once if you master its commands, then you will able to control everything including finding files. No matter which distro you have on Linux, they have lots of GUI tools and thus helps in searching for files. A terminal is a must with this you can find the files effortlessly and control your files. By getting in this article, you will be dealing with the commands with which you can find a file on Linux.
How To Find a File in Linux using Find?
We have covered almost all the working command lines to find a file on Linux PC here using Find here. Make use of it for an instant search result.
Using certain symbols on Linux terminal will have their own effect.
- Period (.) means the current and nested folders
- Tilde (~) implies the home directory of the active user
- Forward Slash (/) represents the entire filesystem.
Almost all of the modern Linux distributions supports find command from the terminal window. Open it clicking on the icon or press Ctrl+Alt+T together to open it directly.
The command to search for a file on Linux is “find”
1. Search for a file on Linux by File Name
The general syntax to use the find command is
- For example, find text.html
To search for the file on the current drive, use the syntax
find / filename
For example, find /home text.html or find /home/pat text.html
The below syntax will help you find the file in the current folder.
find . filename
For instance, find text.html
To search for a file on the whole drive, use the find command as
find / -name filename
For example, find /home -name text.odt
Note: Linux is case sensitive and you can prefer the following command to ignore case sensitivity while finding a file.
find / -iname filename
name implies case sensitive whereas iname implies case insensitive.
To find a file that matches your part of the search, use wildcard character (*) along with the find command. This is useful if you don’t know the full title of your filename.
find /home/pat -iname "*.conf"
2. Search for a file on Linux by File Type
You can look for files of certain types instead of the file name. Here is are the possibilities.
Using certain letters has their own effects while the search for a file on Linux. So of the letters that you can use with find command and its meaning as follows.
- b represents block devices
- c implies character devices
- d means a directory
- f implies regular file type
- l means a symbolic link
The general syntax to find a file by type is
find / -type filetype
For example, find /home -type d
This will find all the files in the home directory.
3. Search for a file on Linux by File Size
It is possible to find a file on Linux distro with its size if you know. Find our how from below.
The size description letters you should know before searching for a file by its size are
- c means bytes
- k implies Kilobytes
- M represents Megabytes
- G means Gigabytes
- b implies 512-byte blocks
The general syntax to find a file by size is
find / -size +file size
For example, find /home -size +50M
If you want to filter files with similar names but with your preferred size, use the command
find / -size +20G -iname text.html
4. Search for a file on Linux by Modification Time
Based on the last modification time, you can easily find the file on Linux PC.
You can use the command line as
find / -name "*conf" -mtime -modification time
find /home/user/ -name “*conf” -mtime -6
Where 6 implies the files modified in the last 6 days.
5. Search for a file on Linux using Expressions
Linux users can look for files with the help of expressions. We have covered the most used expressions and how to use it with find command here.
find / -expression
For example, find /home/user/ -name and this will search for the name of the file on the specified directory.
- -amin n – file last accessed in n minuted ago. For example: find ~ -amin 60
- -atime n – file last accessed more n days ago
- -cmin n – file last chaned in n minutes ago
- -empty – file that is empty
- -executable – file that is executable
- -ilname pattern – search for symbolic line ignoring case
- -iname pattern – search for file ignoring case
How To Find a File in Linux using Locate?
If you want to find a file on Linux at a faster rate than Find, then use Locate command. Currently, locate command isn’t installed on all the Linux distros.
To install it,
- On Ubuntu and Debian,
- Enter the command on the terminal as sudo apt-get update
- Type sudo apt-get install mlocate
- Use the emerge as emerge mlocate
On Arch Linus,
- Use the Pacman package manager pacman -S mlocate
To use Locate to find a file on Linux, the general syntax is
locate file name
How To Find a File in Linux using Grep?
Using grep command, you can possibly find a file by searching for the text.
The general syntax is
grep "search query"
For example, grep -r -i “techowns /home/
These are different possibilities in which you can find a file in Linux PC. Hope this section is useful to you.