Solved

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

Posted on 2014-01-03
7
240 Views
Last Modified: 2014-01-21
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
Comment
Question by:c11v11
7 Comments
 
LVL 19

Expert Comment

by:Patricksr1972
ID: 39753277
Hi

I would use:

ls /directory | grep <name you are looking for>
0
 
LVL 2

Expert Comment

by:karanprabham
ID: 39753279
For Speed use locate command
0
 
LVL 9

Expert Comment

by:jeff_01
ID: 39753669
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 84

Expert Comment

by:ozo
ID: 39753684
Can you run find on the server machine?
0
 
LVL 62

Expert Comment

by:gheist
ID: 39755306
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
 
LVL 28

Accepted Solution

by:
serialband earned 20 total points
ID: 39756309
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
 
LVL 48

Expert Comment

by:Tintin
ID: 39757988
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Virtualizing very old guest OS 4 95
Hacked File Timestamps 4 62
Can't ping New Linux Servers 40 66
Securing Azure Oracle instance of Linux VM 4 57
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question