LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   mkdir & cp in one command? (https://www.linuxquestions.org/questions/linux-software-2/mkdir-and-cp-in-one-command-536674/)

une 03-11-2007 08:36 PM

mkdir & cp in one command?
 
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.

vectordrake 03-11-2007 09:18 PM

Try
Code:

mkdir newdirectory && cp test.txt newdirectory/test.txt


All times are GMT -5. The time now is 05:30 PM.