Summary

In this chapter, we showed how to list files and file metadata with ls and stat, and how to set file timestamps with touch. The touch experiments revealed information about the time-of-day clock and its limited range in many current systems.

We showed how to create unique temporary filenames with the shell process ID variable, $$, with the mktemp utility and a do-it-yourself sampling of streams of random numbers. The computing world can be a hostile environment, so it is worth protecting your programs from attack by giving their temporary files unique and unguessable names.

We described the locate and slocate commands for fast lookup of filenames in a regularly updated database constructed by complete scans of the filesystem. When you know part or all of a filename and just want to find where it is in the filesystem, locate is generally the best way to track it down, unless it was created after the database was constructed.

The type command is a good way to find out information about shell commands, and our pathfind script from Chapter 8 provides a more general solution for locating files in a specified directory path.

We took several pages to explore the powerful find command, which uses brute-force filesystem traversal to find files that match user-specified criteria. Nevertheless, we still had to leave many of its facilities for you to discover on your own from its manual pages and the extensive manual for GNU find.

We gave a brief treatment of xargs, another powerful command ...

Get Classic Shell Scripting 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.