Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast way to find file names in Linux and specify directory

Tags:

linux

find

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)?

like image 397
warship Avatar asked Aug 30 '25 17:08

warship


2 Answers

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.

like image 101
Eric Renouf Avatar answered Sep 02 '25 10:09

Eric Renouf


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

like image 24
mrflash818 Avatar answered Sep 02 '25 10:09

mrflash818