Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Does diff exclude (-x and -X) also work with directories?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
VinzC
Advocate
Advocate


Joined: 17 Apr 2004
Posts: 4672
Location: Theux (Belgium)

PostPosted: Sun Aug 07, 2011 9:27 pm    Post subject: Does diff exclude (-x and -X) also work with directories? Reply with quote

Hi all.

Been banging my head against it for more than one hour in vain. You might ask if I had nothing better to do today? No. I am in vacation.

So I'd like to recurse diff -Nau through a bunch of directories but excluding some files (which happen to be symbolic links actually) in some sub directories. I've tried -x */subdir/* or -x path/to/diff/subdir/* (with or without quotes) or using -X exclude-file, which contains the whole list of files I want to exclude... No! That beast doesn't want to listen!

Does anyone have an idea what I could be missing?

For a concrete example, I would like to recursively compare {old,new}/lib/rc/networking/ excluding {old,new}/lib/rc/networking/modules-enabled/*. Files in modules-enabled are symbolic links to files in ../modules-available/ . (FTR, these are directories I added to my system.)

Thanks in advance for any suggestion.
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
GNU/Linux user #369763
“Wow! I feel root”
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1567
Location: U.S.A.

PostPosted: Mon Aug 08, 2011 1:02 am    Post subject: Reply with quote

You might try using 'find'.
_________________
pjp wrote:
I didn't misquote you, I just misunderstood you.
Back to top
View user's profile Send private message
VinzC
Advocate
Advocate


Joined: 17 Apr 2004
Posts: 4672
Location: Theux (Belgium)

PostPosted: Mon Aug 08, 2011 9:58 am    Post subject: Reply with quote

BoneKracker wrote:
You might try using 'find'.

... and compare files by individual pairs? I guess so. It's less immediate and I will need a script and a loop to prefix one of the files.

But my question still remains. In the French man I read diff works with files and directories. But in the English man I only see "file names which match the pattern". File name is abstract to me. I understand "base name" and "path name" or even "full path name" but just "file name" can mean about anything.

Note I tried once more, realized there's one thing I didn't do:
Code:
diff -Naur {old,new}/path -x subdirname
and it worked!

So in the end only the directory component (i.e. the directory base name) must be specified, no fancy wildcards (unless maybe the excluded directory names are based on a pattern), slashes, nothing, just the directory name.

So in the manual, "file name" must indeed be read as "base name" and not the entire path name.
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
GNU/Linux user #369763
“Wow! I feel root”
Back to top
View user's profile Send private message
wildhorse
Tux's lil' helper
Tux's lil' helper


Joined: 16 Mar 2006
Posts: 148
Location: Estados Unidos De América

PostPosted: Mon Aug 08, 2011 3:35 pm    Post subject: Reply with quote

The behaviour of diff is documented - in the source code. :wink:
The matching is eventually done in fnmatch_loop.c, which can function exactly the way you expected. But diff calls this function with a flag that makes it match only the base names of a file specification. This behaviour of diff is defined in a mess called fnmatch.m4, which makes it through the Autoconf process into the C source code. It's the FNM_FILE_NAME flag that defines the behaviour of the matching routine, in case you like to change the code. (Don't.)

'info diff' gives you a few more details:
Quote:
To ignore some files while comparing directories, use the `-x
PATTERN' or `--exclude=PATTERN' option. This option ignores any files
or subdirectories whose base names match the shell pattern PATTERN.
Unlike in the shell, a period at the start of the base of a file name
matches a wildcard at the start of a pattern. You should enclose
PATTERN in quotes so that the shell does not expand it. For example,
the option `-x '*.[ao]'' ignores any file whose name ends with `.a' or
`.o'.


As always with unix, your result may differ with different flavours of diff.
Back to top
View user's profile Send private message
VinzC
Advocate
Advocate


Joined: 17 Apr 2004
Posts: 4672
Location: Theux (Belgium)

PostPosted: Mon Aug 08, 2011 4:41 pm    Post subject: Reply with quote

wildhorse wrote:
As always with unix, your result may differ with different flavours of diff.

Thanks. That is interesting indeed for I tried -x modules-en* and it worked, too so unlike what the info says, shell patterns work. I didn't try with a regular expression on the base name though. BTW I rarely dig into the info and mostly use the man pages (RTFM). Perhaps I should investigate the info pages more often, that's right...
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
GNU/Linux user #369763
“Wow! I feel root”
Back to top
View user's profile Send private message
wildhorse
Tux's lil' helper
Tux's lil' helper


Joined: 16 Mar 2006
Posts: 148
Location: Estados Unidos De América

PostPosted: Mon Aug 08, 2011 5:31 pm    Post subject: Reply with quote

VinzC wrote:
wildhorse wrote:
As always with unix, your result may differ with different flavours of diff.

Thanks. That is interesting indeed for I tried -x modules-en* and it worked, too so unlike what the info says, shell patterns work. I didn't try with a regular expression on the base name though. BTW I rarely dig into the info and mostly use the man pages (RTFM). Perhaps I should investigate the info pages more often, that's right...
Regular expressions are not supported. Only wildcards, in particular ?, *, and []. The backslash is being used as escape character. You can also make the search case-insensitive with the option --ignore-file-name-case.
Back to top
View user's profile Send private message
VinzC
Advocate
Advocate


Joined: 17 Apr 2004
Posts: 4672
Location: Theux (Belgium)

PostPosted: Mon Aug 08, 2011 5:47 pm    Post subject: Reply with quote

wildhorse wrote:
Regular expressions are not supported. Only wildcards, in particular ?, *, and []. The backslash is being used as escape character. You can also make the search case-insensitive with the option --ignore-file-name-case.

Well, if I read «a period at the start of the base of a file name matches a wildcard at the start of a pattern» that furiously sounds like a regular expression. Limited (indeed), still but a regular expression. But I recon, it's not the point to battle around a definition, the most important is to make it work and it does now 8) .

EDIT: Oh, and I must now say I'm pretty happy for I was crazy enough to edit my diff's by hand... (yeah, and clear 80% of it manually. I know, I know.)

BTW, I know I can look into the source code but I don't think any GNU/LInux or Gentoo user would dare put their hands in there even as a last resort... (I don't take it as an excuse for myself, I just say this is not the best place to provide the most complete documentation.)
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
GNU/Linux user #369763
“Wow! I feel root”


Last edited by VinzC on Mon Aug 08, 2011 6:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
wildhorse
Tux's lil' helper
Tux's lil' helper


Joined: 16 Mar 2006
Posts: 148
Location: Estados Unidos De América

PostPosted: Mon Aug 08, 2011 6:20 pm    Post subject: Reply with quote

I was just curious about the functions. Turns out they are a mess. BTW, my real name has been eternalised in some of the GNU code. I am immortal. :D
Back to top
View user's profile Send private message
VinzC
Advocate
Advocate


Joined: 17 Apr 2004
Posts: 4672
Location: Theux (Belgium)

PostPosted: Mon Aug 08, 2011 6:31 pm    Post subject: Reply with quote

wildhorse wrote:
I am immortal. :D

O.M.G. ! Never have believed I'd meet one! Hold on please, I'm taking a picture... (Must show that to whomever I'll meet at the other side!)
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
GNU/Linux user #369763
“Wow! I feel root”
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum