LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-09-2010, 06:27 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 37
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?
 
Old 04-09-2010, 06:33 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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).
 
1 members found this post helpful.
Old 04-09-2010, 06:36 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684

Original Poster
Blog Entries: 2

Rep: Reputation: 37
FolderName='WIN2003-SP2'

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

How can i do above task?
Thanks for the quick reply.
 
Old 04-09-2010, 06:37 AM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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 !
 
Old 04-09-2010, 06:57 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
@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!
 
2 members found this post helpful.
Old 04-09-2010, 06:18 PM   #6
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Rep: Reputation: 65
Quote:
Originally Posted by pinga123 View Post
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.
 
Old 04-09-2010, 06:18 PM   #7
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Rep: Reputation: 65
Quote:
Originally Posted by colucix View Post
@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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
counted folder for each time in Perl kariagekun Programming 3 11-11-2009 07:32 PM
[SOLVED] Find folder creation time kenneho Linux - Newbie 2 08-24-2009 07:56 AM
Benchmarking a tape drive, time to copy takes forever, time to append takes longer? jeriryan Linux - Hardware 2 06-15-2008 12:15 AM
How can I append the date/time stamp to commands in history? abefroman Linux - Security 2 05-29-2008 11:21 AM
time --output=log.txt --append sadarax Linux - General 1 05-22-2006 08:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration