Find -name with multiple file names using shell variable

I have a command findthat finds files with a name that matches several patterns mentioned in the parameter-name

find -L . \( -name "SystemOut*.log" -o -name "*.out" -o -name "*.log" -o -name "javacore*.*" \)

This finds the necessary files on the command line. I am looking to use this command in a shell script and join it with a command tarto create a tar of all log files. So, in the script, I do the following:

LIST="-name \"SystemOut*.log\" -o -name \"*.out\" -o -name \"*.log\" -o -name \"javacore*.*\" "
find -L . \( ${LIST} \)

This does not print the files I am looking for.

First, why does this script not work as a command? As soon as this happens, can I turn it on using cpioor similarly create it tarin one shot?

+3
source share
5 answers

, find * . ( bash ):

LIST=( -name \*.tar.gz )
find . "${LIST[@]}"

:

LIST=( -name SystemOut\*.log -o -name \*.out -o -name \*.log -o -name javacore\*.\* )
find -L . \( "${LIST[@]}" \)
+6
eval "find -L . \( ${LIST} \)"
+1

, , :

# List of file patterns
Pat=( "SystemOut*.log"
"*.out"
"*.log"
"javacore*.*" )

# Loop through each file pattern and build a 'find' string
find $startdir \( -name $(printf -- $'\'%s\'' "${Pat[0]}") $(printf -- $'-o -name \'%s\' ' "${Pat[@]:1}") \)

, , ( , ).

find -exec :

find -L . \( .. \) -exec tar -Af archive.tar {} \;
+1

eval xargs,

eval "find -L . \( $LIST \) " | xargs tar cf 1.tar
+1
LIST="-name SystemOut*.log -o -name *.out -o -name *.log -o -name javacore*.*"

, . ,

LIST="-name \"SystemOut*.log\""

, find .

0

All Articles