Thursday, March 6, 2008

A command to gather log files on UNIX

Here's a command that will gather logfiles underneath /opt/Tivoli into a single tar file (/mylogfiles.tar) on a UNIX machine:

find /opt/Tivoli -name "*.log" -exec tar -rf /mylogfiles.tar {} \;

Read on for details on the command options.

The 'find' command is EXTREMELY powerful, and this command leverages just one of its extended capabilities - the ability to run a command on each file found. The flag that allows this is -exec and the format of this flag is:

-exec command_to_run switches {} \;

Where the {} will be replaced with the name (including path) of each file found. The literal \; (backslash-semicolon) is the delimiter to tell 'find' that the end of the command has been reached.

No comments: