0

I was reading this question but it hasn't answer, and the mine its different.

Linux: Trying to find files from a list recursively and copy them somewhere else

I'm trying to find the real files from symlinks of these files!.

$ sudo find /usr/lib64 -iname "libSM.so" -o -iname "libX11.so" -o -iname "libXinerama.so" -o -iname "libXxf86vm.so" -o -iname "libatk-1.0.so" -o -iname "libc.so.6" -o -iname "libcairo.so" -o -iname "libdl.so" -o -iname "libgcc_s.so.1" -o -iname "libgdk-x11-2.0.so.0" -o -iname "libgdk_pixbuf-2.0.so" -o -iname "libglib-2.0.so" -o -iname "libgmodule-2.0.so" -o -iname "libgobject-2.0.so" -o -iname "libgthread-2.0.so" -o -iname "libgtk-x11-2.0.so.0" -o -iname "libjpeg.so" -o -iname "libm.so" -o -iname "libpango-1.0.so" -o -iname "libpangocairo-1.0.so" -o -iname "libpng.so" -o -iname "libpthread.so.0 " -o -iname "librt.so" -o -iname "libstdc++.so.6" -o -iname "libtiff.so.[3,5]" -o -iname "libz.so"

For this question I was trying so shorter example:

$ sudo find -L /usr/lib64 -iname "libSM.so" -o -iname "libz.so" 
     -o -iname "libtiff.so.[3,5]" -exec cp {} /usr/copy \;

The folder empty.

$ ls -al /usr/copy/
total 0
drwxr-xr-x.  2 root root   6 Feb 15 22:39 .
drwxr-xr-x. 14 root root 167 Feb 15 21:33 ..

The files to be copied

$ sudo find /usr/lib64 -iname "libSM.so" -o -iname "libz.so" -o -iname "libtiff.so.[3,5]"
/usr/lib64/libz.so
/usr/lib64/libSM.so
/usr/lib64/libtiff.so.5
/usr/lib64/libtiff.so.3

The command!

$ sudo find /usr/lib64 -iname "libSM.so" -o -iname "libz.so" -o -iname "libtiff.so.[3,5]" -exec cp -L {} /usr/copy \;

The result!

$ ls -al /usr/copy/
total 884
drwxr-xr-x.  2 root root     46 Feb 15 22:39 .
drwxr-xr-x. 14 root root    167 Feb 15 21:33 ..
-rwxr-xr-x.  1 root root 419456 Feb 15 22:39 libtiff.so.3
-rwxr-xr-x.  1 root root 479440 Feb 15 22:39 libtiff.so.5
$ 

Only it's executing the copy for the last file found!!!

How do that?

1 Answers1

2

man find on my Kubuntu states:

Please note that -a when specified implicitly (for example by two tests appearing without an explicit operator between them) or explicitly has higher precedence than -o. This means that find . -name afile -o -name bfile -print will never print afile.

You need (escaped) parentheses:

sudo find /usr/lib64 \( -iname "libSM.so" -o -iname "libz.so" -o -iname "libtiff.so.[3,5]" \) -exec cp -L {} /usr/copy \;