The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Copy files from a directory by ftp hippa77 UNIX for Dummies Questions & Answers 3 10-06-2007 11:26 AM
find files and copy into a directory balireddy_77 Shell Programming and Scripting 4 04-27-2007 12:38 AM
Copy files from CDROM to DOS Directory greystoke UNIX for Dummies Questions & Answers 3 01-24-2007 09:12 AM
Copy files from one directory to another HAA Shell Programming and Scripting 1 07-05-2006 11:47 PM
Copy files from one directory to another hd2006 Shell Programming and Scripting 0 06-07-2006 11:29 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-14-2003
Registered User
 

Join Date: Sep 2003
Posts: 4
Stumble this Post!
Unhappy copy files from one directory to another directory

how do i copy files from one directory to another directory using a while loop? (like jus say i had a.doc and b.doc in one directory and i want to copy it into another)

i used a if statement but doesn't work
Forum Sponsor
  #2 (permalink)  
Old 09-14-2003
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,432
Stumble this Post!
You don't need a while loop. Something like

cp -R dir_a/ dir_b

should work.
  #3 (permalink)  
Old 09-14-2003
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
Stumble this Post!
cbkihong's example will work to copy entire directorys over. that seems like what you were asking. the -r flag for the cp command tells cp to copy directories recursivley.

coping individual files works the same way, just without the -r flag. eg:
cp file1 somewhere/file1
  #4 (permalink)  
Old 09-14-2003
Registered User
 

Join Date: Sep 2003
Posts: 4
Stumble this Post!
yeh i did that.....but it keeps having a error that says "too many arguments"

for my if statement i got

if [ -f $HOME/$directory/*.src ]

is there something wrong with that if multiple files are to be copied?
  #5 (permalink)  
Old 09-14-2003
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,432
Stumble this Post!
The -f test doesn't accept multiple arguments. *.src is expanded by the shell to all matching filenames, so there are multiple arguments. As being said, from your description you don't even need an "if" to do it. It's as simple as

cp *.src dir_b/
  #6 (permalink)  
Old 09-14-2003
pressy's Avatar
solaris cultist
 

Join Date: Aug 2003
Location: Vienna / Austria (Europe) [EARTH]
Posts: 712
Stumble this Post!
...............

searching for that?:

for x in $HOME/$directory/*.src
do
cp $x $NEWDIR
done

greetings Preßy
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0