cp work as xcopy.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp work as xcopy.
# 1  
Old 12-15-2006
cp problem should works like xcopy.

Actually i want to copy some file locations to another. so if directory not exist it should create that.
i used cp -R/r but it copies only one directory. it doesnt make directory inside directory..
so i want this should create them automatically.

One more thing if file already exist there then it should not prompt to overwrite...
I just tried cp -f but its not working. means file still prompting for overwrite.
i want it just overwrite not ask me...

Please suggest me right one.

Thanks

Last edited by ajayyadavmca; 12-15-2006 at 02:57 AM..
# 2  
Old 12-15-2006
Don't know where you got that. From the man page of cp:
Quote:
one or more directories speci-
fied by source_dir are copied to the directory specified by
target. Either -r or -R must be specified. For each
source_dir, cp copies all files and subdirectories.
Code:
# ls -l /tmp/1/2/3/4/5/6
total 0
-rw-r--r--   1 root     other          0 Dec 15 13:39 6.1
-rw-r--r--   1 root     other          0 Dec 15 13:39 6.2
-rw-r--r--   1 root     other          0 Dec 15 13:39 6.3
-rw-r--r--   1 root     other          0 Dec 15 13:39 6.4
# ls -l /tmp/test
total 0
# cp -r 1 test/
# cd test/1/2/3/4/5/6
# ls -l
total 0
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.1
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.2
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.3
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.4
# cd /tmp
# ls -l /tmp/test
total 16
drwxr-xr-x   3 root     other        175 Dec 15 13:40 1
# ls -l /tmp/test/1/2/3/4/5/6
total 0
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.1
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.2
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.3
-rw-r--r--   1 root     other          0 Dec 15 13:40 6.4

cp with the -R/-r option works just like xcopy does (if I remember what xcopy works like, its been too long since I used that command).
# 3  
Old 12-15-2006
sorry i m not clear that time..

yes right it works..
But question was if dir not exist it should create.

u explained Ex: cp -r 1 test/ ---- yes it work now

but if command is : cp -r 1 test/xxx/xxxx ----will not works becoz xxx/xxxx not exist

so i want this should create them automatically.

One more thing if file already exist there then it should not prompt to overwrite...
I just tried cp -f but its not working. means file still prompting for overwrite.
i want it just overwrite not ask me...

Now i think u got my problem...

Last edited by ajayyadavmca; 12-15-2006 at 02:37 AM..
# 4  
Old 12-15-2006
cp like xcopy..

hi..

i want to copy all my one directory structure to another place ...

i used cp -R/r it works like...

Ex: have structure ab>ty>dl>d>kt
and having file in each... now

i use cp -r ty /root/abc/am ---not works becoz abc/am not exist
so i want they should create whole structure if dir not exist..

now 1 more thing is.
when i copy files they prompt if already exist.
i used cp -f but they still prompting me..

Plz help..
# 5  
Old 12-15-2006
Ok, the first one cannot be done. You have to have the destination directory in place before cp can copy files to that directory.
The second thing is that cp is asking for confirmation for each file. This is not default behaviour. Check if cp is aliased to 'cp -i'. If it is, unalias it and rerun the command.
# 6  
Old 12-15-2006
ajayyadavmca, do not start multiple threads for the same topic. This is against the rules. I have merged the threads.
# 7  
Old 12-15-2006
Sorry n Thanks !!

I didnt get first one,s but i got second one...

i just used: cp -r --reply=yes/y it worked.

Sorry for starting new thread. But reason was because my wuestion was replied by some one. So no body giving me answer so i did it.

Anyway thank for responding. But plz can u do something so now some one see my topic again n i got answer of my first ques.

Thanks for ur gr8 help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies

2. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

3. IP Networking

NIC will not work, but it did work.

I have a client machine that was built and loaded with SCO UNIX 2.1.3, (yes it is old). The machine worked fine on the closed network that I tested on in my shop. I then had to change it to the network that it would be connected to. Below is the host file, router and subnet mask file that I usually... (0 Replies)
Discussion started by: NC user
0 Replies

4. Shell Programming and Scripting

ls -d does not work

Hi falks, I need to dispaly a list of only directories . As it written in the manual ,the command to do it is 'ls -d'. When i issue 'ls -d' i'm getting: tornado.orca.ent:DB10g :/home/oracle/Create_Database > ls -d . Is anyone have any idea why id does not display directories ,or maybe... (11 Replies)
Discussion started by: nir_s
11 Replies

5. Linux

Come and work for me! (UK)

********nothing too see here!!!****** (2 Replies)
Discussion started by: TonyChapman
2 Replies

6. Linux

How does it work?

Can anyone explain how Graphic LCD (CSTN / STN) work in Unix... From Graphic file thro driver code to display....? Thanks (1 Reply)
Discussion started by: nat123
1 Replies

7. UNIX for Dummies Questions & Answers

cant get this to work

whoami | grep < $1 | echo $1 trying to write a script that finds out who the user is and then takes occurences of that username from a file that is passed as an argument and then displays it (6 Replies)
Discussion started by: iago
6 Replies

8. UNIX for Advanced & Expert Users

how does this work....

1|foo|bar 2|usa|ll 3|usa|vg 4|usa|vg 5|bar|vg 6|usa|vg 7|usa|ll 8|uk|nn 9|foo|manu|bar 10|uk|bb 11|foo|mm 12|kuwait|jkj 13|kuwait|mm 14|dubai|hh awk '/foo/,/bar/' test_file1----command run at the prompt output should have been the first 3 lines...... 1|foo|bar (1 Reply)
Discussion started by: bishweshwar
1 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

copy only newer files? (xcopy equivalent)

Howdy folks. I have a problem - I'm sure the answer is very simple, but I can't work it out. I want to create a UNIX shell script that does what I've been doing in DOS batch files for years - that is, backing up files. By which I mean copying files from a source directory to a target... (4 Replies)
Discussion started by: Chomps
4 Replies
Login or Register to Ask a Question