cp & mkdir simultaneously


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cp & mkdir simultaneously
# 1  
Old 03-05-2007
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.
# 2  
Old 03-05-2007
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
# 3  
Old 03-06-2007
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
# 4  
Old 03-11-2007
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.
# 5  
Old 03-11-2007
Try cpio, e.g....
Code:
echo test.txt | cpio -pd ./newdirectory

man cpio for details.
# 6  
Old 03-13-2007
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cd then mkdir from script

Importing images from a camera (or two). I sort by date (1901 this month). Currently (failing) if ] then echo "Found Panasonic G9X" #echo "List files on camera" #ls ${pana}/* . chxdir.sh ${photos}/$mn I want to change directory to a fixed base ($photos)/$mn... (10 Replies)
Discussion started by: dpawson
10 Replies

2. UNIX for Beginners Questions & Answers

Mkdir

hi linux expert what is a difference between: mkdir test and mkdir ./test and also if ( -e /test ) then and if ( -e ./test ) then thanks in advance Please use icode or code tags next time for your code and data (1 Reply)
Discussion started by: abdossamad2003a
1 Replies

3. UNIX for Dummies Questions & Answers

How to use mkdir{...} with a variable?

Hi, I used "mkdir job{0001..10}" do get directories. Now I want to create directories with a variable, for exemple "mkdir job{0001..$a}". When a=5 I get the directory "job{0001..5}". What have i to change to get job0001,...,job0005 :/ Thx for ur help :) (1 Reply)
Discussion started by: E_taks
1 Replies

4. UNIX for Dummies Questions & Answers

Mkdir utility

Howdy, Puttering around in unix, and read this in the mkdir man page: "The mkdir utility creates the directories named as operands..." What does this mean, i.e. as operands? Many thanks, DN (2 Replies)
Discussion started by: danuke
2 Replies

5. Homework & Coursework Questions

Mkdir

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Do the procedure, which if there are 5 parameters then it creates 4 directories with names of 4 parameters, in... (2 Replies)
Discussion started by: bolones
2 Replies

6. Shell Programming and Scripting

Cp/Mkdir and spaces

I am having trouble using cp and mkdir commands on a small script. The problem is I have spaces what I am trying to mkdir and then copy. Any suggestions on how I can solve this problem? I've tried searching online. while read linefile do echo mkdir -p $CPP$linefile | cut -d / -f 1-5,8-12 ... (10 Replies)
Discussion started by: imagiro1
10 Replies

7. UNIX for Advanced & Expert Users

mkdir

Is there ant way to increase max number of folders in the directory from the 32766: Problem UFS: shell>mkdir mmm mkdir: mmm: Too many links But there are no links, just folders. shell>ls | wc -l 32766 (3 Replies)
Discussion started by: mirusnet
3 Replies

8. Shell Programming and Scripting

mkdir

Hi, I look for a script to create 150 directories : d000 d001 d002 ... ... d149 would you help me please ? I think it would be for i mkdir d$i Many thanks. PS : #uname -a AIX fserver 3 5 0050691A4C00 (2 Replies)
Discussion started by: big123456
2 Replies

9. Linux

install vs mkdir

I'm sitting here late at night, reading linux from scratch, and I come to this part: http://lfs.osuosl.org/lfs/view/stable/chapter06/creatingdirs.html my question to you, the all knowing unix.com'ers is this: what's the difference between using the install command as they do, and using the... (1 Reply)
Discussion started by: thmnetwork
1 Replies

10. UNIX for Dummies Questions & Answers

mkdir limitations

What characters can't be used with a mkdir? Any limits on length of name? Thank you, Randy M. Zeitman http://www.StoneRoseDesign.com (12 Replies)
Discussion started by: flignar
12 Replies
Login or Register to Ask a Question