Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 05-07-2010, 04:51 PM   #1
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Rep: Reputation: 15
Smile move file and folder date stamps

Hi all,

I wrote this little script and I need some help, I am trying to achieve following:

Every day I receive new file in the /home/denis/MyData/ folder and I don't know what the file mane will be but I want to move any file that arrives there to the new location /media/DataBackup/Linux/backup/
(media/DataBackup/ is external 500GB USB drive)
and to automatically create new folder with the date and time stamp every day and then to move content of the /home/denis/MyData/ into the new folder with current date stamp. So every day there will be new folder and will contain files for that day only.

My script is as follows:

cd /media/DataBackup/Linux/backup/

mkdir MyData_$(date +%Y%b%d_%HH%MM)

#this creates file MyData_current date and time

cd /home/denis/MyData/

mv *.* /media/DataBackup/Linux/backup/
MyData_????/ what do I key in here?

I hope someone can help me with this one.

Thanks in advance

Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-07-2010, 05:06 PM   #2
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
You want it to be the same as the "MyData_$(date +%Y%b%d_%HH%MM)" before it, right?

Fill a variable and use it.
DEST=/media/DataBackup/Linux/backup/MyData_$(date +%Y%b%d_%HH%MM)
mkdir ${DEST}
mv /home/denis/MyData/*.* ${DEST}/
2 members found this post helpful.
Old 05-07-2010, 05:09 PM   #3
Senior Member
Registered: Aug 2003
Location: Barcelona, Catalunya
Distribution: Gentoo
Posts: 1,042

Rep: Reputation: 54
I know close to nothing regarding bash scripting, but you might want to try this:
cd /media/DataBackup/Linux/backup/
DIR=MyData_$(date +%Y%b%d_%HH%MM)
mkdir $DIR
#this creates file MyData_current date and time
cd /home/denis/MyData/
mv *.* /media/DataBackup/Linux/backup/$DIR
Hope it helps!

LOL! While I was typing this, AlucardZero proposed the same solution (slightly different)

Last edited by Hammett; 05-07-2010 at 05:11 PM.
2 members found this post helpful.
Old 05-08-2010, 10:52 AM   #4
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Original Poster
Rep: Reputation: 15
Thumbs up

Hi both,

Thank you very much for your suggestions, both scripts are working well. I really appreciate you help you saved me many hours of work.

Best wishes



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
find and move to folder and file dulahdaglace Linux - Newbie 1 09-15-2009 10:44 PM
Help me...after used mv command all file missing only folder move to new path scoreone1 Linux - General 9 10-20-2008 11:22 PM
Time stamps following move to British Summer Time aikempshall Linux - General 2 03-30-2007 08:30 AM
making a script that will move a file or files in a trash folder Paxmaster Programming 5 12-12-2004 06:00 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:11 AM.

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