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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using cp -r command to selectively omit *.dat files while copying a directory.
# 1  
Old 11-10-2005
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 hundreds of such files which would consume a lot of time.

How can I use the 'cp -r' command to selectively omit the *.dat files in Ec1 and obtain the Ec2 directory without any *.dat files while copying the directory Ec1.

Any suggestions are appreciated.

Thanks,
Sai.
# 2  
Old 11-10-2005
It's easier not to use, cp -r

Code:
cd /the/path/to/EC1
find . depth ! -name "*.dat" | cpio -pdmv /the/path/to/EC2


Last edited by reborg; 11-10-2005 at 01:30 PM.. Reason: more info
# 3  
Old 11-10-2005
Thanks.

You are a genius reborg!

This is what I did, and it worked.
cd Ec1/
find . -depth ! -name "*.dat" | cpio -pdmv ../Ec2

In the first part, I am guessing that you are finding all the files without a *.dat and then you are piping the output into Ec2. Just curious, what do the cpio and -pdmv do?

Thanks a lot,
Sai.
# 4  
Old 11-11-2005
-p pass trough (copy in and out)
-d make dirs
-m preserve modification time
-v verbose

from the man page:
Code:
       ....cpio copies files
       into or out of a cpio or tar archive, which is a  file  that  contains
       other  files  plus  information  about  them, such as their file name,
       owner, timestamps, and access permissions.  The archive can be another
       file  on the disk, a magnetic tape, or a pipe.

# 5  
Old 07-18-2008
MySQL Hi

Hi It was very excellent .... made my job easy.

I have another question ....
Dir1 I have some files *.dat
Dir2 I have script to run .... I would like to pass the all *.dat files to the script in dir2 without path ( only the file names) ... can anyone help me in this

Thanks in advance

Madan
# 6  
Old 07-18-2008
cd /Dir1
cp -p *.dat /Dir2/
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute a Command in a .Dat File and use it in other Files

We have a process where we store the database password in a config file like below from where the password is picked up and used in Database Scripts ID, Password But we now have a Audit Requirement not to have the passwords in Config Files directly. We have a command which could fetch the... (2 Replies)
Discussion started by: infernalhell
2 Replies

2. Shell Programming and Scripting

How to use 'ls' command to list files like *.dat, not *.*.dat?

How to use 'ls' command to list files like *.dat, not *.*.dat (5 Replies)
Discussion started by: pmcginni777
5 Replies

3. Shell Programming and Scripting

Copying files to a directory

Hi, I am newbie to unix scripting, need a help in the doubt i have. It is " when files are copied to a directory using cp command, they are arranged by default according to the file name, is there anyway where the files that are copied be arranged with respect to their size, with using the sort... (5 Replies)
Discussion started by: pundalik
5 Replies

4. Shell Programming and Scripting

Command to list only files omit directories.

Hi All I am writting a script that does a comparison between files in 2 diffectent directories. To do this I need a command that will list out only the files in a give directory and omit any sub dorectories with that directory. But I am unable to find it. Please Help. I tried ls... (5 Replies)
Discussion started by: Veenak15
5 Replies

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

6. Shell Programming and Scripting

Copying files to a directory

Hi I have a few questions. I am trying to copy a file to a directory. I need to copy files that do not end in numbers, for example, into a directory. This is what I tried so far. cp filename directorytowhereIwannacopy but it says it can't copy to a directory. I need to copy many files into one... (2 Replies)
Discussion started by: #moveon
2 Replies

7. Shell Programming and Scripting

Copying files from one directory into another.

Could someone please tell me if there is a command similar to head or tail that can be used on directories. I want to select a given number of files from a directory and copy them into another directory. But I found out I can't use head as it doesn't (or I don't know how yet!) work on directories.... (4 Replies)
Discussion started by: Krush187
4 Replies

8. UNIX for Dummies Questions & Answers

Copying files from one directory to Other

Hi UNIX Gurus, Could please help me out regarding following situation. I am copying some files from one directory to other directotry using following command. cp /var/tmp/*date*.gz /var/tmp/user/ Problem: Once the copy has completed, I need to check whether all the files (including... (3 Replies)
Discussion started by: satishkeshetty
3 Replies

9. Solaris

Copying DAT tapes

I am trying to find a way of copying a system DAT tape onto another DAT tape for security reasons. I have tried searching the net for commands but so far I have been unsuccessful. (2 Replies)
Discussion started by: johnrussell
2 Replies

10. UNIX for Dummies Questions & Answers

Copying DAT tapes

I am looking for a way of making a backup of a system DAT tape onto another DAT tape for security reasons. (0 Replies)
Discussion started by: johnrussell
0 Replies
Login or Register to Ask a Question