Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

Try doing this :

find . -path '*/RCS/*,v'

If your version of find lack the -path option, you can test :

find . -name '*,v' -print | grep -E 'RCS/[^/]+,v$'

From find man-page:

-name pattern
       Because the leading directories are removed, the file names
       considered for a match with -name will never include a slash, 
       so `-name a/b' will never match anything (you probably need 
       to  use -path instead). 

So you can use -path instead of -name as in sputnick's answer. Another way is first finding the relevant directories:

find -name '*RCS' -type d | xargs -n1 -I{} find {} -name '*.c,v'
find . -type f -name '*,v' | grep /RCS/

This will find all files whose names end in ,v that are under a directory named RCS.

If you want to be sure they're immediately under an RCS directory:

find . -type f -name '*,v' | grep '/RCS/[^/]*$'

This ensures that there are no additional / characters after the /RCS/.

Note that CVS also uses the ,v suffix (and the same file format) and does not use a special directory name for its repository files; it uses a CVS directory, but that's created when you checkout files, and it only contains a handful of metadata files. If you're not using CVS on your system, that probably won't be an issue. If you're using both RCS and CVS, the above should find only ,v files maintained by RCS, ignoring those maintained by CVS.

The other answers using find -path are probably better, but this is an alternative -- and for other purposes, grep regular expressions are more powerful than the shell patterns accepted by find -path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top