BACKUPFILE=backup-$(date +%m-%d-%Y)
# Backup file name
tar cvf $BACKUPFILE.tar `find *.sh -mtime -1 -type f -print`
gzip $BACKUPFILE.tar
tarball은 일반적으로 tar 파일을 지칭하기도 하고, tar로 만든 뒤 압축한 파일을 의미하기도 한다.
위 코드는 find 명령어를 사용해 하루동안 변경된 sh파일을 모아 tar파일을 만든 뒤 압축하는 스크립트.
역시 백업할 때 유용하다.
깃허브 주소:
https://github.com/binary-river/prsh/blob/master/tarball.sh
GitHub - binary-river/prsh: shell practices
shell practices. Contribute to binary-river/prsh development by creating an account on GitHub.
github.com
find 명령어는 man page를 참조하는 것도 좋지만, 역시 한국인이니까.. 아래 블로그에서 읽어보는 것을 추천한다.
https://recipes4dev.tistory.com/156
리눅스 find 명령어 사용법. (Linux find command) - 리눅스 파일 검색.
1. find 명령어. find는 리눅스에서 파일 및 디렉토리를 검색할 때 사용하는 명령입니다. 이름 그대로 리눅스에서 접근할 수 있는 파일 시스템에서, 파일 및 디렉토리를 "찾는(find)" 것이죠. 그런데
recipes4dev.tistory.com
'CS > Script' 카테고리의 다른 글
[Shell] 현재시간을 이용하여 파일명 설정 (0) | 2021.10.30 |
---|