我想在Linux腳本中創建一個循環,它將穿過一個目錄中的文件夾並將照片複製到一個文件夾並覆蓋具有相同名稱的照片。任何人都可以指出我的寫作方向嗎?Linux腳本循環
2
A
回答
3
find /path/to/source -type f -exec cp -f {} /path/to/destination \;
會這樣嗎?請記住,這會覆蓋文件而不詢問。
如果您希望它在覆蓋前與您確認,請在cp
命令中使用-i標誌(用於交互模式)。
0
find /path/to/source -type f | xargs -I {} file {} | grep <JPEG or image type> | cut -d ":" -f1 | xargs -I {} cp -rf {} /path/to/destination
有了這個,你可以找到調整你的副本只選擇圖像類型。
0
實際上,您不需要通過文件夾循環查找使用腳本的照片,find
命令將爲您完成這項工作。
嘗試使用find
與xargs
和cp
find source_dir -type f -iname '*.jpg' -print0 | xargs -0 -I {} cp -f {} dest_dir
替換*.jpg
與照片文件格式。 (例如*.png
等)
注意使用的cp
-f
的選擇,因爲你要使用相同的名稱覆蓋照片
相關問題
- 1. 循環的linux腳本
- 2. linux bash腳本循環錯誤處理
- 3. 循環錯誤的Linux shell腳本
- 4. Bash腳本循環
- 5. 循環XCOPY腳本
- 6. AutoHotkey循環腳本
- 7. Bash腳本循環?
- 8. 只循環腳本
- 9. Cmd腳本循環
- 10. bash腳本,循環不循環
- 11. 停止從Linux腳本中運行的PHP腳本的infinit循環
- 12. Bash腳本無限循環
- 13. 在CMD腳本循環
- 14. Windows shell腳本循環
- 15. 如何循環PHP腳本
- 16. 如何循環腳本
- 17. while循環bash腳本
- 18. 在matlab腳本中循環
- 19. 從cron循環php腳本?
- 20. shell腳本While循環
- 21. bash:退出腳本循環
- 22. KSH腳本,對於循環
- 23. 循環的Python腳本
- 24. Exchange Powershell腳本循環
- 25. bash腳本:循環參數
- 26. bash腳本 - 在while循環
- 27. 循環腳本錯誤
- 28. 循環咖啡腳本?
- 29. bash腳本For循環*
- 30. 在bash腳本中循環