Advertisement
plirof2

bash compress large folder using HD space and NOT RAM.sh

Nov 6th, 2023 (edited)
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. #compress BIG folder using hard disk only (to avoid RAM limitations). This will be slow
  2. #!/bin/bash
  3. #apt install pigz
  4.  
  5. # Define the source directory and output archive file name
  6. SOURCE_DIR="/mnt/home/downloads_linux/path/to/source"
  7. OUTPUT_ARCHIVE="/mnt/home/downloads_linux/output.tar.gz"
  8.  
  9. # Define a temporary directory for storing intermediate files
  10. TMP_DIR="/mnt/home/downloads_linux/TEMP"
  11.  
  12. # Create the temporary directory if it doesn't exist
  13. mkdir -p "$TMP_DIR"
  14.  
  15. # Use tar and pigz to create a compressed archive
  16. tar -cf - "$SOURCE_DIR" | pigz -9 -p 4 > "$TMP_DIR/temp_archive.tar.gz"
  17.  
  18. # Move the temporary archive to the final destination
  19. mv "$TMP_DIR/temp_archive.tar.gz" "$OUTPUT_ARCHIVE"
  20.  
  21. # Remove the temporary directory
  22. rm -rf "$TMP_DIR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement