LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Date & time as dir name (https://www.linuxquestions.org/questions/linux-general-1/date-and-time-as-dir-name-425200/)

Pyrate_02 03-15-2006 06:53 PM

Date & time as dir name
 
I am trying to write a shell script that will creat a directory with the current date and time as name (mkdir /home/??), then move some files into it (mv /home/cam/*.avi /home/??). This is for a security cam setup, using lavrec as the recorder. Any sugestions for syntax?

ckoniecny 03-15-2006 06:57 PM

The command you will want to execute at the prompt to get the date and time is:
Code:

$ date +%m-%d-%Y-%H:%M
That will output
Code:

3-15-2006-20:11
In your case, you will want to do

Code:

#!/bin/zsh

CUR_DATE=`date +%m-%d-%Y-%H:%D`


if [ -d /home/$CUR_DATE ];
then
    cp /home/cam/*.avi /home/$CUR_DATE
else
    mkdir $CUR_DATE
fi


Pyrate_02 03-16-2006 01:24 AM

Well; Almost
 
Tried that code verbatum. Got zip. Played with it for awhile, and finally got to:

cd /home/cam

CUR_DATE='date +%m%d-%Y-%H:%D'

mkdir $CUR_DATE

mv /home/cam/*.avi /home/cam/$CUR_DATE

which got me a directory called "+%m%d-%Y-%H:%D", with a directory called "date" in it, along with all of the avis. It's close, but is not reading the format.
I'm using bash in Mandriva. Any chance that's my problem?

ckoniecny 03-16-2006 05:43 AM

Notice that CUR_DATE=`date +%m-%d-%Y-%H:%D` is not encapsulated with aposterphies, it uses the character that is next to the number one on the keyboard. This tells the script to execute the command "date". Copy and paste my script, you will see that it does work.

Pyrate_02 03-16-2006 01:21 PM

Yer rite! It works now.
That's what happens when you get old. You can't see. Increased my font size and saw what you told me. I beat my head against the wall for 3 days on that one.
Thank you very much for your help.

timmeke 03-17-2006 02:40 AM

If you don't want to use backquotes, try using the out=$(command) syntax instead.

Note also that you can play around with the format of the dates by changing the date command appropriately.

Pyrate_02 03-18-2006 03:53 AM

Date & time as dir name
 
Did that. Got the format the way I wanted it, then added a tar/zip line. Thing works smooth as a baby's bum. That's why I love Linux so much. Get stuck on something, and people trip over themselves to help you. Where else in the world do you see that attitude?


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