Chapter 9. Finding Files: find, locate, slocate
How easy is it for you to search for files throughout your filesystem?
For the first few files that you created, it was probably easy enough just to remember their names and where you kept them. Then when you got more files, you created subdirectories (or folders in GUI-speak) to clump your files into related groups. Soon there were subdirectories inside of subdirectories, and now you are having trouble remembering where you put things. And of course, with larger and larger disks it is getting easier to just keep creating and never deleting any files (and for some of us, this getting older thing isn’t helping either).
But how do you find that file you were just editing last week? Or the attachment that you saved in a subdirectory (which seemed such a logical choice at the time)? Or maybe your filesystem has become cluttered with MP3 files scattered all over it, and you want to collect them all up.
Various attempts have been made to provide graphical interfaces to help you search for files, which is all well and good—but how do you use the results from a GUI-style search as input to other commands?
bash and the GNU tools can help. They provide some very powerful search capabilities that enable you to search by filename, dates of creation or modification, even content. They send the results to standard output, perfect for use in other commands or scripts.
So stop your wondering—here’s the information you need.
9.1 Finding All Your ...
Get bash Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.