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
mkdir mirusnet UNIX for Advanced & Expert Users 3 02-23-2008 05:00 AM
mkdir big123456 Shell Programming and Scripting 2 07-22-2006 07:23 AM
calling mkdir from PHP gmclean2006 UNIX for Dummies Questions & Answers 4 06-15-2006 06:23 PM
Can't mkdir in /home leond UNIX for Dummies Questions & Answers 5 03-05-2003 07:04 AM
mkdir limitations flignar UNIX for Dummies Questions & Answers 12 08-30-2002 11:30 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-05-2007
Registered User
 

Join Date: Mar 2007
Posts: 39
cp & mkdir simultaneously

Can I create a new directory and copy files to it in a single command (not by linking 2 commands with a semi colon)? If so how? The only way I can see to do it is to first create the new directory using mkdir THEN copy files to it using the cp command.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-05-2007
Registered User
 

Join Date: Feb 2007
Posts: 10
Actually, I would not use a semicolon anyway ...

maybe you could use "mkdir dirname && cp /path/to/file* dirname/" instead

It is still 2 commands, I don't know how to do it with one (I don't think it is possible)

Why can't you use 2 commands ??

hope this can help
Reply With Quote
  #3 (permalink)  
Old 03-05-2007
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 767
try cp -r

when you use cp -r (the recursive option), directories are created and files are copied into them without keying in two separate commands, if that's what you want
Reply With Quote
  #4 (permalink)  
Old 03-11-2007
Registered User
 

Join Date: Mar 2007
Posts: 39
Say I had a file called
/home/adirectory/text.txt
and I wanted to copy it to a directory that does not yet exist, say
/home/adirectory/newdirectory

prior to executing the command I am looking for, the directory
/home/adirectory
does exist, but
/home/adirectory/newdirectory
does not exist

In one command I want to create the new directory
/home/adirectory/newdirectory
AND copy the file
/home/adirectory/text.txt
to it

I can do it thus
$ mkdir newdirectory;cp test.txt ./newdirectory
by chaining two commands, but I was wondering if it can be done using a single command.
Reply With Quote
  #5 (permalink)  
Old 03-11-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Try cpio, e.g....
Code:
echo test.txt | cpio -pd ./newdirectory
man cpio for details.
Reply With Quote
  #6 (permalink)  
Old 03-13-2007
Registered User
 

Join Date: Mar 2007
Posts: 39
Thanks, that will work. I thought that if you specified a destination directory that did not exist when using the cp command, that the cp command would create it. I was wrong.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
cpio

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:34 AM.


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

Content Relevant URLs by vBSEO 3.2.0