I need to find files that match this pattern:
find root_folder/*/match_string/*.ext
"*" means any levels of folders or files. So it means any file with an extention "ext" under root_folder or its sub folder and whose full path contains a folder called "match_string", for example:
root_folder/f1/f2/match_string/f3/f4/1.ext
root_folder/f1/f2/match_string/2.ext
But the above command doesn't work. find -name also doesn't work.
And I need to output the result list of matched files to a file for later import into zip command. It seems not to be straightforward to use ">" if cascaded commands are used.
You can use
The command will search for all folders named
match_string
, then search for all files which names end with.ext
in them and their subfolders and list all found files with their absolute pathes. The list will be stored in~/file_list
.If you use
the files will be listed with relative pathes to the current directory, but the name of the current directory (which is
path/to/root_folder
) will not be displayed, instead./
is displayed.Save filelist to file with "starting-point" removed (man find).
zip-archive-file.list
Archive from file (man zip).
Pipe find result to zip.