LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-07-2010, 05:51 PM   #1
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: Fedora 20 64 bit
Posts: 43

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

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

Rep: Reputation: 525Reputation: 525Reputation: 525Reputation: 525Reputation: 525Reputation: 525
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.
Code:
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, 06:09 PM   #3
Hammett
Senior Member
 
Registered: Aug 2003
Location: Barcelona, Catalunya
Distribution: Gentoo
Posts: 1,037

Rep: Reputation: 54
I know close to nothing regarding bash scripting, but you might want to try this:
Code:
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 06:11 PM.
 
2 members found this post helpful.
Old 05-08-2010, 11:52 AM   #4
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: Fedora 20 64 bit
Posts: 43

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

Denis
 
  


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


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration