LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 07:27 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
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, 07:33 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 07:36 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
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, 07:37 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,672
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
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, 07:57 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
@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, 07:18 PM   #6
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,031

Rep: Reputation: 63
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, 07:18 PM   #7
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,031

Rep: Reputation: 63
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:32 PM
[SOLVED] Find folder creation time kenneho Linux - Newbie 2 08-24-2009 08:56 AM
Benchmarking a tape drive, time to copy takes forever, time to append takes longer? jeriryan Linux - Hardware 2 06-15-2008 01:15 AM
How can I append the date/time stamp to commands in history? abefroman Linux - Security 2 05-29-2008 12:21 PM
time --output=log.txt --append sadarax Linux - General 1 05-22-2006 09:46 AM


All times are GMT -5. The time now is 08:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration