find multiple files, and copy real files from symlink

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?

chepe lucho

Posted 2018-02-16T03:55:06.883

Reputation: 157

Possible duplicate of Strange "find" behavior in linux

– Kamil Maciorowski – 2018-02-16T06:22:18.223

@KamilMaciorowski It's bad title for a question, how I need to looking for my question? 'something strange is happening'? The question must to be more descriptive about the goal, the fails and results, and the other post haven't these. – chepe lucho – 2018-02-16T10:45:30.117

What's your point? It's hard to name the issue unless you already know what the issue is. Note your current title is not perfect either, symlinks are completely irrelevant here. Feel free to improve any title. Your attitude seems somewhat defensive but my intention was to help you and future users to reach good answers and understand the subject. If I thought you hadn't researched enough then I would have voted your question down. – Kamil Maciorowski – 2018-02-16T11:18:18.473

I can't change title of another person, for me this action is invasive, maybe inform the change the question to post owner. The point is, how to find something related in other post that hasn't clue? (In real World) do you not go to find a book for cooking in car shop. – chepe lucho – 2018-02-17T03:17:13.927

You can't compare the skills to find something where you have 11K when I have only 120. These site it's for expert people and newbie (I guess that)... I'm (riéndome) smiling about these comments. – chepe lucho – 2018-02-17T03:22:53.367

Even anonymous users can propose an edit to a post. The edit will be reviewed by users with enough reputation, it will be accepted or rejected. If you propose a truly better title and your edit summary is "more descriptive title, now easier to find", then it will probably be accepted by the community. But in the first place you can change the title of your question (without even being reviewed because you own the question) to something like "Why does find command skip expected results when -o is used?". Anyone who finds your question may follow my link, so the other title wouldn't matter. – Kamil Maciorowski – 2018-02-17T09:49:00.553

You seem to treat this personally but I'm not comparing our skills. Pointing to a duplicate doesn't necessarily mean you have failed your research. It means "the answer is already there". Searching for the other question wasn't easy for me either. I tried, failed, wrote my answer, had this nagging feeling the other question is there, searched harder. If I have found it at my first try, I wouldn't bother writing my answer. – Kamil Maciorowski – 2018-02-17T09:49:05.943

I will learn about superuser here... Thank you. @KamilMaciorowski – chepe lucho – 2018-02-17T14:13:05.067

I have just edited the title of the other question. This should help future users. Thank you for your input. – Kamil Maciorowski – 2018-02-17T19:56:23.600

Answers

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 \;

Kamil Maciorowski

Posted 2018-02-16T03:55:06.883

Reputation: 38 429