1) back up the specified file
[root@iZ2vc5lqzt23aweti4j777Z 15thOctober2024]
suffix=` date +%Y%m%d`
for f in `find /root/15thOctober2024/data/ -type f -name '*.txt'`
do
echo 'backup file $f'
cp ${f} ${f}_${suffix}
done
[root@iZ2vc5lqzt23aweti4j777Z 15thOctober2024]
total 16
drwxr-xr-x 3 root root 4096 Oct 15 17:48 .
dr-xr-x---. 14 root root 4096 Oct 15 17:48 ..
drwxr-xr-x 2 root root 4096 Oct 15 17:48 data
-rw-r--r-- 1 root root 147 Oct 15 17:48 test1.sh
[root@iZ2vc5lqzt23aweti4j777Z 15thOctober2024]
backup file $f
[root@iZ2vc5lqzt23aweti4j777Z 15thOctober2024]
total 16
drwxr-xr-x 2 root root 4096 Oct 15 17:48 .
drwxr-xr-x 3 root root 4096 Oct 15 17:48 ..
-rw-r--r-- 1 root root 25 Oct 15 17:38 test1.txt
-rw-r--r-- 1 root root 25 Oct 15 17:48 test1.txt_20241015