If you just want to release a few files from the archive file, you can use the w parameter again:
# tar xvwf
extract mydir/?y
mydir
extract mydir/file2?y
mydir/file2
extract mydir/mydir2/?y
mydir/mydir2/
extract mydir/mydir2/file21?y
mydir/mydir2/file21
extract mydir/mydir2/file23?y
mydir/mydir2/file23
The above example shows that the archive file was viewed and the file was released interactively. If you want to release only a file from the archive file, you can specify this file on the command line. As an example, I first deleted the original mydir subdirectory and then used an empty subdirectory to do the following:
# tar xf mydir/mydir2/file23
# tree mydir
m y d i r
- - mydir2
- - file23
1 directory, 1 file
Note that as seen, only one file is released. Although the tar command does not overwrite the entire subdirectory, it overwrites files with the same file name.
It is worth mentioning that other programs, such as BRU-2000 or tape script programs, can also be used to back up the system or selected files and subdirectories. OpenLinux operating system can also automatically archive and organize files through cron schedule.
Create cpio archive file
The cpio command can copy or copy files from tar or cpio archive files. Because the cpio command is compatible with the tar command, I will not go into details about how it works here. However, this command has some functions that the tar command does not have, as shown below:
◆ Supports two archive file formats: cpio and tar;
◆ Supports many old-fashioned tape data formats;
◆ The file name of the file can be read through a pipeline.
Only a few Linux packages are issued in cpio format. If you are interested in the details of the cpio command, you can read its user manual.
Use gzip to compress files
The gzip command is used to compress files. It can not only be used to compress large, less-used files to save disk space, but it can also form a more popular compressed file format in Linux operating systems with the tar command. According to statistics, the gzip command has a compression rate of 60% to 70% for text files.
The format of the gzip command is:
gzip [option] [file]
gzip is easy to use. If you want to compress a file or tape archive file, you can enter the following content:
# gzip
By default, gzip will compress the file, add a .gz extension, and then delete the original file. If you want to decompress the file, you can use gzip's corresponding program command gunzip or -d of the gzip command to decompress the parameters. However, it must be ensured that the file used for decompression has the .gz (or .Z, -gz, .z, -z, or _z) extension, otherwise the gzip command and the gunzip command will display error information. If you want to use your own extension, you can use the -S suffix parameter as follows:
# gzip -S .gzipped
gzip can also handle file packages compressed with zip commands, compress commands and pack commands. If you want to see more information during compression or decompression, you can use the -l column list parameter to see the file length of the file when it is compressed or decompressed. In the previous example, after compressing the subdirectory mydir, you can use the gzip command to obtain the relevant data according to the following method:
# gzip -l
compressed uncompressed_name
312 21330 98.2%
In addition, gzip also has a very useful parameter - t, which can be used to test the integrity of compressed files. If the file is normal, gzip will not give any display. If you want to see the two letters OK, you can use the -tv parameter when testing a file.
Use compress to compress files
The compress command is used to compress files just like its file name. This is a relatively early compression program in Unix that reduces the size of the referenced file by using adaptive Lemple-Ziv encoding. Each file will be replaced by a compressed file with the .Z extension, but the file's owner relationship, access time and modification time will remain the same. If there is no pointer file, the file that accepts standard input is compressed and sent to standard output.
The format of the compress command is:
compress [option] [file]
There is an uncompress command corresponding to compress, which is the format as follows:
uncompress [option] [file]
It restores the compressed file of ".Z".
The options for the compress and uncompress commands are as follows:
◆-c Write to standard output without changing the file.
◆-f Force compression, even if the file does not really decrease or the .Z file already exists, it will be compressed.
◆-v Displays the percentage of shrinking of each compressed file.
The following is an example to illustrate the usage of the compress command:
#compress file
The above code shows that a compressed file will be generated instead of a file, and the input to be decompressed:
#uncompress
Note that, like using the gzip command, a file name with the .Z extension must be given when using the uncompress command, otherwise the uncompress command will display an error message.
Previous page12Read the full text