October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk12 min

How to Use the find and locate Commands in Linux

Use find for live, metadata-aware filesystem searches and locate for fast indexed filename lookups. This guide covers syntax, quoting, grouped expressions, updatedb, safe actions, troubleshooting, and practical workflows.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use find when the answer must reflect the filesystem right now or when you need filters such as type, size, age, or permissions. Use locate when you need a fast filename search from an index; run updatedb when that index is missing recent entries.

What find and locate actually do

find walks one or more directory trees at query time and evaluates an expression for every item it encounters. Its results describe the filesystem as it exists during that traversal. GNU Findutils summarizes the program as searching “a directory tree to find a file or group of files.”

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

locate does not normally walk directories during your query. It searches one or more prebuilt filename databases. That makes a name lookup very quick, but the result can be stale or incomplete. The database is generated or refreshed by updatedb, whose configuration determines which directories are indexed and how often the refresh occurs.

Need Start with Why
A file created moments ago find It examines the current directory tree instead of waiting for an index refresh.
Filter by size, type, age, permissions, or several conditions find Its expression language supports metadata predicates and compound logic.
A quick lead from a known or partial filename locate It scans a filename index rather than traversing every directory.
Search only paths covered by an index and accept possible staleness locate Results depend on the last successful updatedb run and its configured scope.
Confirm a path before changing or deleting anything find A live traversal can verify that the object still exists and meets your predicates.

Using find: start with a path, then add an expression

The general form is:

find [starting-point...] [expression]

The starting point is not optional in the practical sense: find . searches below the current directory, while find /home searches below /home. You can provide several starting points, such as find /etc /var -name 'settings.conf'.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Find an exact name

find . -name 'report.pdf'

This searches the current directory and all of its descendants for a name matching report.pdf. The pattern is quoted so the shell passes it unchanged to find.

Match a pattern, regardless of case

find /home -iname '*.jpg'

-iname performs a case-insensitive name match. The quotes around '*.jpg' are essential: without them, the shell may expand the wildcard against files in your current directory before find receives it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Restrict results to files or directories

find /var/log -type f -name '*.log'
find /tmp -type d -name 'cache*'

-type f selects regular files and -type d selects directories. Combining a type test with a name test prevents similarly named objects of another type from appearing in the output.

Search by size

find /data -type f -size +100M

This selects regular files larger than 100 megabytes using GNU find‘s size suffix. A leading + means greater than the stated threshold; a leading - means less than it. If you omit a suffix, GNU find measures in 512-byte blocks, so using an explicit suffix is clearer.

Search by modification time

find /var/log -type f -mtime -1

-mtime -1 means the file was modified less than one 24-hour period ago, measured in complete 24-hour periods from the time the command starts. It is not the same as “modified since midnight.” For a live, current-state check, run the command again rather than relying on an old result list.

How find evaluates multiple tests

find evaluates expressions from left to right, with operator precedence. Adjacent tests are implicitly combined with logical AND. The -o operator means OR, and its precedence can surprise you when it is mixed with other tests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Group OR conditions deliberately

find /var/log -type f ( -name '*.log' -o -name '*.txt' )

The escaped parentheses make the OR apply only to the two name tests, while -type f applies to both alternatives. You can also quote the parentheses, for example '(' and ')', so the shell does not treat them as syntax.

Combine age and size conditions

find /data -type f -size +100M -mtime -7

This returns regular files larger than 100 megabytes that were modified within the last seven complete 24-hour periods. Add each predicate only after you have confirmed what it means for your task; a narrow expression is safer than a broad one.

Limit how deep the search goes

find . -maxdepth 2 -type f -name '*.conf'

GNU find supports depth controls such as -maxdepth. They are useful when a full recursive walk would include unrelated subdirectories. Availability and option details can vary with non-GNU implementations, so check the local manual when writing portable scripts.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Match semantics and readable output

With -name or -iname, find tests the name of each directory entry while walking the tree. The starting path controls where that test is applied, so the same expression can produce different results from ., /home, and /. A relative starting point normally produces relative-looking paths; an absolute starting point produces paths rooted at that location.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

locate, by contrast, matches patterns against complete paths stored in its database. A pattern can therefore match text in a parent directory as well as in the final filename. Implementations that provide -b can restrict the match to the basename, but that option is not universal. If you need an exact current basename and object type, use a follow-up find command.

Both commands can print names containing spaces, tabs, or newline characters. Treat output as data rather than as a list that is automatically safe to split on spaces. For a shell pipeline, use null-delimited output where the receiving command supports it.

