make diff to ignore symbolic link
Solution 1
Use find in the following way:
find . ! -type l
This option should skip following symbolic links. Use that command to locate your file before running diff.
Solution 2
In GNU diff v3.3 there is now an option --no-dereference that does the trick
Solution 3
If you add lines like:
dir1/config.mk
dir2/config.mk
to a file .ignore-diff
then you can execute diff(1)
like this:
diff -ur -X .ignore-diff
Dien Nguyen
Updated on June 25, 2022Comments
-
Dien Nguyen almost 2 years
My project has the following structure
/project/config.mk /project/dir1/config.mk -> ../config.mk /project/dir2/config.mk -> ../config.mk
When I used
diff
to create the patch file, the/project/config.mk
was done correctly, but the two symbolic links got some problems. They were both treated as new files, the diff sections were the whole content of theconfig.mk
file. I tried to find adiff
option to disable following symbolic link, but there is no such option available. Any suggestions are appreciated.As Overbose's suggestion, I create this script. It works. Thank everyone for taking time answering.
#!/bin/sh -v ori_dir=$1 new_dir=$2 patch_file=./patch_file if [ -f ${patch_file} ] then rm ${patch_file} fi ori_files=`cd ${ori_dir} ; find ./ -type f ! -type l` for i in ${ori_files} ; do if [ -f ${ori_dir}/$i ] then if [ -f ${new_dir}/$i ] then diff -rup ${ori_dir}/$i ${new_dir}/$i >> ${patch_file} fi fi done