create directory on fly

create directory on fly

am 09.01.2008 06:29:32 von onkar

i am writing a script in that I want to copy the files in one
directory which is created on fly :

a line in the script is :

cp -p config.log BASE_PATH/"log.`date '%k-%M-%F'`"


i.e., I want to copy file config.log to the directory
BASE_PATH/


how can cp create directories on fly ??
if no ..
is there any other way i can do this ??



Thanks & regards,
Onkar

Re: create directory on fly

am 09.01.2008 07:00:39 von Janis Papanagnou

onkar wrote:
> i am writing a script in that I want to copy the files in one
> directory which is created on fly :
>
> a line in the script is :
>
> cp -p config.log BASE_PATH/"log.`date '%k-%M-%F'`"
>
>
> i.e., I want to copy file config.log to the directory
> BASE_PATH/


targetdir=BASE_PATH/DIRNAME_CREATED_ON_THE_FLY
mkdir -p "$targetdir"
cp -p config.log "$targetdir/log.$(date '+%k-%M-%F')"

Mind that your date specifier may create filenames with blanks.

Janis

>
> how can cp create directories on fly ??
> if no ..
> is there any other way i can do this ??
>
>
>
> Thanks & regards,
> Onkar
>

Re: create directory on fly

am 09.01.2008 07:01:04 von Cyrus Kriticos

onkar wrote:
> i am writing a script in that I want to copy the files in one
> directory which is created on fly :
>
> a line in the script is :
>
> cp -p config.log BASE_PATH/"log.`date '%k-%M-%F'`"
>
>
> i.e., I want to copy file config.log to the directory
> BASE_PATH/

>
> how can cp create directories on fly ??
> if no ..
> is there any other way i can do this ??

[GNU tar]

tar c config.log | tar xv --transform="s;.*;YOURDR/&;" --show-transformed-names

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.

Re: create directory on fly

am 09.01.2008 07:02:47 von Cyrus Kriticos

onkar wrote:
> i am writing a script in that I want to copy the files in one
> directory which is created on fly :
>
> a line in the script is :
>
> cp -p config.log BASE_PATH/"log.`date '%k-%M-%F'`"
>
>
> i.e., I want to copy file config.log to the directory
> BASE_PATH/

>
> how can cp create directories on fly ??
> if no ..
> is there any other way i can do this ??

[GNU tar]

tar c config.log | tar xv --transform="s;.*;YOURDIR/&;"
--show-transformed-names

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.

Re: create directory on fly

am 09.01.2008 07:59:51 von Cyrus Kriticos

Cyrus Kriticos wrote:
> onkar wrote:
>> i am writing a script in that I want to copy the files in one
>> directory which is created on fly :
>>
>> a line in the script is :
>>
>> cp -p config.log BASE_PATH/"log.`date '%k-%M-%F'`"
>>
>>
>> i.e., I want to copy file config.log to the directory
>> BASE_PATH/

>>
>> how can cp create directories on fly ??
>> if no ..
>> is there any other way i can do this ??
>
> [GNU tar]
>
> tar c config.log | tar xv --transform="s;.*;YOURDIR/&;" --show-transformed-names

To preserve permissions:

tar c config.log | tar xvp --transform="s;.*;YOURDIR/&;"
--show-transformed-name

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.