mv $1 `echo $1 | sed 's/\/[^/][^/]*//'`/Archive/`echo $1 | sed 's/.*\///'`.`date +"%Y-%m-%d"`
N.b. not intended to backup entire directories at a time, but if you do, drop the trailing slash (or just edit the script to do it for you; I wanted to keep it simple).
awesome...Thanks a lot for your help...a little bit of refinement...
For some directories it is ARCHIVE, for some archive and for some it is Archive.....How do I include this condition to check for the available archive directory
+ sed s/\/[^/][^/]//
+ echo test_file.txt
+ sed s/.\///
+ echo test_file.txt
+ date +%Y-%m-%d
+ mv test_file.txt test_file.txt/ARCHIVE/test_file.txt.2008-07-23
mv: cannot rename test_file.txt to test_file.txt/ARCHIVE/test_file.txt.2008-07-23: Not a directory
It works perfectly...Thanks a lot for your help....
Would like to know if there is a way to see if the check if the directories ARCHIVE/archive/Archive exists and based on that move the files to the Archive directory...since I want to write a generic script that archives the files to archive directory...but for some projects the archive directory is ARCHIVE, for some it is Archive and for others it is Archive.
#!/bin/sh
file=$1
if [ -d ${file%/*}"/ARCHIVE" ]; then
archive="ARCHIVE"
else
archive="Archive"
fi
echo $file|sed "s_\(.*/\)\(.*\)_mv & \1$archive/\2_" | sh