Re: cp output format
Hi,
On 16/07/2015 10:23 PM, Haines Brown wrote:
> Sorry for this elementary question. I want to do sequential copies with
> a command like this: $ cp --backup=t file .../destination/file. When
> periodically run it produces file, file.~1~, file.~2~, etc.
>
> How do I get rid of the "~" so that the backups are file.1, file.2,
> etc.?
Hmm, okay, so you are copying potentially unchanged files to new version
numbers in a destination directory..
Not sure if this is relevant enough, but I have a method to keep
"source" files -- in this case .forward files in a controlled directory;
if any of these differ from the target locations, then I save the target
location file with a dated version and copy in the controlled source
copy. This way I only get new files if they are changed, you could use
a similar method for the backups, that is only copying files to the
backup area if they are different to the current copy in the source area.
# cat fix_dot_forward.sh
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
(
wrk_dir=/backup/.forward-wrk
for fix_name in user1 user2 user3
do
HOME_DIR=$(grep ^${fix_name}: /etc/passwd|cut -d: -f6)
md5_1=$(md5sum $HOME_DIR/.forward|cut -d\ -f1)
md5_2=$(md5sum $wrk_dir/$fix_name/.forward|cut -d\ -f1)
if [ "$md5_1" != "$md5_2" ]
then
echo "The .forward file has changed for: "$fix_name
diff $HOME_DIR/.forward $wrk_dir/$fix_name/.forward|sed
's/^/ /'
cp -p $HOME_DIR/.forward
$HOME_DIR/${fix_name}.forward.$(date +%Y%m%d%H%M)
cp -p $wrk_dir/$fix_name/.forward $HOME_DIR/
fi
done
)
That gives me file versions and history in a fairly simple way; all in
the same file system area, not using any kind of version control system
other than simple file names.
Another option might be to use the %s date format for the file name
suffix to get the seconds since epoch with the file itself giving the
reference date/time value used for the suffix.
for filex in $(ls);do cp -p $filex ${filex}.$(date -r $filex +%s);done
Cheers
AndrewM
Reply to: