1

So the following command copies from /source/allsubdirectroies (/usr/hdp/2.6.3.0-235) to a /target (/tmp/jar263) folder:

find /usr/hdp/2.6.3.0-235 -type f -name "*.jar" -exec cp {} /tmp/jar263 \;

The problem for me is that in the source directory there are files with symbolic link, i.e.: hadoop-nfs.jar -> hadoop-nfs-2.7.3.2.6.3.0-235.jar

So when I check my /tmp/jar263 folder I see the following file:

hadoop-nfs-2.7.3.2.6.3.0-235.jar

However what I want is the "hadoop-nfs.jar" name.

Any way to get the link name not the original name of the file?

There are many links in the usr/hdp/2.6.3.0-235/ folder/subfolder structure.

  • 1
    man find and check the options for -type – roaima Apr 3 '18 at 14:36
1

From man find, ubuntu manpages version:

-L Follow symbolic links. When find examines or prints information about files, the information used shall be taken from the properties of the file to which the link points, not from the link itself (unless it is a broken symbolic link or find is unable to examine the file to which the link points). Use of this option implies -noleaf. If you later use the -P option, -noleaf will still be in effect. If -L is in effect and find discovers a symbolic link to a subdirectory during its search, the subdirectory pointed to by the symbolic link will be searched.

When the -L option is in effect, the -type predicate will always match against the type of the file that a symbolic link points to rather than the link itself (unless the symbolic link is broken). Using -L causes the -lname and -ilname predicates always to return false.

So find -L /usr/hdp/2.6.3.0-235 -type f -name "*.jar" -exec cp {} /tmp/jar263 \; should do the trick. Make sure to read the options under -type, as roaima suggested, if you run into any strange behavior (find may behave slightly differently on, e.g. OSX).

  • There's also the possibility of using -L with cp instead of with find, depending on what name one wants to have at the target. – Kusalananda Apr 3 '18 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.