The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 02:26 PM
find files and copy into a directory balireddy_77 Shell Programming and Scripting 4 04-27-2007 03:38 AM
Copy files from CDROM to DOS Directory greystoke UNIX for Dummies Questions & Answers 3 01-24-2007 01:12 PM
Copy files from one directory to another HAA Shell Programming and Scripting 1 07-06-2006 02:47 AM
Copy files from one directory to another hd2006 Shell Programming and Scripting 0 06-07-2006 02:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2003
zip_zip zip_zip is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 4
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
  #2 (permalink)  
Old 09-14-2003
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
You don't need a while loop. Something like

cp -R dir_a/ dir_b

should work.
  #3 (permalink)  
Old 09-14-2003
norsk hedensk norsk hedensk is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
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
zip_zip zip_zip is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 4
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
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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
pressy pressy is offline Forum Staff  
solaris cultist
  
 

Join Date: Aug 2003
Location: Vienna / Austria (Europe) [EARTH]
Posts: 726
...............

searching for that?:

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

greetings Preßy
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0