Compressing Files
- Lossless. Lossless compression preserves all the data contained in the original. This means that when a file is restored from a compressed version, the restored file is exactly the same as the original, uncompressed version.
- Lossy. Lossy compression, on the other hand, removes data as the compression is performed to allow more compression to be applied. When a lossy file is restored, it does not match the original version; rather, it is a close approximation. Examples of lossy compression are JPEG (for images) and MP3 (for music).
gzip gunzip
gzip, gunzip, zcat - compress or expand files
| Option | Long option | Description |
|---|---|---|
| -c | —stdout —to-stdout |
Write output to standard output and keep the original files. |
| -d | —decompress —uncompress |
Decompress. This causes gzip to act like gunzip. |
| -f | —force | Force compression even if a compressed version of the original file already exists. |
| -h | —help | Display usage information. |
| -l | —list | List compression statistics for each file compressed. |
| -r | —recursive | If one or more arguments on the command line is a directory, recursively compress files contained within them. |
| -t | —test | Test the integrity of a compressed file. |
| -v | —verbose | Display verbose messages while compressing. |
| -number | Set amount of compression. number is an integer in the range of 1 (fastest, least compression) to 9 (slowest, mostcompression). The values 1 and 9 may also be expressed as —fast and —best, respectively. The default value is 6. |
gunzip -c foo.txt.gz = zcat foo.txt.gzgunzip -c foo.txt.gz | less = zless foo.txt.gz
bzip2 bunzip2 bzcat bzip2recover
bzip2, bunzip2 - a block-sorting file compressor
bzcat - decompresses files to stdout
bzip2recover - recovers data from damaged bzip2 files
Archiving Files
tar
- .tar Indicates a “plain” tar archive
- .tgz Indicates a gzipped archive
mode
cCreate an archive from a list of files and/or directories.xExtract an archive.- If we are operating as the superuser, files and directories extracted from archives take on the ownership of the original owner, otherwise the user performing the restoration.
rAppend specified pathnames to the end of an archive.tList the contents of an archive.options
zEnable gzipjEnable bzip2vVerbosef FILENAMESpecify file name of the tar archivecf -将结果输出至 stdoutxf -从 stdin 提取内容
--wildcardsEnable pathnames wildcards-T, --files-from=FILENAMERead pathnames from a file rather than the command line--files-from=-从 stdin 里读取 pathnamesexamples
find playground -name 'file-A' | tar cf - --files-from=- | gzip > playground.tgzfind playground -name 'file-A' | tar czf playground.tgz -T -find playground -name 'file-A' | tar cjf playground.tbz -T -ssh remote-sys 'tar cf - Documents' | tar xf -
The zip program is both a compression tool and an archiver.zipzip options zipfile file...omitted~rsyncSynchronizing Files and Directoriesrsync options source[/] destination
where source and destination are one of the following:
- A local file or directory
- A remote file or directory in the form of [user@]host:path
- A remote rsync server specified with a URI of rsync://[user@]
host[:port]/path
Note that either the source or the destination must be a local file. Remote-to-remote copying is not supported.
source后面如果跟了/,那么只同步source目录里的文件,而不包括source本身
options
aarchiving, recursion and preservation of file attributesvverbose output--deletedelete extraneous files fromdestinationdirs-e, --rsh=COMMANDchoose an alternative remote shell programLocal
```bash $ rsync -av playground foo $ ls foo playground
$ rsync -av playground/ foo # Note the trailing / $ ls foo file1.txt file2.txt
$ mkdir /media/BigDisk/backup $ sudo rsync -av —delete /etc /home /usr/local /media/BigDisk/backup
$ alias backup=’sudo rsync -av —delete /etc /home /usr/local /media/BigDisk/backup’
<a name="qpKyK"></a>### Remote```bash$ sudo rsync -av --delete --rsh=ssh /etc /home /usr/local remote-sys:/backup$ rsync -av –delete rsync://archive.linux.duke.edu/fedora/linux/development/rawhide/Everything/x86_64/os/ fedora-devel
