Packaged
Tar
Cpio
Compression
Zip
bz2
Example:
① Batch compression script: tar-gzip-dir-rm.sh
Implementation features: Compressed directory under all folders for the same name packaging compressed files (tar.gz), compression after successful deletion;
Script code:
- #!/bin/bash
- For i in ' ls |grep-v tar.gz |grep ';d o
- Nice-n tar-cf $i. tar.gz-z $i && rm-rf $i
- # Nice worth reducing to prevent because the compression causes the server to be too jammed,
- Done
Script execution:
Nohup Bash tar-gzip-dir-rm.sh &
# The execution of the command is associated with terminal detachment (the execution environment is Xshell), preventing execution failures due to network or other unexpected conditions.
② in the log storage directory, each day will produce a log folder, require writing a cron file, to achieve automatic compression of log files, and delete the log folder
Implementation features: Automatically compress the log folder generated by the same name, compressed files, compressed successfully deleted the original folder;
Code:
- #cron –e
- # * * * * * * */bin/bash/path/to/tar-gzip-dir-rm.sh &>/dev/null
Shell-Packaging, compression, and decompression instructions summary