On Wed, Oct 22, 2003 at 10:43:50PM -0600, Scott Gerhardt wrote: > I am having trouble combining the tar and find command. I want to > tar and > delete all .bak,.Bak,.BAK files. > > I am using the following command but keep receiving errors. [...] > The script is as follows > ========================================= > #! /bin/bash > set +x > TAR_DIR=/home/tarbackups; > FILES_DIR=/home/common; > tar --remove-files -cvzpf $TAR_DIR/bak_files_`date +%F`.tar.gz\ > `find $FILES_DIR -xdev -type f -iname "*.bak"`; > ========================================== [...] > Here is some error output returned: > > tar: jobs/ROOF: Cannot stat: No such file or directory > tar: LAYOUTS/RESIDENTIAL/FRASER/219: Cannot stat: No such file or > directory > tar: LEWIS: Cannot stat: No such file or directory > tar: CRES.bak: Cannot stat: No such file or directory [...]
--- --- --- Matthew Seaman <[EMAIL PROTECTED]> replied: > The problem is that you have file/directory names like 'ROOF LAYOUTS' > which contain spaces and possibly other filenames containing > characters with syntactic significance to the shell. > > Try: > > find $FILES_DIR -xdev -type f -iname "*.bak -print0 | \ > xargs -0 tar --remove-files -cvzpf $TAR_DIR/bak_files_`date > +%F`.tar.gz > --- --- --- Would the following approach also work? (Have sed surround each item returned by the find command with single quotes?) --- #! /bin/bash set +x TAR_DIR=/home/tarbackups; FILES_DIR=/home/common; tar --remove-files -cvzpf $TAR_DIR/bak_files_`date +%F`.tar.gz\ `find $FILES_DIR -xdev -type f -iname "*.bak" | sed "s/\(^.*$\)/'\1'/"`; --- or the backticks in the last line replaced with the newer alternative "$()": "$( find $FILES_DIR -xdev -type f -iname "*.bak" | sed "s/\(^.*$\)/'\1'/" )" ; Do the characters \ * $ in sed's argument need to be quoted further, to protect them from interpretation by the shell? The "find" portion of the command works correctly, as written above, on my FreeBSD machine using /bin/sh or /usr/local/bin/bash, but I don't know why those characters in sed's argument don't need to be further escaped. --- --- --- Steve D Portales, NM US _______________________________________________ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"