Help - Search - Members - Calendar
Full Version: Copy Or Rename Script
Linuxhelp > Support > Technical Support
Hello I am rather new to Linux and I need a script or utility to copy or rename a file that changes frequently to succesive file names.. that maybe i can call from cron to be done at certain times
As an example I have file and want it copied or renamed to
and next time it is copied to check to see what last name is and name it next higher number in succession.. ie and

Am I asking for too much? sounds pretty simple just not familiar enough with linux script files.

Maybe it doesnt have to be a script can i add options to end of a command like cp that will handle this for me?
A script is the way to go ... it can be done several ways. First, would a date-time e better than a number? If you are going to run the script once per day or less, you could use the date like so (or maybe Either is doable ... what's best for you?

Here is a simple script i named


# This does the math for the filename and stores the result
# for future use in a file called test.num.  This file is
# designed to be in the directory the other files reside in
if [ -f test.num ]; then
 a=`cat test.num`

let "a = $a + 1"
echo $a > test.num

# This copies the file to when you run
# the script.  If you also want to remove the old
# and start with a new file, remove the # from the last line

cp list-"$a".xxx
#echo >

If you save this script to a text file and make it executable (chmod 755, it will copy a file named to (the next time it is run it will copy to, etc.) and if you remove the # from the last line it will blankout to start it over from a blank file.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.