简体   繁体   中英

Exclude directories from command line output

I'm attempting to create a tar.gz of all files added or modified between SVN revisions, using the following command:

svn diff -r1:HEAD --summarize|grep -ve '^D'|awk '{print $2}'|xargs tar -vzcf file.tar.gz --exclude .svn

I suppose I'm looking for any tips to tighten up this command, however my main issue is that folders with modifications are being added to the archive, which in turns is adding the entire folder's contents, which is not desirable.

I was hoping for something along the lines of |xargs test -f but that it would return the filename if true, and nothing if false, therefore excluding directories from the mix.

Thanks!

I decided to solve this with a quick perl script:

exclude_dir.pl:

#!/usr/bin/perl -w

use diagnostics;
use strict;

my $arg = '';

while ($arg = shift) {
  print "$arg\n" if -f $arg;
}

And then modified the command to read:

svn diff -r1:HEAD --summarize|grep -ve '^D'|awk '{print $2}'|xargs exclude_dir.pl|xargs tar -vzcf file.tar.gz --exclude .svn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM