用于确定目录“diff”的脚本

发布于 2024-11-08 11:31:20 字数 460 浏览 1 评论 0原文

我有两个目录,它们是同一软件包的不同版本。我想列出两者之间已更改的所有文件/目录,然后将这些差异复制到新目录。

我一直在使用 md5sumdiff -Nurq 尝试不同的脚本,但无法获得我正在寻找的结果。

有什么建议吗?

编辑

我最初尝试使用md5sum,但这似乎不起作用,尤其是在新文件丢失的情况下。

接下来我尝试了这样的循环:

for x in `diff -Nurq ./dir1/ ./dir2/ | awk -F" " '{print $4}'`
do 
  mkdir -vp ./dir_1_2_upgrade/$x; 
  cp $x ./dir_1_2_upgrade/$x
done

但最终生成了一堆目录而没有文件。

I have two directories which are different versions of the same software package. I'd like to list all the files/directories that have changed between the two then copy those differences to a new directory.

I've been trying different scripts with md5sum and diff -Nurq but haven't been able to get the result I'm looking for.

Any recommendations?

Edit:

I originally tried taking md5sums, but that didn't seem to work especially if new files were missing.

Next I tried a loop like this:

for x in `diff -Nurq ./dir1/ ./dir2/ | awk -F" " '{print $4}'`
do 
  mkdir -vp ./dir_1_2_upgrade/$x; 
  cp $x ./dir_1_2_upgrade/$x
done

But that ended up making a bunch of directories and no files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错爱 2024-11-15 11:31:20
source=SOME_DIR
dest=OTHER_DIR

# TODO: rewrite as awk script
delta=`diff -ur $source $dest`
deleted=`echo "$delta" | grep "^Only in ${source}:" | sed "s/^Only in ${source}: //"`
added=`echo "$delta"   | grep "^Only in ${dest}:"   | sed "s/^Only in ${dest}: //"`
changed=`echo "$delta" | grep '^\+\+\+' | awk '{print $2}'`

echo $deleted
echo $added
echo $changed

如果文件名不包含空格,则有效。如果您希望它尽可能通用,请查看程序的源代码,例如 git-diff

source=SOME_DIR
dest=OTHER_DIR

# TODO: rewrite as awk script
delta=`diff -ur $source $dest`
deleted=`echo "$delta" | grep "^Only in ${source}:" | sed "s/^Only in ${source}: //"`
added=`echo "$delta"   | grep "^Only in ${dest}:"   | sed "s/^Only in ${dest}: //"`
changed=`echo "$delta" | grep '^\+\+\+' | awk '{print $2}'`

echo $deleted
echo $added
echo $changed

works if filenames contain no spaces. If you want this to be as general as possible, check out the source for a program such as git-diff.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文