copy files from one directory to another directory | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

copy files from one directory to another directory

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-14-2003
zip_zip zip_zip is offline
Registered User
 
Join Date: Sep 2003
Last Activity: 4 October 2003, 8:11 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Data 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
Sponsored Links
    #2  
Old 09-14-2003
cbkihong cbkihong is offline Forum Advisor  
Advisor
 
Join Date: Sep 2002
Last Activity: 4 May 2014, 6:22 AM EDT
Location: Hong Kong, China
Posts: 1,622
Thanks: 0
Thanked 9 Times in 8 Posts
You don't need a while loop. Something like

cp -R dir_a/ dir_b

should work.
Sponsored Links
    #3  
Old 09-14-2003
norsk hedensk norsk hedensk is offline Forum Advisor  
Registered User
 
Join Date: Jul 2002
Last Activity: 26 May 2006, 8:38 PM EDT
Location: new york
Posts: 1,025
Thanks: 0
Thanked 1 Time in 1 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  
Old 09-14-2003
zip_zip zip_zip is offline
Registered User
 
Join Date: Sep 2003
Last Activity: 4 October 2003, 8:11 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Sponsored Links
    #5  
Old 09-14-2003
cbkihong cbkihong is offline Forum Advisor  
Advisor
 
Join Date: Sep 2002
Last Activity: 4 May 2014, 6:22 AM EDT
Location: Hong Kong, China
Posts: 1,622
Thanks: 0
Thanked 9 Times in 8 Posts
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/
Sponsored Links
    #6  
Old 09-14-2003
pressy's Avatar
pressy pressy is offline Forum Advisor  
solaris cultist
 
Join Date: Aug 2003
Last Activity: 12 March 2014, 9:56 AM EDT
Location: Vienna / Austria (Europe) [EARTH]
Posts: 732
Thanks: 1
Thanked 2 Times in 2 Posts
...............

searching for that?:

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

greetings Pre▀y
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Copy files into another directory ankitha UNIX for Dummies Questions & Answers 5 02-24-2012 11:10 AM
How to copy all files into the same directory dreamer0085 UNIX for Dummies Questions & Answers 3 01-26-2011 12:22 PM
Copy files from a directory by ftp hippa77 UNIX for Dummies Questions & Answers 3 10-06-2007 02:26 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



All times are GMT -4. The time now is 06:10 PM.