Unix copy command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix copy command
# 1  
Old 03-23-2009
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 /isdev/data//history to /isdev/data/history1
the command is not failing( history1 folder doesn't appear in unix server) instead the command is creating a file called history1 in /isdev/data/ folder.

This there anyway to alter the command to fail if the path is invalid.
# 2  
Old 03-23-2009
Use

Code:
[ -z "$dest_dir" ]

which would check the existence of the directory.

w020637
# 3  
Old 03-24-2009
[leiyang@localhost drivers]$ find . -name "*.ko" -exec cp -R {} "/home/leilyang/12"
find: missing argument to `-exec'

why?
# 4  
Old 03-24-2009
Code:
find . -name "*.ko" -exec cp -R '{}' "/home/leilyang/12" \;

# 5  
Old 03-28-2009
the {} means what, where can I get its usage?
# 6  
Old 03-28-2009
Quote:
Originally Posted by yanglei_fage
the {} means what, where can I get its usage?
Check the man page of find.

Regards
# 7  
Old 03-28-2009
Unix is not a MSDOS. Filename *.* does not have the same meaning in unix as MSDOS and can cause you to miss files. In your case it will miss directories unless the directory name contains a full stop character.
The command sequence posted may be nearly giving the right results by accident. it is however not correct.

After re-reading your post several times I am not 100% clear what you are trying to do.

Are there any subdirectories under /dev/data ?
Are there any files directly under /dev/data ?
If there are subdirectories, do you you want to replicate that tree under /isdev/data/history ?
If so you should really be looking at unix "cpio -p" not "cp -R". This will also address your problem of "cp -R" creating the directory tree one level down.

For example (but do check your local "man cpio").

Code:
cd /dev/data
TARGET="/isdev/data/history"
if [ -d "${TARGET}" ]
then
         find . -print|cpio -pdum "${TARGET}"
else
         echo "Directory missing: ${TARGET}"
fi


Last edited by methyl; 03-28-2009 at 05:05 PM.. Reason: Typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copy command

Hi , I am trying to take a backup of file before overwriting it with cp command, I am using the command cp -b. -rw-rw-r-- 1 autoengine murex 0 Jan 22 07:08 a -rw-rw-r-- 1 autoengine murex 0 Jan 22 07:08 b cp -b a b -rw-rw-r-- 1 autoengine murex 0 Jan 22 07:08 a -rw-rw-r-- 1... (1 Reply)
Discussion started by: Raj999
1 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

Help with copy command

Hello, I have a directory in which I have files as follows CRDT.csv CRDT.csv.1 CRDT.csv.2 .... CRDT.csv.n I would like to copy it over to another directory as crdt_lon.csv crdt_lon.csv.1 crdt_lon.csv.2 .... crdt_lon.csv.n I am looking for a one line command but I am... (5 Replies)
Discussion started by: srattani
5 Replies

4. Shell Programming and Scripting

Help with using grep command with copy command

Hi, im taking an entry Unix class, and as part of my lab assignment I have to copy all files in the /home/david/lab3 directory that have the file extension .save to your lab3/temp directory. I'm having trouble getting the grep to do anything worth while I've been trying to do: cp... (6 Replies)
Discussion started by: Critical jeff
6 Replies

5. UNIX for Dummies Questions & Answers

UUCP (Unix to unix copy) not working

I have a problem using uucp. I have Ubuntu 10.4 and i installed the 'uucp' package. In my LAN there are a desktop pc, a laptop, and the router the desktop local ip is: 192.168.0.2 the laptop local ip is: 192.168.0.4 Here are the /etc/uucp/config and the /etc/uucp/sys i used on the desktop.... (4 Replies)
Discussion started by: mghis
4 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. Linux

copy command

sir can any body tell me how i can copy files like copy c:\abc\pqr\mr.txt c:\windows\my documents\this.txt i need command in linux like this really i am a new in linux that is why simple questions alson can any body explain me how i get current directory tree or path in windows... (2 Replies)
Discussion started by: sadiquep
2 Replies

9. Shell Programming and Scripting

copy command

what command would i wrote to copy files from $folder1 to $folder2 ???? (1 Reply)
Discussion started by: perleo
1 Replies

10. UNIX for Dummies Questions & Answers

Where can i get a copy of Unix?

where can i get a free copy of unix? any kind... plz send to ::email removed:: (5 Replies)
Discussion started by: gregtampa
5 Replies
Login or Register to Ask a Question