LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-28-2006, 01:17 PM   #1
john_551
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Rep: Reputation: 0
Question script to change file name and append the date


Hello,

Please bare with me, I'm rather new.
At the present time I am trying to take a bunch of files in a directory and append the date to the end of them and move them to a different directory.

Here is what I have so far:

#!/bin/sh

DATETIME=`date +%Y%m%d`


mv $1 $1.$DATETIME
mv $1.$DATETIME /home/magicman/done/


At the present time I have to call the script and give it a file. I would like to be able to automatically go to a specific directory, append the date to the end of each file like above and then move the file to the new directory. And then repeat until the directory is empty.

Can anyone help me out regarding this, I'm not that great at programming, but I am learning. Any help would be greatly appreciated! Thanks
John
 
Old 07-28-2006, 01:55 PM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
create another script:
for i in *; do mv-somwhere-with-date $i; done

now read man bash for how to make functions instead separate files.
 
Old 07-31-2006, 08:38 AM   #3
john_551
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Raskin,
Thank you for the reply.
I was able to achieve what I wanted to do.
I created another script as you suggested and did this:
for i in /home/magicman/update/*
do
/home/magicman/changename.sh $i
done

And it worked perfectly.
Thanks
 
Old 08-23-2006, 04:05 PM   #4
john_551
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
I now have a little problem.
I have three scripts that need to run, but depend on which type of files are in a directory.


My three scripts are:
sendjpg
sendmp3
send

In my temp directory /tmp
If I have a file.mp3, run the sendmps, a jpg run sendjpg, and the rest of the files use the send script.

I would like to know how I can place this in a script:
If I have no files, do nothing
If I have mp3, run only sendmp3
If I have a jpg, run only sendjpg
If I have jpg and mp3, run them both.
etc etc.
I'm not sure on how to place this in a script to select the correct action.
John
 
Old 08-26-2006, 06:56 AM   #5
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Well, try 'case':

for i in /tmp/*; do
case $i in
*.mp3)
sendmp3 $i;
;;
*)
send $i;
;;
esac;
done;
 
  


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
Get file modification date/time in Bash script cmfarley19 Programming 16 04-15-2015 06:25 PM
Unix script : Append to a file linux_newbee Linux - Newbie 2 06-08-2006 01:12 PM
Script to change date in filename minus one day ft77 Linux - General 3 06-02-2006 09:56 AM
How to append today's date in a script anjaan Programming 4 06-12-2004 08:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:53 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
Open Source Consulting | Domain Registration