How to find a file in Linux by name?
The most direct way to find files in Linux is to use the find and locate commands. 1. Use find to search by file name, the syntax is find [Search path] -name "file name", which supports wildcards and additional conditions such as -type, -user, -size, etc.; 2. Use locate to quickly search, rely on the database, and need to perform updatedb updates regularly, which is suitable for quickly locate existing files; 3. Use other conditions of find to improve accuracy, such as filtering by modification time, user, size, etc. Mastering these two tools can effectively respond to most file search needs.

One of the most direct ways to find a file in Linux is to search by file name. If you know the general information about file names, use the command line tool to quickly locate the location of the file.

Use the find command to find files by name
find is a very powerful search tool in Linux, especially suitable for searching files by name, type, size and other conditions.
- The basic syntax is:
find [Search path] -name "File name"
For example, if you want to find a file named example.txt in the entire system, you can run:

find / -name "example.txt"
- Notes:
- Searching the root directory
/some permissions may be required. If the permissions are insufficient, many "Permission denied" prompts will be output. You can usesudoto increase permissions or narrow the search scope. - If you are not sure about the full file name, you can use the wildcard
*. For example, find all.logfiles:find /var/log -name "*.log"
- Searching the root directory
Quickly find files with locate
If you want to find files faster, you can use the locate command, which relies on a pre-built database and is therefore very fast.
Basic usage:

locate filename
But it needs to be noted:
- The database is not updated in real time and the latest created file may not be found. You can manually update the database:
sudo updatedb
- If the system does not have
locateinstalled, it can be installed through a package manager in most distributions, such as Ubuntu:sudo apt install mlocate
- The database is not updated in real time and the latest created file may not be found. You can manually update the database:
Use find in combination with other conditions to improve accuracy
Sometimes multiple files with the same name may be distributed in different locations, and the results can be further filtered based on other conditions.
For example, find the file named todo.txt modified in the current user's home directory in the past 7 days:
find ~/ -name "todo.txt" -mtime -7
Common combination options include:
-
-type fmeans only normal files -
-user usernameto find files belonging to a user -
-size 10kfinds files larger than 10KB
These additional criteria can help you lock your target faster from a bunch of search results.
Basically these are the methods. By mastering the two tools of find and locate , you can meet most of the needs of finding files by name.
The above is the detailed content of How to find a file in Linux by name?. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
The Ultimate Guide to High-Performance Gaming on Linux
Aug 03, 2025 am 05:51 AM
ChoosePop!_OS,Ubuntu,NobaraLinux,orArchLinuxforoptimalgamingperformancewithminimaloverhead.2.InstallofficialNVIDIAproprietarydriversforNVIDIAGPUs,ensureup-to-dateMesaandkernelversionsforAMDandIntelGPUs.3.EnabletheperformanceCPUgovernor,usealow-latenc
What are the main pros and cons of Linux vs. Windows?
Aug 03, 2025 am 02:56 AM
Linux is suitable for old hardware, has high security and is customizable, but has weak software compatibility; Windows software is rich and easy to use, but has high resource utilization. 1. In terms of performance, Linux is lightweight and efficient, suitable for old devices; Windows has high hardware requirements. 2. In terms of software, Windows has wider compatibility, especially professional tools and games; Linux needs to use tools to run some software. 3. In terms of security, Linux permission management is stricter and updates are convenient; although Windows is protected, it is still vulnerable to attacks. 4. In terms of difficulty of use, the Linux learning curve is steep; Windows operation is intuitive. Choose according to requirements: choose Linux with performance and security, and choose Windows with compatibility and ease of use.
Understanding RAID Configurations on a Linux Server
Aug 05, 2025 am 11:50 AM
RAIDimprovesstorageperformanceandreliabilityonLinuxserversthroughvariousconfigurations;RAID0offersspeedbutnoredundancy;RAID1providesmirroringforcriticaldatawith50�pacityloss;RAID5supportssingle-drivefailuretoleranceusingparityandrequiresatleastthre
Linux how to enable and disable services at boot
Aug 08, 2025 am 10:23 AM
To manage the startup of Linux services, use the systemctl command. 1. Check the service status: systemctlstatus can check whether the service is running, enabled or disabled. 2. Enable the service startup: sudosystemctlenable, such as sudosystemctlenablenginx. If it is started at the same time, use sudosystemctlenable--nownginx. 3. Disable the service startup: sudosystemctldisable, such as sudosystemctldisablecups. If it is stopped at the same time, use sudosystemctldisabl
Setting up a Development Environment on Linux for Python
Aug 03, 2025 am 12:26 AM
InstallPythonandessentialtoolsusingyourdistribution’spackagemanager,ensuringpython3-venvandpython3-devareincludedforenvironmentisolationandCextensions.2.Alwaysusevirtualenvironmentsbyrunningpython3-mvenvmyproject_envandactivatewithsourcemyproject_env
How to set up a firewall in Linux
Aug 22, 2025 pm 04:41 PM
UsefirewalldoriptablestosecureLinux;firewalldisuser-friendlywithzonesandservices,idealforCentOS/RHEL/Fedora,whileiptablesoffersgranularcontrolforDebian/Ubuntu.Enablefirewalld:sudosystemctlstartfirewalld,allowserviceslikeSSHwith--add-service=ssh,orope
Linux how to list all running processes
Aug 08, 2025 am 06:42 AM
Usepsauxforacompletesnapshotofallrunningprocesses,showingdetailedinformationlikeUSER,PID,CPU,andmemoryusage.2.Usetoporhtopforreal-timemonitoringofprocesseswithdynamicupdates,wherehtopoffersamoreintuitiveinterface.3.UsepgreporpidoftoquicklyfindthePIDs
How to clean up your Linux system
Aug 22, 2025 am 07:42 AM
Removeunusedpackagesanddependencieswithsudoaptautoremove,cleanpackagecacheusingsudoaptcleanorautoclean,andremoveoldkernelsviasudoaptautoremove--purge.2.Clearsystemlogswithsudojournalctl--vacuum-time=7d,deletearchivedlogsin/var/log,andempty/tmpand/var



