맥을 사용하다보니 매번 “다운로드” 디렉토리에는 온갖 것들이 잔뜩 들어서 정리가 안된다.
한 번씩 정리하는 건 맥을 리셋하거나 기기변경을 할 때 정도 뿐인 것 같다.
아예 파일 종류별로 좀 정리되어 있으면 좋지 않을까 해서 스크립트를 만들었다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#!/bin/bash cd ~/Downloads; find . -maxdepth 1 -name '*.HEIC' -mtime +15 -exec mv {} ./picture \; find . -maxdepth 1 -name '*.JPG' -mtime +15 -exec mv {} ./picture \; find . -maxdepth 1 -name '*.jpeg' -mtime +15 -exec mv {} ./picture \; find . -maxdepth 1 -name '*.jpg' -mtime +15 -exec mv {} ./picture \; find . -maxdepth 1 -name '*.mp4' -mtime +15 -exec mv {} ./picture \; find . -maxdepth 1 -name '*.png' -mtime +15 -exec mv {} ./picture \; find . -maxdepth 1 -name '*.docx' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.dot' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.hwp' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.key' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.pdf' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.pptx' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.xls' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.xlsx' -mtime +15 -exec mv {} ./document \; find . -maxdepth 1 -name '*.dmg' -mtime +15 -exec mv {} ./program \; find . -maxdepth 1 -name '*.bz2' -mtime +15 -exec mv {} ./zip \; find . -maxdepth 1 -name '*.tar' -mtime +15 -exec mv {} ./zip \; find . -maxdepth 1 -name '*.zip' -mtime +15 -exec mv {} ./zip \; find . -maxdepth 1 -name '*.json' -mtime +15 -exec mv {} ./etc \; find . -maxdepth 1 -name '*.pl' -mtime +15 -exec mv {} ./etc \; find . -maxdepth 1 -name '*.py' -mtime +15 -exec mv {} ./etc \; find . -maxdepth 1 -name '*.sql' -mtime +15 -exec mv {} ./etc \; cd -; cd ~/interview find . -maxdepth 1 -not -path . -mtime +1 -exec rm -rf {} \; cd -; |
아래처럼 해서 매핑 정보를 좀더 nice하게 해줬으면 좋으련만… shell에서는 하기가 힘들 것 같아서 말았다. (python 쓰면 괜찮긴 할텐데)
1 2 |
{document, {doc, docx, pdf}} {picture, {jpg, jpeg, png, gif}} |
마지막으로 crontab에 해당 스크립트를 걸어주면 그냥 알아서 정리되지 않을까?
1 |
0 10 * * * ~/check_and_move_download_files.sh |
하악.. 이런거 보면.. 확장자 별 디렉토리 map 만들어서 for each 돌리고 싶은 욕구가…
ㅇㅇ 좀더 잘 만들수도 있을텐데, 귀차니즘이… 게다가 bash는 collection 없으니까. 역시 파이썬인가… 🙂
collection은 모르겠으나 map, foreach는 됨
https://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/
map도 되는구나… 하고 봤더니 bash 4.0 이상 지원이네!!
내가 쓰는 맥북은 bash가 3.x구만 🙂 (업데이트하라고 하겠지? 귀차늠)