Unix command to copy files selectively


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unix command to copy files selectively
# 1  
Old 06-22-2009
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:
Code:
<target name="copy_graphics">
  <copy overwrite="true" todir="${target.dir}">
    <fileset dir="${source.dir}" includes="**/*.tif" excludes="archive/**"/>
  </copy>
</target>

Appreciate any help.

Thanks,
Anand
# 2  
Old 06-22-2009
Should the dest directory have the same structure as the source?

ie.

source/dir1/file1
source/dir2/file2

becomes

dest/dir1/file1
dest/dir2/file2


(before scripting anything it's important to know exactly what the requirements are)
# 3  
Old 06-22-2009
Yes, they need to be the same.

Thanks!
# 4  
Old 06-22-2009
This looked to be quite easy with tar using the -X (--exclude-from) option until the filename (*.tif) came into it! GNU stuff does seem to print some odd messages!

If your source directory has only *.tif files, then I'd create a exclude.list that looks like this:
archive

And then:
Code:
tar cvf - --exclude-from exclude.list . | (cd /MY_NEW_LOCATION; tar xf -)

Otherwise, and I'm too tired to argue with wierd GNU messages...

Code:
NEW_DIR=/MY_NEW_LOCATION
find . -name *.tif -type f | grep -v '/archive/' | while read FILE; do
  mkdir -p $NEW_DIR/$(dirname $FILE)
  cp $FILE $NEW_DIR/$(dirname $FILE)
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX ksh Copy Files Script

I need a UNIX ksh script that counts the number of files in directory, if the files exceed 20 files, then email results. I want the script to run every hour.. I don't have access to cron.. I'm some what new to UNIX. Windows guy all my career.. this is what I have so far.. #!/bin/ksh # count.sh ... (5 Replies)
Discussion started by: PerlHaven2k
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. UNIX for Dummies Questions & Answers

Copy files from windows outlook in to UNIX box.

HI All, I am using a windows RDP machine . from the RDP i am opening a putty session of a unix server.i have outlook installed in the windows RDP machine, and if i get a file inthe outlook mail how can i copy it to a location in the putty unix machine. Please help me!!!! (3 Replies)
Discussion started by: mahesh300182
3 Replies

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

5. Shell Programming and Scripting

Awk or Perl - to selectively merge two files.

I have two files, these have to be selectively merged into two other files. In addition there will require to be a edit to the last field, where the date format is changed. The first file is a csv file with around 300k lines the data is now nearly 20 years old and I have been asked to move this... (7 Replies)
Discussion started by: gull04
7 Replies

6. Shell Programming and Scripting

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,... (4 Replies)
Discussion started by: royalibrahim
4 Replies

7. Shell Programming and Scripting

Unix copy command

Hi, I have the below command running in unix find /dev/data/ -name "*.*" -exec cp -R {} "/isdev/data//history" \; This command will copy the files from /dev/data/ to /isdev/data//history and will not throw even if there is no files in source. But if i modify the path from... (6 Replies)
Discussion started by: redd
6 Replies

8. UNIX for Dummies Questions & Answers

Using cp -r command to selectively omit *.dat files while copying a directory.

Hi all, I want to copy a directory named Ec1 to another directory named Ec2, newly created. But Ec1 has a bunch of *.dat files and many many other kinds of files. Whle creating Ec2, I selectively want to omit the *.dat files since they are huge files of the order of 100 MBs and there are... (5 Replies)
Discussion started by: d_sai_kumar
5 Replies

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

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