Reputation: 3937
I have a shell script to automate the creation of separate tar files for several directories; cd'ing to each and calling the command:
tar cf pakage1.tar *.csv *.fmt
Most directories contain .fmt and .csv files, I need a solution for when a *.csv may not exist but *.fmt does and therefore a tar is required. I haven't found an 'ignore wildcard if not found' command, does one exist?
Thankyou in advance.
Upvotes: 1
Views: 875
Reputation: 16327
Use find
in combination with xargs
:
find . \( -name '*.csv' -or -name '*.fmt' \) -print0 | xargs -0 tar cf pakage1.tar
-print0
and -0
to use null-separators instead of spaces otherwise it will choke on filenames with spaces in them.
Upvotes: 3