PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > create directory on fly
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

create directory on fly

Réponse
 
LinkBack Outils de la discussion
Vieux 09/01/2008, 05h29   #1
onkar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 09/01/2008, 06h00   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
>

  Réponse avec citation
Vieux 09/01/2008, 06h01   #3
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 09/01/2008, 06h02   #4
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 09/01/2008, 06h59   #5
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h58.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,33451 seconds with 13 queries