Preview results before taking an action

With no explicit action, GNU find prints matching paths. Treat that output as a preview. Do not begin with deletion or a command that changes files until the displayed set is exactly what you intend.

Delete only after verifying the expression

find /tmp -type f -name '*.tmp' -mtime +30 -print

Review the paths first. If the result is correct and you have a backup or recovery plan, an explicit deletion action can be added:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
find /tmp -type f -name '*.tmp' -mtime +30 -delete

-delete is irreversible from the command’s perspective. Start with a narrow directory, avoid running as the superuser unless required, and never test a destructive expression against / or another broad starting point.

Run a command for each match

find . -type f -name '*.log' -exec wc -l {} ;

The {} token is replaced with each matching path. The escaped semicolon terminates -exec so the shell does not consume it. For commands that can process several paths at once, use + instead:

find . -type f -name '*.log' -exec wc -l {} +

Always quote or safely delimit paths when constructing more complex shell actions. A filename can contain spaces, tabs, or characters that have meaning to a shell.

Handle names safely in pipelines

Plain text pipelines can mis-handle unusual filenames. When a downstream program supports it, prefer a null-delimited form:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
find . -type f -print0 | xargs -0 grep -n 'error'

This preserves whitespace and newline characters in filenames. If you do not need a pipeline, -exec avoids the extra parsing step.

Using locate for indexed filename searches

The general form is:

locate [option...] pattern...

Patterns are matched against paths stored in the database. Supplying a shell-style pattern makes your intention explicit:

locate 'report.pdf'
locate '*[Mm]akefile'

The second command finds indexed paths containing a basename spelled Makefile or makefile, along with any matching path components allowed by the implementation. If you want a basename-only match, some implementations provide -b:

locate -b 'report.pdf'

Option names and defaults are not identical across GNU locate, mlocate, and plocate. Read man locate on the system where the command will run before putting implementation-specific options in a script.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why a new file may not appear

locate can return no result even though the file exists. The file may have been created after the last database update, or its directory may be excluded by the updatedb configuration. The index can also omit paths that the database builder cannot read.

To refresh the database, run:

sudo updatedb

Whether sudo is needed depends on how the database is configured and where it is stored. On systems that refresh automatically, the interval is distribution-specific; do not assume that a newly created file is indexed immediately.

Understand the indexed scope

updatedb decides which directories are included, which filesystem types or paths are pruned, and which database file is written. A successful command therefore does not guarantee that every mounted filesystem or private directory is searchable with locate. If the path matters and freshness matters, switch to find.

Refreshing and diagnosing the locate database

When a result is missing, separate three questions: does the path exist now, was its directory included in the index, and has the database been refreshed since the path was created? Run a live check such as find /home -name 'report.pdf' first when correctness matters. If find finds the file, run updatedb when you are allowed to refresh the configured database, then repeat the locate query.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the entry is still absent, inspect the local updatedb and locate manuals and configuration. A path can be intentionally pruned by directory or filesystem type, omitted because the database builder lacks read access, or stored in a database different from the one your command is reading. Refreshing cannot add a path that the configuration excludes.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Automatic refresh schedules are distribution-specific. Some systems run updatedb periodically, but the exact interval and service mechanism are not portable assumptions. For files created during an active troubleshooting session, a direct find query is the reliable test.

A practical workflow: locate first, find second

  1. Use locate for a fast lead. Start with a distinctive part of the filename, such as locate 'invoice-2026'.
  2. Check whether the result is current. The path is only evidence from the last database refresh; it is not a live existence check.
  3. Confirm with find. For example, find /home/alex -type f -name 'invoice-2026.pdf' tests the current tree and restricts the object type.
  4. Add metadata predicates. Add -size, -mtime, permissions, or grouped name conditions when the task requires them.
  5. Preview before acting. Print the final match set, then use -exec or -delete only after checking the paths.

This two-stage approach uses the index for discovery while keeping verification and file operations tied to the live filesystem.

Choosing a starting path and dealing with permissions

Current directory versus an absolute path

find . never searches above the current directory. If you launched the shell in /home/alex/projects, it will not inspect /home/alex/Downloads. Choose an explicit starting point such as /home, /var/log, or / when the scope requires it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Searching broad trees

A search from / can traverse many directories and may produce permission-denied messages. Narrow the starting point whenever possible. If you do need a system-wide search, run it with appropriate privileges and understand that elevated access changes which files the process can read; it does not change the meaning of the expression.

Symbolic links

