2 cent Linux tip – using find and tar for a selective backup.

120

 

So the basic requirements in this scenario boil down to finding all the config files under the ~/.cxgames tree. I have a ~/etc directory to keep a backup of important things such as settings and handy scripts. I will copy my tar file to the ~/etc directory so I can find it easily later. However, I don’t want every *.cfg file under my Steam bottle, just the ones for those specific games (Team Fortress and Left 4 Dead). When I run the following command, I’ll discover those games have a common top-level directory, “~.cxgames/Steam/drive_c/Program Files/Steam/steamapps”.

find ~/.cxgames -name "*.cfg"

When I run the following command, however, I’ll get an error due to spaces in the directory/filename structure.  Note the backslash in “Program Files” is an escaped space for the shell to properly interpret this.

find .cxgames/Steam/drive_c/Program Files/Steam/steamapps/ | xargs tar -rf ~/etc/steam-settings.tar

The find command has a switch -print0 to deal with this, and xargs will process this find output format with the -0 flag. Therefore the following command will get the files I need

find ~/.cxgames/Steam/drive_c/Program Files/Steam/steamapps/ -name "*.cfg" -print0 | xargs -0 tar -rf ~/etc/steam-settings.tar

Restoring is as simple as running, the following command from within my home directory.

tar xvf ~/etc/steam-settings.tar

Perhaps some day we’ll have a Linux steam client, and a promotional TF2 item named the Unix Pipe.