45 일보다 오래된 파일을 찾아서 압축하여 보관 폴더로 이동하고 원본 파일을 삭제해야합니다.파일 찾기, 압축 해제 및 다른 위치로 이동, 원본 파일 삭제
find . -name '*.dat' -exec zip '{}.zip' '{}' ';' -exec mv '{}' ~/archive/ \;
위의 명령은 작동하지만 원본 파일은 여전히 폴더에 있습니다. 위의 명령
-m --move Move the specified files into the zip archive; actually, this deletes the target directories/files after making the specified zip archive. If a directory becomes empty after removal of the files, the directory is also removed. No deletions are done until zip has created the archive without error. This is useful for conserving disk space, but is potentially dangerous so it is recommended to use it in combination with -T to test the archive before removing all input files.
왜 멋진 스크립트를 만들지 않습니까? –
다른 유스 케이스로 파일을 정리하는 스크립트가 있고 대부분이 하나의 라이너입니다. 그래서 저는 find를 사용하여 모든 것을 한 줄에 넣으려고 노력할 것입니다. – coolnags
스크립트 내에서 함수를 만들 수 있습니다. 그 함수를 호출하는 것도 1 행입니다. –