create directory on fly

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/<dir name created on fly "log.`date '%k-%M-%F'`"

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



Thanks & regards,
Onkar
onkar [ Mi, 09 Januar 2008 06:29 ] [ ID #1903291 ]

Re: create directory on fly

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/<dir name created on fly "log.`date '%k-%M-%F'`"
>
> 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.
Cyrus Kriticos [ Mi, 09 Januar 2008 07:01 ] [ ID #1903293 ]

Re: create directory on fly

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/<dir name created on fly "log.`date '%k-%M-%F'`"

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
>
Janis Papanagnou [ Mi, 09 Januar 2008 07:00 ] [ ID #1903294 ]

Re: create directory on fly

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/<dir name created on fly "log.`date '%k-%M-%F'`"
>
> 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.
Cyrus Kriticos [ Mi, 09 Januar 2008 07:02 ] [ ID #1903295 ]

Re: create directory on fly

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/<dir name created on fly "log.`date '%k-%M-%F'`"
>>
>> 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.
Cyrus Kriticos [ Mi, 09 Januar 2008 07:59 ] [ ID #1903297 ]
Linux » comp.unix.shell » create directory on fly

Vorheriges Thema: Double hight characters
Nächstes Thema: Re: I don't understand why the following increases cpu time