LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to append time to folder (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-append-time-to-folder-800998/)

pinga123 04-09-2010 06:27 AM

How to append time to folder
 
Hi i just want to create a folder with current time.

For example.

foldername_09042010 How do i modify mkdir or write script to do this?

colucix 04-09-2010 06:33 AM

You can try command substitution, e.g.
Code:

mkdir foldername_$(date +%d%m%Y)
May I suggest to invert the order of the date fields? I mean:
Code:

mkdir foldername_$(date +%Y%m%d)
In this way dates can be sorted from the oldest to the newest (useful when listing items with similar name but different date).

pinga123 04-09-2010 06:36 AM

FolderName='WIN2003-SP2'

Directory_Name=$FolderName_$(date +%Y%m%d)

How can i do above task?
Thanks for the quick reply.

Aquarius_Girl 04-09-2010 06:37 AM

Thanks colucix,

I tried the following
Code:

mkdir foldername_$(date +%d-%m-%Y)
It worked nicely and resulted in the following folder:
foldername_09-04-2010

Its nice to have experienced people like you here !

colucix 04-09-2010 06:57 AM

@pinga123: you have to keep the variable name separated from the underscore. Use the complete syntax for parameter substitution with brackets:
Code:

Directory_Name=${FolderName}_$(date +%Y%m%d)
otherwise the shell look for a variable called "FolderName_".

@anishakaul: You're welcome! :)

cola 04-09-2010 06:18 PM

Quote:

Originally Posted by pinga123 (Post 3929759)
FolderName='WIN2003-SP2'

Directory_Name=$FolderName_$(date +%Y%m%d)

How can i do above task?
Thanks for the quick reply.

Mark the thread as "[SOLVED]",this option is under the Thread Tools above.

cola 04-09-2010 06:18 PM

Quote:

Originally Posted by colucix (Post 3929777)
@pinga123: you have to keep the variable name separated from the underscore. Use the complete syntax for parameter substitution with brackets:
Code:

Directory_Name=${FolderName}_$(date +%Y%m%d)
otherwise the shell look for a variable called "FolderName_".

@anishakaul: You're welcome! :)

+1 colucix.


All times are GMT -5. The time now is 06:38 PM.