Here, starting-directory is the place in the directory tree at which to begin the search (the search will continue through the entire directory sub-tree from this vertex), and pattern is a file name pattern (either a full file or directory name, or one that uses wild cards, ie. "*.mpg" or "X*").
In this example, the file name search will be case insensitive.
Here path is a file or directory, and only those files are found which have been modified more recently than path.The newer option is very convenient in designing backup scripts, in conjunction with the touch command: if you "touch /root/.backup" at the end of each backup, "find / -newer /root/.backup" will find all files and directories modified since the last backup.
Any of the find commands will produce output more like "ls -l" by using the option "-ls". This is useful if information about the found files is needed.
find / -newer /root/.backup -type f | tar -czf backup.tgz -T -Here, the files modified since the last backup will be placed in the gzipped tarball "backup.tgz". The "-T" option to tar tells it to get the list of files to place in the tarball from a file, and "-T -" specifies that stdin is the file to be used. By piping stdout from the find command (which is of course the list of file names) into stdin for the tar command, we avoid the necessity of creating a temporary file on disk with the list of file names to be backed up. Note that stdin and stdout (as well as stderr) are "streams": a stream of data can only be scanned once (the water in a stream passes by only once; it never returns as long as you ignore evaporation and rain). This means that some tar options won't work, since the list of file names cannot be rescanned (ie., -W to verify the tarball).
Since tar stores path names it is sometimes hard to remember exactly what filename to use when extracting a specific file. You can use a pipe to make the job easier:
tar -tzf backup.tgz | grep -e 'filename' | tar -xvzf backup.tgz -T -will list the table of contents of the tarball, grep the one with the filename you are looking for (but with the path information tar needs to find it) and extract that file.
Note that if you write a file to disk and then use cmp to see if it has been written correctly, you must first umount and re-mount the disk. This guarantees that you are not checking the actual file on the disk, and not just the copy in cache.
Submit the script to your instructor.
©2008, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.
Please send comments or suggestions to the author.