Linux Format

Keep files in order

-

The shell has various mechanisms to effectivel­y create compressed archives and backup files. Archiving is the process of gathering up many files and bundling them together into a single large file. The tar program is the classic tool for archiving files, e.g. the command tar cvf documents.tar Documents/ would archive the whole Documents directory inside a single file called documents.tar. Conversely, tar xvf / path/to/documents.tar will extract the contents of the archive under the current directory.

Once you’ve created an archive, you can also compress it before backing it up. The gzip program is used to compress one or more files. When executed, it replaces the original file with a compressed version of the original. The correspond­ing gunzip program is used to restore compressed files to their original, uncompress­ed form. The bzip2 program is similar to gzip, but uses a different compressio­n algorithm that achieves higher levels of compressio­n at the cost of compressio­n speed. A file compressed with bzip2 has the extension .bz2, e.g. the command bzip2 documents.tar would replace the documents.tar file with the documents.tar.bz2 file. Once you’ve rolled your files into an archive, you can use rsync to back them up to a different location. Rsync does more than make copies of your files. You can use it to sync files on two directorie­s on the same PC, on two different computers on the same network or on machines thousands of miles apart over the internet, e.g. This command will sync a single file ( backup.tar) on a local machine from one location to another location (/ tmp/backups/): $ rsync -vh backup.tar /tmp/backups/

The v option increases verbosity and h prints numbers in a human-readable format. You can as easily sync the file to a remote PC: $ rsync -zvh --progress backup.tar pi@192.168.3.101:/home/pi/backups/

The z option compresses the files before ferrying them and saves you bandwidth and time and --progress helps you track the transfer.

Newspapers in English

Newspapers from Australia