• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

How to find a file based on name easily from thousands files

Most of my data is on the NFS side. There are more than hundreds of thousand files in each directory. how can find a file based on name easily?I don't what happened when I run find ./  -name "**"  but it is very slow to show the result. Anybody has any idea about this ? can you tell me what happen when I run the find command? like the inode, directory, etc
0
c11v11
Asked:
c11v11
1 Solution
 
Patrick BogersDatacenter platform engineer LindowsCommented:
Hi

I would use:

ls /directory | grep <name you are looking for>
0
 
karanprabhamCommented:
For Speed use locate command
0
 
jeff_01Commented:
locate is fast but only if the index is kept up to date. It searches through a prebuilt database which is updated using the command updatedb .
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ozoCommented:
Can you run find on the server machine?
0
 
gheistCommented:
If it is just thousands of files just scroll them on screen. In couple of hours you will be ready

If it is a lot more...
find /wherever -type f -name \*heeeeelp\*

you said you want to find files...and let find expand wildcard, not the shell
0
 
serialbandCommented:
The find command is traversing the entire directory structure under the search directory to locate your file.

The locate command will only work on systems that have it installed or enabled.  Not all linux distros installed it by default.  The database is updated overnight and will not contain files or changes in the new day.  It's very fast at finding older existing files, but it won't find any newly created files.

if you know the subdirectory layer that your file resides in, you can also just do ls with wildcards.  There's no need to pipe to a grep.

You can find the file in the 2nd level subdirectory
ls -l subir*/*file*
ls -l  subdir/*file*
ls -l */*
ls -l */file*
ls -l sub?/file*
list the files maching the pattern file00 through file99 in subdirectories sub1 through sub9
ls -l sub[1-9]/*file[0-9][0-9]


You can even go down a 3rd level
ls -l subdir/subdir_level2/*file*
ls -l subdir[0-9]/*/*
ls -l */*/*

This will be slightly faster than the find command if you have several subdirectory layers, since it's not traversing all subdirectories and files underneath.
0
 
TintinCommented:
If you don't know what directory or sub-set of directories the file might exist in and you don't have an index of the files (via locate or any other similar command), then you are essentially stuck with the speed of traversing NFS.

Note that

find ./  -name "**"

is effectively the same as

find ./

ie:  it will match everything.

Make sure you include part of the filename in the match, eg:

find . -name "filename*"
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now