Help with cp command to copy library files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with cp command to copy library files
# 1  
Old 06-11-2010
Help with cp command to copy library files

Hi,

I have to copy *.so shared objects filtering out the files having *.debug extension and if symbolic link is present copy only the links excluding the source (i.e) if it is a symbolic link then it should not de-reference the source file. For this I used the "-P" option, but I am not sure, whether it is correct.

Consider the files as:
Code:
$ ls libRuntime*.so*

libRuntimeCore.so
libRuntimeCore.so.1
libRuntimeCore.so.1.4.0
libRuntimeCore.so.1.4.debug  # have to exclude this file while copying
libRuntimeCore.so -> libRuntimeCore.so.1.0.0  # copy only the link

I came up with a command
Code:
find . -type f -name "lib*.so.*" | grep -v debug | xargs -I '{}' cp -P '{}' .

Is there any other command simpler than this to accomplish my task? Also please help me to understand to how to use regular expression in cp command.
# 2  
Old 06-11-2010
If I were you I would to do like this :

Firstly copy normal files exclude debug so list all file name matched "lib*.so.*" pattern and let be max line count is one and copy these to mysourcedir..
Code:
find . -type f -name "lib*.so.*" ! -name "*debug" -print0 | xargs -0 -L 1 cp -t /mysourcedir

Secondly the controlly remove the incorrect symbolic links file (with prompt)
Code:
find -L -name "lib*.so*" -type l -print0 | xargs -0 -L 1 rm -i

And latest copy correct symbolic links file
Code:
find -H -name "lib*.so*" -type l -print0 | xargs -0 -L 1 cp -t /mysourcedir  -P


Regards
ygemici
# 3  
Old 06-11-2010
Thank you for the help.

But can you tell me, suppose if the library *.so files are residing in the sub-directories as well and if I want to descend into these directories and copy all the *.so files into another directory (without copying the directory itself), how do I do it using cp? Because cp -R or cp -r does not help. I guess I could use "find" command in this scenario. Am I right?
# 4  
Old 06-11-2010
this find itself should find and give files from sub directories also.
# 5  
Old 06-12-2010
Quote:
Originally Posted by royalibrahim
Thank you for the help.

But can you tell me, suppose if the library *.so files are residing in the sub-directories as well and if I want to descend into these directories and copy all the *.so files into another directory (without copying the directory itself), how do I do it using cp? Because cp -R or cp -r does not help. I guess I could use "find" command in this scenario. Am I right?
find command default works in depth as already say thegeek..so recursive copy is unnecessary in this Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copy files from one drive to another, keeping most recently modified files

Hi all, I am a bit of a beginner with shell scripting.. What I want to do is merge two drives, for example moving all data from X to Y. If a file in X doesn't exist in Y, it will be moved there. If a file in X also exists in Y, the most recently modified file will be moved to (or kept) in... (5 Replies)
Discussion started by: apocolapse
5 Replies

2. Shell Programming and Scripting

UNIX command to copy files from Windows to UNIX box

Hi Folks, I have a file name abc.xml in my windows machine at the location c:\ytr\abc.xml which I want to place at the unix box machine inside cde directory.. at the following location that is /opt/app/cde/ now the credentials of unix box are abc345 -->(dummyid) ftyiu88--->(dummy passwd) ... (4 Replies)
Discussion started by: punpun66
4 Replies

3. Shell Programming and Scripting

command to copy original files from links in HP-UX

I have folder ABC and files in ABC are links. I want to create the same ABC folder in different path and copy the actual files from source ABC dir. Can anyone provide command for this? Thanks in advance. (2 Replies)
Discussion started by: venkatababu
2 Replies

4. Shell Programming and Scripting

Any command to delete files from source dir after SFTP copy

Hi, I am currently using SFTP 'put' command to copy all files to remote server and then delete the copied files from source directory. Can anyone help me with a single command to copy and remove files in one go? Thanks and Regards, Chetan Vyas (5 Replies)
Discussion started by: chetancrsp18
5 Replies

5. Solaris

How to safely copy full filesystems with large files (10Gb files)

Hello everyone. Need some help copying a filesystem. The situation is this: I have an oracle DB mounted on /u01 and need to copy it to /u02. /u01 is 500 Gb and /u02 is 300 Gb. The size used on /u01 is 187 Gb. This is running on solaris 9 and both filesystems are UFS. I have tried to do it using:... (14 Replies)
Discussion started by: dragonov7
14 Replies

6. UNIX for Dummies Questions & Answers

Copy a command string from the command line

How can we copy a command string from a previous command line and paste it into the cursor position on the current command line? I know that ^c will not work as the shell will interpret as an interrupt signal. Thanks, (1 Reply)
Discussion started by: Pouchie1
1 Replies

7. UNIX for Dummies Questions & Answers

Unix command to copy files selectively

Hi, I'm new to Unix and am trying to write a copy command for the following scenario: Copy all .tif files from the src directory to dest directory but exclude the ones under archive directory. In other words, I'm trying to write the unix cp equivalent of the following ant target: <target... (3 Replies)
Discussion started by: anandkumarj
3 Replies

8. UNIX for Advanced & Expert Users

command to copy files with original ownership

Hi, I need a command that to copy files from others and to keep files' ownership. Example: I copy file.txt from users "abc" to my local, and file.txt is own by user "abc" in local. Thanks in advance! (3 Replies)
Discussion started by: need_help
3 Replies

9. UNIX for Dummies Questions & Answers

using tar command to copy files?

hi, can i use the tar command to copy an entire directory and its content in another folder? What is the proper syntax? thx (2 Replies)
Discussion started by: tomapam
2 Replies
Login or Register to Ask a Question