Home » Questions » Computers [ Ask a new question ]

Find files in a path

Find files in a path

I want to search for a specific file type(.jpeg) in a given path very efficient manner.

Asked by: Guest | Views: 254
Total answers/comments: 4
Guest [Entry]

"Depends on what you want as a result. ls -R won't tell you which directory it found the file in, while find will.

Also, ls -R generates more output, which is subsequently filtered, while find searches specifically for what you wanted. Without having done measurements, I would guess that find is generally more efficient."
Guest [Entry]

find ./ -name *.jpg -print
Guest [Entry]

"Install ""locate"" or ""slocate""

Run ""updatedb"" and ""locate \*.jpeg""

updatedb builds a index database for the filenames in your system.

locate will find the file from the database instead of scanning directory by directory.

It is faster that find if you are do searching a lot after each database build. You might want to setup a cron job to run the updatedb command.

This is kind of like Google Desktop Search, but only for searching filename."
Guest [Entry]

"Find is definitely the best tool for this job.
The output of ls -R will be difficult to parse (the file names are interleaved with the directory names). Besides with ls you will have hard time dealing with names with spaces, whilst find . -name '*.jpeg' -print0 will generate a list separated by null-characters. xargs, grep and others have option to read this kind of input. This means all weird names are preserved."