Usage: /tools/findem [-help] [-dir DIR] [-between SERIALDATES] [-maxdepth NUMBER] [-idir DIR] [-xdir DIR] [-nmfl NMFILE] [-xnmfl NMFILE] [-asciii] [-skiptilda] [-pattern PATTERN] [-nopatcase] [-newpattern PATTERN] [-commit] [-pati] [-sortby ATTRIBUTE] [-pathrgx RGX] [-nocase] [-pathlevel STEMLEVELS] [-anylevel] [-silent] [-exec cpffl|mvffl {} DIR ;] [-interactive] [-update] [-nocheckdest] [-moveanyway] # 5 10 20 30 40 50 60 70 80 #|...+....1....+....2....+....3....+....4....+....5....+....6....+....7... # |...+....1....+....2....+....3....+....4....+....5....+....6....+....7... Where: -help Display this summary -dir DIR Originating source directory for findem -between DATE1,DATE2 Only files whose mtime is between DATE1 and DATE2 are selected. DATE1 and DATE2 are two serial dates. eg. -between 19930000,20231231 -maxdepth NUMBER Maxdepth from the specified directory -idir REGEX Include only the directories whose pieced stems match the specified regex. May be specified zero or more time. -xdir REGEX Exclude the directories whose pieced stems match the specified regex. May be specified zero or more time. -nmfl REGEX Specify to select only these named files that match the regex. eg. -nmfl '.java|.xmi' -xnmfl NMFILE Exclude the named files that match the regex. -ascii Skip any file that is not ASCII per UNIX MIME file and will only include ASCII and XML. It is used with search and searchreplace -skiptilda Skip any directory or file where a ~ appears. -pattern PATTERN Search for pattern -nopatcase Ignore the pattern case -newpattern PATTERN Replace with new pattern -commit Overwrite the file, if not specified then just print to result -pati Go interactive when replacing patterns with new patterns in a file and prompt the user before commiting and writing the changes. -sortby ATTRIBUTE Sort by attribute the result where attribute can be one of atime mtime ctime size -pathrgx RGX Look into directory matching the regular expression -nocase Ignore case when matching the regular expression -pathlevel STEMLEVELS Break the fully located file (along its path) into pieces, then follow each piece from right to left to select only these files whose fully qualified names match the stem at each level. The levels are numbered from right to left with the rightmost level starting at 0 and is the located file itself, and level 1 is the stem that is directly below it. Going from right to left, the level is increased by one for each broken stem. -anylevel Ignore the levels and match any piece regardless of its level. -silent Silent when making changes like copying or moving files, or when replacing patterns within files. -quiet Suppress verbose information about the found files whether they will be processed or not -sortby ATTRIBUTE Sort the located file by sorting them following the attribute that can be atime|mtime|ctime|size -exec cpffl|mvffl Copy or move the found files to a directory. eg. to copy the found files to ./d123 -exec cpffl {} ; eg. to move the found files to ./d123 -exec mvffl {} ; -interactive Interactive prompts the user to replace the file before copying it or moving it. True only if the file already exists in the destination directory. -update Update will overwrite pre-existing file in the destination directory. -nocheckdest Write to destination without checking and validating the named destination. By default findem when used with -exec the destination is checked to be within the /tmp directory. -moveanyway Move the found files regardless of their pre-existence. -settransform identifier Only used along -exec cpffl to apply a transform on the file name on the ffl before copying it or moving it -showtransforms Show the coded transforms in your FindemTrans.pm -freetransform anonstr Specify inline an anonymous sub as a transform -setdirtransform identifier Only used along -exec cpffl to apply a transform on the path of the file -transcond dtf|ftd When transforms of file names and directory stems is in effect, then the (-transcond dtf) will cause a conditional transformation: if stem transformed then transform file name and (-transcond ftd) will cause a conditional transformation: if file name is transformed then transform stem. In it absence both transformations will occur regardless. -backup extension Backup copied or moved files with extension: eg. .bk ~bak ~datetime|date|epotime.bk|~atime.bk atime, mtime, and ctime are substitued from the file stat; also it is possible to use multiple or repeated entries like in: eg. ~atime~mtime~datetime~foo-ctime-atime.bk Recall that using the pattern substitution and committing the changes with backup may result in a repeated chain of backed up file (since the backup contain the old pattern); for this reason end your backup extension with something like .bk so that you can excluded it with -xnmfl on subsequent run. -relative Copy or move the files relative to the directory specified by -dir -samedirok Make changes to initial directory when targetdirectory is the same as initial dirctory: eg. findem -dir /tmp/junkdir -exec cpffl {} junkdir ; findem can find the files and copy or move the found files to a destination directory. To copy the found files, use the option -exec cpffl {} somedestinationdir ; To move the found files, use the option -exec cpffl {} somedestinationdir ; where the somedestinationdir is the target directory that must already exist. For sefaty, findem assumes that somedestinationdir is a directory that is in the /tmp directory. If the somedestinationdir is anywhere else then use the option -nocheckdest If the source directory and the desnitation directory are the same then cpffl will skip copying to the target directory unless the option -samedirok is used. Example: findem -dir JOJO.ear -pattern getParameter -newpattern OOooooooooo -between 19930000,20231231 -idir '.*classes/com.*' findem -dir JOJO.ear -pattern getParameter -newpattern OOooooooooo -between 19930000,20231231 -idir '.*classes.*' -xdir '.*classes/com.*' findem -dir JOJO.ear -pattern getParameter -newpattern OOooooooooo -between 19930000,20231231 findem -dir JOJO.ear -pattern getParameter -newpattern OOooooooooo -between 20210000,20231231 findem -dir JOJO.ear -between 19930000,20231231 findem -dir JOJO.ear -between 20210000,20231231 If the source directory and the desnitation directory are the same then mvffl will skip moving the files to the target directory. If the source directory and the desnitation directory are the same then cpffl will skip copying to the target directory unless the option -samedirok is used. -settransform followed by an identifier to a replacement subroutime ----------------------------------------------------------------------- When -settransform is used along -exec cpffl it can do transformation of name patterns of the file names and directory stems names. The transformation can be coded in a Perl package file that is loaded by findem. findem will read the package file that is set in the environment variable FINDEM_TRANSFORMS, for example: export FINDEM_TRANSFORMS=/tools/FindemTrans.pm -relative and the special meaning of the source directory ending slash: ----------------------------------------------------------------------- All files found in the source directory are copied including their originating source directory path. However, the -relative option can exclude the originating source directory path from the target name of the destined files. In addition, when appending the slash / to the source directory this will cause the exclusion of the stem from the target destination. The option -relative is used along -exec cpffl so that the copied files from the source directory exclude the name of the originating directory. In addition, when the source originating directory end with a / (slash) then the source files copied will not include the last stem of the source directory; otherwise, when a final / (slash) is not included, then the last stem of the originating name is also included when files are copied to the target directory. The option -relative can also be used along -exec mvffl so that the moved files from the source directory exclude the name of the originating directory. The behavior of the / (slash) has the same effect as it is explained with cpffl. -exec [cpffl|mvffl] {} DESTINATIONDIR ; ----------------------------------------------------------------------- Once the files are found, these files can be copied or moved to a destibation directory. Use -exec followed by either cpffl or mvffl to copy or to move the found files. The -exec has a special meaning, when it is followed by cpffl or mvffl then it causes to copy the files or to move them to a destination directory (that must exists). What follows -exec can be either words: "cpffl" or "mvffl", as the findem program will mimic the process of copying or moving the files (and this will look for the operator as if the program is calling an external processing command) but it will not execute any external command. Both cpffl and mvffl are internally coded in the findem program. The following paragraph explains how you can invoke an external command on the found files. export FINDEM_EXECOK=1 to execute an external command ----------------------------------------------------------------------- -exec followed by whatever follows it up to ; is captured as a string and the {} is replaced with each file found by findem. The captured string is treated as follows: - if it starts with either one "cpffl {}" or "mvffl {}" then it is handled by the findem internally and no external script is executed, - if it is anything else like words and options, then the {} is replaced with the found file and thecommand is executed externally via the current running shell where the program started. By default -exec will only recognize cpffl or mvffl as executable command, but you can allow it to take anything else by setting the environment variable to FINDEM_EXECOK to 1 as follow: export FINDEM_EXECOK=1 Here is an example using the external "cp" command findem -dir ../../tmp/JUNKFILES/wasdg.ear4/ -pathrgx .*/com/tcnd/wasdg/.*java -exec cp -p -i {} Zaa ; -settransform 'replacerex (Login)(Screen) ' -setdirtransform "replacestem com/tcnd COM/IBM" -transcond dtf Also other options like -between and -pattern can be used, eg. -between 19930000,20231231 -pattern Login NOTE: the slash before the semicolon ; is mandatory so that it is passed to the findem program otherwise it will be interpreted by the shell as a command separator. -dir followed by the source directory ---------------------------------------------------------------------- The source directory following -dir can be specified without an ending slash or with an ending slash. Adding a terminating slash / to the source directory causes to exclude the subdirectory of the source (from whatever precede the slash /) when copying or moving the files, hence excluding the subdirectory of the source. Omitting the slash / causes to include the subdirectory of the source when copying or moving the files. These two commands are different: findem -dir JOJO.ear -pattern getParameter -newpattern GETparameter -idir '.*classes.*' -xdir '.*classes/com.*' -pati -commit -exec cpffl {} Zoo ; findem -dir JOJO.ear/ -pattern getParameter -newpattern GETparameter -idir '.*classes.*' -xdir '.*classes/com.*' -pati -commit -exec cpffl {} Zoo ; replacing patterns: ---------------------------------------------------------------------- -pattern and -newpattern options are used to find specific patterns and replacing them with a new patter. Finding and replacing patterns is displayable without being commited unless the option -commit is used. In addition, use -pati to make the program prompt you before changing the file. The following three commands # findem -dir Zaa -pattern getPa -newpattern JJJJ -pati -commit -pathrgx .*/.*java since findem exec the command before searching for pattern, the following will not execute the replacement because "cp" will fail to copy the same file to itself # findem -dir Zaa -pattern getPa -newpattern JJJJ -pati -commit -pathrgx .*/.*java -exec cp -p {} Zaa ; # findem -dir Zaa/ -pattern getPa -newpattern JJJJ -pati -commit -pathrgx .*/.*java -exec cpffl {} Zaa ; -backup option to back up replaced files: ---------------------------------------------------------------------- The following command will replace the pattern .. and backup the file Since the backed up file contains the old pattern then repeating the same command will cause a new backup (with the original pattern) and replacing within .bk file again Use -xnmfl '.*.bk' to exclude from being backed up: findem -dir Zaa/ -pattern getPA -newpattern JJJJ -pati -commit -pathrgx .*/.*java -exec cpffl {} Zaa ; -nocheckdest -backup '.bk' -xnmfl .*.bk AVOID cyclical replacement if files are backed up: ---------------------------------------------------------------------- findem -dir WASDG2 -sortby mtime -between 2002-08-15_08:44:06,2002-08-20_06:45:33 -pattern getParam -newpattern JJJJ -commit -pati -backup ~datetime.bk To avoid just findem -dir WASDG2 -sortby mtime -between 2002-08-15_08:44:06,2002-08-20_06:45:33 -pattern getParam -newpattern JJJJ -commit -pati -backup ~datetime.bk -xnmfl .*.bk See command "findreplace" findreplace -dir Zaa -pattern getPA -newpattern JJJJ -commit -pati -xnmfl '.*.bk' Bye FileManagement::FileFinder!