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
  • 1
    man find and check the options for -type Commented Apr 3, 2018 at 14:36

1 Answer 1

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).

1
  • 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. Commented Apr 3, 2018 at 15:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.