LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-25-2008, 10:04 AM   #1
saghir27
LQ Newbie
 
Registered: Apr 2008
Posts: 1

Rep: Reputation: 0
Script to rename a file


Hi

I'm new to linux and need help with a script.

I want to be able to run this script from webmin

#!/bin/bash
# script=dname
#parameter $1 is the existing file name
dt=`date +%y%m%d`
mv $1 $1$dt

I'm using filesystem backup to backup some files to /backup/backup.tar

problem is the file is getting over written everyday, I want to change the file name to include current date this way it wouldn't get deleted at next backup.

Can someone help
 
Old 04-29-2008, 08:20 AM   #2
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia 4
Posts: 746

Rep: Reputation: 35
Do it in Python. Python is great for this sort of thing. It has a date library, so you can just get the day's date from it and play around naming files to your heart's content.

Python is simply fabulous and easy to learn.

http://www.linuxjournal.com/article/3946

Have a look at that to get basic idea then look at how to import libraries.

import time

now = time.localtime()
 
  


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
HELP! Script to RENAME/REMOVE ( ) From File NAMES!! xberetta21 Linux - Newbie 4 01-29-2008 01:10 PM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-22-2008 11:25 PM
Rename script superior888 Programming 2 07-31-2006 11:53 AM
Help with script to rename shilo Slackware 10 02-04-2006 08:58 AM
File rename script jjwl89 Linux - General 1 03-14-2005 06:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:01 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration