Archiving and Compression ========================= Archiving is the process of combining multiple files and directories into one file. compression is the process of reducing the size of a file (or an archived directory). Here's an article touching on all of this in depth. https://www.linuxjournal.com/article/9370 tar and gzip options and examples --------------------------------- `tar [options] [archive-file] [file or directory to be archived]` * -c : Creates Archive * -x : Extract the archive * -f : creates archive with given filename * -t : displays or lists files in archived file * -u : archives and adds to an existing archive file * -v : Displays Verbose Information * -A : Concatenates the archive files * -z : zip, tells tar command that create tar file using gzip * -j : filter archive tar file using tbzip * -W : Verify a archive file * -r : update or add file or directory in already existed .tar file .. code-block:: bash # piping data (text or chars) through gzip, and reverse echo "hello world" | gzip -c > file.gz ; cat file.gz | gzip -d -c zcat file.gz # is a shorthand for this cat file.gz | gzip -d -c gunzip file.gz # this command does stuff in-place # creat a tar.gz file tar -f /bits/data/logs.tar.gz -czv /bits/data/logs # extract a tar.gz gile tar -xzf logs.tar.gz # download file with a specified name wget -O drupal.tar.gz https://www.drupal.org/download-latest/tar.gz tar -xzvf drupal.tar.gz # list contents of an archive tar -tvf drupal.tar.gz drupname=$(tar -tf drupal.tar.gz | head -n 1 | sed 's/.$//') Drupal Update process --------------------- .. code-block:: bash # download file with a specified name wget -O drupal.tar.gz https://www.drupal.org/download-latest/tar.gz tar -xzvf drupal.tar.gz # list contents of an archive, not tar -tvf drupal.tar.gz drupbase=/home/mk/drupal cd $drupbase time_stamp=$(date +%s) mv drupal drupal_back_$time_stamp filename=drupal_$time_stamp.tar.gz wget -O $filename https://www.drupal.org/download-latest/tar.gz drupname=$(tar -tf $filename | head -n 1 | sed 's/.$//') tar -xzf $filename mv $drupname drupal Other Tricks ------------ When creating backup you can include datetime (date time) stamp (timestamp) in the filename .. code-block:: bash pg_dump -h nuc -U redmine redmine > /bits/data/backup/redmine$(date +%s).sql