简体   繁体   中英

Shell Script help to copy directory them remove

I want to write simple script to copy/backup directory then remove on server startup. So something like this:

TC_DIR=${SERVER_HOME}/terracotta
CLUSTER_STAT_DIR=${TC_DIR}/cluster-stat

cp ${CLUSTER_STAT_DIR} ${TC_DIR}/old.cluster-stat
rm ${CLUSTER_STAT_DIR}

Thanks for help guys.

I believe what you have done should work with the only addition that you need to pass -r options to both cp and rm as you are dealing with directories. Try this:

TC_DIR=${SERVER_HOME}/terracotta
CLUSTER_STAT_DIR=${TC_DIR}/cluster-stat

cp -r ${CLUSTER_STAT_DIR} ${TC_DIR}/old.cluster-stat
rm -rf ${CLUSTER_STAT_DIR}

EDIT: if your question is how to execute that on startup take a look here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM