Copy File and make any required directories

Soldato
Joined
26 Aug 2012
Posts
4,434
Location
North West
I'm trying to copy a file from a source path to a destination path and make any required directories in the destination path.

An example would be as below where the 'blah2' directory does not exist at the destination.

cp /etc/blah1/blah2/file1.file /opt/blah1/blah2/file1.file

I need this as I have a php web app that needs to cache certain things.

Any help would be much appreciated.
 
do you mean with cp or via php

For cp use cp --parents

so it would be with your example

Code:
cp --parents /etc/blah1/blah2/file1.file /opt/
That will create the required dirs if not there

Edit: having said that. It would create opt/etc/.....

Maybe cd into etc first then do the cp command
 
Last edited:
Back
Top Bottom