warship
warship

Reputation: 3024

Fast way to find file names in Linux and specify directory

This command is slow: find / -name 'program.c' 2>/dev/null

1) Any faster alternatives?

2) Is there an alternative to the above command to search for a file within a specific nested directory (but not the entire system)?

Upvotes: 4

Views: 7578

Answers (3)

mrflash818
mrflash818

Reputation: 934

For fast searching, you probably want locate It is usually setup to do a daily scan of the filesystem, and index the files.

http://linux.die.net/man/1/locate

Upvotes: 2

Dyno Fu
Dyno Fu

Reputation: 9044

although locate & updatedb is for the whole system, the search usually is faster.

Upvotes: 1

Eric Renouf
Eric Renouf

Reputation: 14520

The first / in your command is the base directory from which find will begin searching. You can specify any directory you like, so if you know, for example, that program.c is somewhere in your home directory you could do find ~ -name 'program.c' or if it's in, say, /usr/src do find /usr/src -name 'program.c'

That should help with both 1 and 2.

If you want a command that's not find that can be faster you can check out the mlocate stuff. If you've done a recent updatedb (or had cron do it for you overnight) you can do locate <pattern> and it will show you everywhere that matches that pattern in a file/directory name, and that's usually quite fast.

Upvotes: 4

Related Questions