我有两个文件夹,它们的文件名相同,但内容不同。因此,我试图生成一个脚本来了解差异并查看正在更改的内容。我在下面写了一个脚本:
folder1="/opt/dir1"
folder2=`ls/opt/dir2`
find "$folder1/" /opt/dir2/ -printf '%P\n' | sort | uniq -d
for item in `ls $folder1`
do
if [[ $item == $folder2 ]]; then
diff -r $item $folder2 >> output.txt
fi
done
我相信此脚本必须有效,但不会在输出文件夹上提供任何输出。 因此,所需的输出应该在一个文件中。例如:
cat output.txt
diff -r /opt/folder1/file1 /opt/folder2/file1
1387c1387
< ALL X'25' BY SPACE
---
> ALL X'0A' BY SPACE
diff -r /opt/folder1/file2 /opt/folder2/file2
2591c2591
< ALL X'25' BY SPACE
---
> ALL X'0A' BY SPACE
感谢您的帮助!
答案 0 :(得分:0)
好的。双重:
ls
。忘记它的存在。 ls
用于在我们的控制台中进行漂亮的打印。在脚本中,使用find
。while read
循环。所以:
{
# make find print relative to `/opr/dir1` director
cd /opt/dir1 &&
# Use `%P` so that print without leading `./`
find . -mindepth 1 -type f -print "%P\n"
} |
while IFS= read -r file; do
diff /opt/dir1/"$file" /opt/dir2/"$file" >> output/"$file"
done
注意: