Linux移動檔案又保留目錄結構的指令

唉~ 蠻可惜的,太晚發現這個指令了!

由於我需要整理一些在資料夾中,比較少用的檔案,並將其搬移到其他的硬碟中

之前都用這個指令
find /來源目錄/ -mtime +210 -type f -print -exec mv "{}" /存放目錄/ \;

改成這個指令,就能讓檔案移動時跟著目錄跑
find /來源目錄/ -mtime +210 -type f -print | cpio -pdumv /存放目錄/

參考連結:
http://www.unix.com/unix-for-dummies-questions-and-answers/153746-find-mv-create-directory-structure.html

後記,後來我發現cpio有個缺點,就是存取速度很慢,用cp指令就好了,複製完成再用rm移掉

find /來源目錄/  -mtime +210 -type f -print -exec cp --parents --preserve=timestamp "{}" /存放目錄/\;

find /來源目錄/  -mtime +210 -type f -print -exec rm '{}' \;


小記:
查詢所有的目錄大小
df -h

查詢221天前的檔案佔用容量 (可以做移動判定)
find /來源目錄/ -mtime +221 -type f -print -exec du -ach {} + | tail -n 1

查詢某個時間區間檔案佔用容量
find /來源目錄/ -newermt "2014-10-01 00:00:00" ! -newermt "2014-11-02 00:00:00" -type f -print -exec du -ach

其實我不曉得Windows的系統有沒有類似的指令能做為檔案管理使用,所以目前為止,有一台Linux系統的NAS,是個很棒的檔案管理方式

留言

熱門文章