By default, implementations commonly examine a symbolic link as a link rather than recursively following its target. GNU find provides options such as -L to follow links, but following links can cross into another tree or create cycles. Use that behavior only when you have defined the intended boundaries and have checked the local manual.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Portability: GNU locate, mlocate, and plocate

The command name does not identify one identical implementation on every Linux distribution. GNU locate, mlocate, and plocate use the same indexed-search idea, but they can differ in available options, quoting behavior, database format, and packaging. Debian documentation describes plocate as a fast way to find files by name and documents shell-safe escaping behavior. Treat implementation-specific switches as local features, not as universally portable syntax.

For scripts shared between machines, keep the expression simple, verify the installed command with its manual, and avoid assuming that a particular database path or refresh service exists. A script that needs current state should use find rather than depending on an index maintained by another package.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common mistakes and their fixes

  • Unquoted wildcard: find . -name *.log lets the shell expand the pattern first. Use find . -name '*.log'.
  • Unexpected OR results: mixed -o and implicit AND can apply tests to different parts of the expression. Escape parentheses and group each alternative.
  • Wrong time interpretation: -mtime -1 measures complete 24-hour periods, not the current calendar date. Choose a predicate that matches your time requirement.
  • Stale locate output: run find to check the live tree, or refresh the index with updatedb when you control its configuration.
  • Missing indexed directories: inspect the updatedb configuration; excluded or unreadable paths will not become locate results.
  • Searching too broadly: replace find / with a specific starting directory to reduce runtime, noise, and permission errors.
  • Acting before inspecting: print matches first, then add an explicit action only after verifying the expression.
  • Assuming every locate is the same: GNU locate, mlocate, and plocate can differ in options, quoting behavior, database format, and packaging. Check the installed implementation.

Command cheat sheet

Goal Command What it does
Exact filename below the current directory find . -name 'report.pdf' Live recursive name search.
Case-insensitive extension search find /home -iname '*.jpg' Matches JPG, jpg, and other capitalization variants.
Only regular log files find /var/log -type f -name '*.log' Excludes directories and other object types.
Directories beginning with cache find /tmp -type d -name 'cache*' Matches directory names by wildcard.
Large files find /data -type f -size +100M Finds regular files over the stated GNU size threshold.
Files modified recently find /var/log -type f -mtime -1 Matches files changed within the last complete 24-hour period.
Indexed name lookup locate 'report.pdf' Searches the filename database, which may be stale.
Refresh the locate database sudo updatedb Regenerates the configured index when permitted.
Verify a locate result live find /home -type f -name 'report.pdf' Checks the current tree and object type.

Bottom line

Choose find for correctness at query time, metadata filters, controlled scope, and any operation that changes files. Choose locate for a fast filename hint, remember that its database can be stale or selectively scoped, and use updatedb or a follow-up find when the result must reflect what exists now.

Frequently Asked Questions

Why does locate not find a file I just created?

The file may have been created after the last updatedb run, or its directory may be excluded or unreadable for the database builder. Use find for a live check, then run updatedb if you control the configured database.

Is find or locate faster?

locate is generally the quicker way to get a name-based lead because it scans a prebuilt filename database. find walks the requested directory tree at query time, but it is the appropriate choice when freshness, metadata predicates, or an exact scope matters.

Why must wildcard patterns be quoted?

Without quotes, the shell can expand a pattern such as *.log before find or locate receives it. Quoting passes the pattern unchanged so the command can apply it to every candidate path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does -mtime -1 mean?

It selects files modified less than one complete 24-hour period before the command started. It does not mean “modified since midnight,” so use a different predicate when your requirement is based on a calendar date.

How can I search more than one directory with find?

Provide multiple starting points before the expression, for example find /etc /var -name 'settings.conf'. Each tree is traversed using the same tests.

How do I make a destructive find command safer?

First run the exact expression without an action and inspect every printed path. Use a narrow starting directory, avoid unnecessary superuser privileges, and add -delete or -exec only after the match set is correct.

Does locate search every mounted filesystem?

Not necessarily. The updatedb configuration controls included directories, pruned filesystem types or paths, and the database that is written. A successful refresh does not imply that every mount or private directory is indexed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use the same locate options on every Linux system?

No. GNU locate, mlocate, and plocate share the basic model but can differ in options, quoting behavior, database format, and packaging. Check man locate on the target system before relying on implementation-specific switches.

The Bottom Line

Use locate to discover a likely filename quickly, then use find whenever the answer must be current, filtered by metadata, or safe to act on. Refresh with updatedb only within the configured index scope.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.