LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to rename a file (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-rename-a-file-637787/)

saghir27 04-25-2008 10:04 AM

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

DiBosco 04-29-2008 08:20 AM

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()


All times are GMT -5. The time now is 03:54 AM.