unixfindrcs

Trying to use the unix command 'find' to find all files checked into RCS


I am trying to use the find command to find all of the files that are checked into RCS from my home directory. This includes files that end in things like c,v. When I run the commands such as

find . -name \*v 
find . -name \*c,v 

this is close to the way I want and will give me files looking like

./LABTECH/RCSlab/trig/RCS/main.c,v

This is great except if I for some reason have a random file on my computer that ends in a v or in c,v that isn't in RCS, it is going to return that, too. Things like find . -name \*RCS\*c,v do not work and return nothing. find . -name RCS\* will return the RCS directory, but none of the files inside the RCS directory.

Is there someway I can get a find command to return all files that are in RCS directories, starting from my home directory. I know I can filter out unwanted files afterwards, but it needs to only be showing me files from the RCS directory to begin with.

After reading all the answers I decided that assuming ,v are RCS files is the best way to go about this because we have not covered scripting for my teacher to ask us a question like that. We are not supposed to pipe into xargs or grep for the question either,and -path does not work on my version of unix. It was helpful to know from perreal that using -name does not allow me to match '/' which clears up some other questions I had but did not ask. I have come to the understanding that there is no way to do this without -path or some type of following command or script. Thank you all for your help.


Solution

  • You should work on the presumption that if the file name ends ,v, it is an RCS file. Any interlopers that are not should be few and far between.

    find $HOME -name '*,v'
    

    If you are consistent about using an RCS sub-directory, then you can use the POSIX find option -path to track down files in RCS sub-directories with:

    find $HOME -path '*/RCS/*,v'
    

    If you must identify actual RCS files, then you'll need to run some program (script) to validate that the files really are RCS files:

    find $HOME -name '*,v' -exec rcsfiles {} +
    

    where rcsfiles is a hypothetical script that echos the names of the arguments it is given that actually are RCS files. I would use the rlog command to identify whether the file is an RCS file or not. The rcs command doesn't have a no-op operation that will validate an RCS file. The rcsfiles script might well be as simple as:

    for file in "$@"
    do
         if rlog "$file" >/dev/null 2>&1
         then echo "$file"
         fi
    done