LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2004, 09:41 PM   #1
tearinox
Member
 
Registered: Aug 2003
Location: you dont want to know
Distribution: Gentoo 2004.2, Slackware 10, Windows XP, Windows 2003 Server
Posts: 348

Rep: Reputation: 30
Putting variables in everyday used commands


What I'm trying to do is make rename a file to the current date. What I tried to do is:

Code:
$ date
Wed Apr 28 19:38:13 PDT 2004
$ mv file.png $date
You can see what I'm trying to do there. But it's not working out so well. Can someone help me out here.
 
Old 04-28-2004, 10:38 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Couple things wrong here. First is the date contains spaces, you want the spaces in the filename? In the Windows world it's ok, but in UNIX they difficult to deal with and not used often. Second is you are trying to use the $date variable when it has never been set.

Set a variable like:
Code:
date=`date`
But you should probably do something like this:
Code:
DATE=`date +'%Y%m%d'`
mv file.png file.png.$DATE
This will move the file to: file.png.20040428

It has no spaces, and it sorts well with file of the same name.

Hope this helps.
 
Old 04-29-2004, 05:08 PM   #3
tearinox
Member
 
Registered: Aug 2003
Location: you dont want to know
Distribution: Gentoo 2004.2, Slackware 10, Windows XP, Windows 2003 Server
Posts: 348

Original Poster
Rep: Reputation: 30
Nice! Thanks muchas gracias crabboy!
I have modified it a little bit to say
Code:
DATE=`date +'%Y_%m_%d_%l:%M'`
mv file.png %DATE.png
Plus I have this now bound to the screenshot button so it will create a different screenshot everytime I press the bound button

Thanks for the help in getting me started!!
 
  


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
reboot everyday ? vacilus Linux - Software 4 04-18-2005 02:10 AM
commands stored into variables? benne Programming 2 11-15-2004 07:20 PM
How to echo variables and commands in one line? hindll01 Programming 1 09-10-2004 06:02 AM
What are some of the everyday commands used for an average user? statyk Linux - Newbie 5 12-16-2003 09:47 PM
Which programs will i need for everyday use?? Horus Linux - Software 3 02-03-2003 05:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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