Unix Shell Scripting - Sajha Mobile
SAJHA MOBILE
Unix Shell Scripting
Posts 3 · Viewed 3962 · Likes 1 · Go to Last Post
jhapaliketo
· Snapshot 0
Like · Likedby · 0
I have written the following script to copy files from a directory to another directory and add time stamp to the copied file and remove the original file. I want to know if it is good for bash scripting.
 

#!/bin/bash
for FILES in ./current/*
do
cp -ur $FILES /previous/${FILE}.`date +%m%d%Y`
rm ./current/$FILES
done
M$Hacks
· Snapshot 65
Like · Liked by · 1

I woud recommend using move instead of copy+remove, its faster. Modified version below:

#!/bin/bash
cd ./current

for FILES in *

do

  mv $FILES /previous/${FILES}.`date +%m%d%Y`

done

 

jhapaliketo
· Snapshot 110
Like · Liked by · 0
That looks good.
Thanks

My VPN is not working. So, i have not been able to test.
Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 9 · Viewed 12671 · Likes 1
· Posts 7 · Viewed 4109 · Likes 1
· Posts 1 · Viewed 1129
· Posts 1 · Viewed 1147
· Posts 1 · Viewed 1037
· Posts 1 · Viewed 1126
· Posts 1 · Viewed 1089
· Posts 21 · Viewed 10264 · Likes 1
· Posts 3 · Viewed 2680
· Posts 5 · Viewed 7873 · Likes 1



Your Banner Here
Travel Partners
Travel House Nepal