Quote:
Originally Posted by
ldorsey
I feel like I should use some sort of regex, but I don't want to force the shell script to look through the entire directory for that file. Is there a way to do this?
In any way the shell will have to look through the directory anyway, because file regexes ("globs" in shell speak) are expanded by the shell - always. If you write a command like
ls -l foo* The shell will first expand
foo* to a list of files matching this expression, let us say
fooA fooB fooC, and then feed this to the
ls command. Entering the command
ls -l fooA fooB fooC would have had the same effect.
Therefore: either you know exactly what your file is named beforehand or you will have to use a glob (like "*", "?", etc.). On the up side it doesn't take much time to search through a directory at all, because UNIX kernels are in the habit of putting every ounce of spare memory to disk caching. Because metadata (inodes, directories, the supernode and so on) are used very often (compared to the content of most files) chances are the needed data are already in memory and are found pretty quickly.
I hope this helps.
bakunin