I am trying to figure out a way to create a file that will be renamed based off of one of multiple files. For example, if I have 3 files (cat.ctl, dog.ctl, and bird.ctl) that gets placed on to an ftp site I want to create a single file called new.cat.ctl, new.dog.ctl, etc for each but if there was a file called falcon.ctl it would not create a "new" file unless it was added to the list of names it was looking for. Inside the file, it will basically be a copy of the old file. I have an if statement in mind but I am still fairly new to Unix. I have tried to explain it how I want to do it but I am just not sure. I would appreciate any help the forum can give.
find /path/to/ftp/directory -name '*.ctl' |
while read fname
do
if [[! -f /path/to/ftp/directory/new.$(basename $fname) ]] ; then
mv ${fname} /path/to/ftp/directory/new.$(basename $fname)
fi
done
Is that what you meant? this only creates a "new" when a "new" does not already exist.
This is similar to what I have in mind. I know that if I use a wild card it would pickup everything with a .ctl but if I set it up with something like find /path/to/ftp/directory -name 'c*.ctl' then that would limit what files get moved. I will try this out.