Linux Command extraction (Solaris)

Source: Internet
Author: User
Tags gz file unpack
In the Solaris environment,
Compress tar> compress Gzip
Decompress the package gzip> tar

. Tar
Unpack: Tar xvf filename.tar
Package: Tar CVF filename.tar dirname
(Note: tar is packed, not compressed !)

. GZ
Decompress 1: gunzip filename.gz
Decompress 2: gzip-D filename.gz
Compression: gzip filename.tar

.Tar.gz and. tgz
Decompress: Tar zxvf filename.tar.gz
Compression: Tar zcvf filename.tar.gz dirname

. Bz2
Decompress 1: Bzip2-D filename.bz2
Decompress 2: bunzip2 filename.bz2
Compression: Bzip2-Z filename

.Tar.bz2
Decompress: Tar jxvf filename.tar.bz2
Compression: Tar jcvf filename.tar.bz2 dirname

. Bz
Extract 1: Bzip2-D filename. bz
Decompress 2: bunzip2 filename. bz
Compression :...

. Tar. bz
Decompress: Tar jxvf filename.tar. bz
Compression :...

. Z
Decompress: uncompress filename. Z
Compression: compress filename

. Tar. Z
Decompress: Tar zxvf filename.tar. Z
Compression: Tar zcvf filename.tar. Z dirname

. Zip
Decompress: unzip filename.zip
Compression: Zip filename.zip dirname

. Rar
Decompress: RAR x filename.rar
Compression: rar a filename.rar dirname

RAR Please download to: http://www.rarsoft.com/download.htm!
After decompression, copy rar_static to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
# Cp rar_static/usr/bin/RAR

. LHA
Decompress: LHA-e filename. LHA
Compression: LHA-a filename. LHA filename

Lha please: http://www.infor.kanazawa-it.ac.jp /~ Ishii/lhaunix/download!
After decompression, copy LHA to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
# Cp LHA/usr/bin/

. Rpm
Unpack: rpm2cpio filename. RPM | cpio-Div

. Deb
Unpack: Ar P filename. Deb data.tar.gz | tar zxf-

. Tar. tgz .tar.gz. tar. z. tar. BZ .tar.bz2. zip. cpio. rpm. deb. SLP. ARJ. RAR. ace. lha. lzh. LZX. LZs. ARC. SDA. SFX. lnx. zoo. cab. kar. CPT. pit. sit. sea
Decompress: Sex x filename .*
Compression: Sex a filename. * filename

Sex only calls related programs and does not support compression or decompression. Please note!
For sex, go to http://sourceforge.net/projects/sexto download it!
After decompression, copy sex to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
# Cp sex/usr/bin/

Backup and recovery utility (Solaris)

Tar
Dd
Cpio
Pax

Tar -- create a tape and file archive to restore files and directories
The tar command can be found on many UNIX platforms. It is a quick and easy-to-use tool for archiving files to tapes. Tar can also be used to archive multiple files into one file (that is, the tar file) so that it can be transplanted to other systems for use. For example, if needed, you can copy the entire user's home directory or installation directory to a single tar file and move it to the server where the HP-UX is running, if necessary.

The tar command has many options available, but I will only discuss three options for creating, extracting, or restoring and list options for the tar file content.

Tar Command Option
-C: Create a tar file
-T: List tar content
-X: extract or restore the tar file content.
-V: verbose (display the action taken by tar)

The basic syntax of the tar command is as follows:
Tar <options >;< tar filename >;< file list>;
Note: Sometimes you will see in some tar command examples that a break number is used before the option, which is not required for the proper running of tar.
Create a new tar file:

% Tar
CVF filename.tar filelist
Here, filename.tar is the name of the TAR file. Filelist is the list of files to be backed up. You can use wildcards to specify a list.

List the contents of a tar file:
% Tar tvf filename.tar filelist
Here, filename.tar can be replaced by a tape device file. For example:
% Tar CVF filename.tar/dev/RMT/0mn

Extract the content of the TAR file to the current location:
% Tar xvf filename.tar

Dd -- convert and copy files
The DD command is usually used to copy the entire file system to another file system, or copy the content of the hard drive to another hard disk. Dd can also be used to copy a file system to a tape, or vice versa. Dd is a relatively fast replication tool: it creates a precise copy (byte-to-byte) for data transmission ). Dd can use several options to specify the buffer size, block size, and data conversion. The basic syntax is:

DD <inputfile >;=< outputfile >;= options

The following example copies the content of c0t1d0s2 to the second disk (c0t4d0s2). The block size is 128. If you have available disk space and want to prepare a backup disk for replacement in case of a disaster, this will work very well. Slice 2 is specified in this example because it represents the entire disk in the Solaris operating system.

% Dd If =/dev/rdsk/c0t1d0s2 of =/dev/rdsk/c0t4d0s2 BS = 128

To copy content from one tape device to another, use the command shown in the following example. (Note: You must have two available drives .)

% Dd If =/dev/RMT/#1 drive of =/dev/RMT/#2 drive
The man page for DD provides many other available options. I suggest you view the man page of DD and read the notes section. There, you will find some limitations of DD, as well as a prompt to use bare character devices when copying data from disk devices.

Cpio-import and copy an archive file
Cpio indicates "copy-in and copy-out", which is used to copy data from one location to another. Cpio is more advantageous than other UNIX utilities, including:
Cpio can back up and restore individual files, not just all file systems.
The file header information created by cpio on the file is small, resulting in fewer backups.
Tar is limited to a single tape device, and cpio is different. It can span multiple tapes.
Cpio runs in three modes: Copy-out (cpio-O), copy-in (cpio-I), and pass (cpio-P ), the last mode is used to copy files from one location on a disk (rather than a tape) to another location. The following section lists several common options.

Cpio Command Options
Unless otherwise specified, these options apply to copy-out and copy-in modes.

-C: Write header information in ASCII format for ease of transplantation.
-D: create the required directory.
-V: verbose (report file name during processing ).
-V: Same as the previous one, except for displaying a "." For each copied file.
-U: used for unconditional copying. Old files will not replace newer files.
-M: retain the modification time of the previous file. This option does not work when copying directories.

To copy a directory and Its subdirectories to a tape, use the following example:
% Ls-r | cpio-OVC>;/dev/RMT/0
The above example copies the current directory and all its subdirectories to the tape device at/dev/RMT/0. -O indicates that the file is in copy-out mode. The-V option indicates verbose and displays. As a progress indicator. -C option to create an ASCII header file.

To copy the content from the tape back to the directory, use the following example:
% Cpio-ICVD </dev/RMT/0

In the above example, our command will use multiple options to restore the data content on the tape. -I option to make the job in copy-in mode. -D option: create all required directories when copying data back.

Using cpio to back up files (copy-out mode)
There are multiple methods to back up files using cpio. Here I will introduce two of them.

% Cpio-ov list>;/dev/RMT/0
This command reads content from the file "list" and copies it to the tape device.

% Cpio-O/dev/RMT/0
This command allows you to specify the file to be backed up. After entering the file name, press Ctrl + D to execute the command. The following is an example:
% Cpio-o>;/dev/RMT/0
Filename.txt
File1name.txt

Use cpio to Restore Files (copy-in Mode)
The recovery process using cpio is similar to that of the backup file. Instead of using-O to specify the copy-out mode, we use-I mode to copy the data back from the tape.

% Cpio-icvum </dev/RMT/0
This example uses a similar option as previously used, and the-M option, which retains the modification time of the file.

Use the following example to view the content list on the tape archive:
% Cpio-ICT </dev/RMT/0

Pass Mode
The pass mode can be used to copy directories on disk devices. It will not work on tape. When you want to copy files and directories, cpio is better than CP because it retains the ownership and modification time of the files.

The following example copies all files and directories to a directory called bkup:

% Ls * | cpio-pdumv bkup

Pax-portable archive swapping (extracting, writing, and listing archive files)
Pax utilities can be found on many POSIX-Compatible UNIX systems. The Solaris operating system has been included since version 2.5. Pax is capable of reading and writing tar and cpio archives. Depending on how you choose to use Pax, it runs in one of four modes: read, write, list, and copy. To set the mode, you can use the combination of-R,-W, and the two, or you do not need any options at all.

Pax mode options
Option mode description
-R read single-r option is only read mode, which allows you to read files from disk or tape
If no-R or-W option is available, Pax is placed in list mode. It reads files from disks, tapes, or standard input devices and displays the file and directory hierarchies.
-W writes a single-W option to make Pax in write mode. It copies the current directory and all its subdirectories to an independent output device in the format specified by the-x option. (See the example below ). If no file is specified, you can read a list and a file at a time from the standard input device.
-During RW replication, both the-R and-W options are specified. The selected file is copied to the target directory.

Pax Command Options
Option description
-A attaches the file to the end of the previously written archive.
-B block size. The minimum block size is 512 bytes, or a larger block with an increment of 512, up to 32256 bytes
-C matches all files or archive members, except those specified by the pattern and file operations.
-F <archive>; Specify <archive> as the path name of the input or output file. An archive can span multiple devices. Pax indicates the path name of the next device in the archive.
-I: interactively rename a file or archive member. Used to provide a file name for optional write or copy through standard input
-P <string>; Specifies one or more file features used to extract or archive a file. Option A does not retain the file access time.
E keep everything: User ID, group ID, file mode bit, file access time, and modification time.
M does not retain the file modification time
O retain the user ID and group ID
P Reserved file pattern bit
V verbose mode

-X specifies the output archive format. The default format is USTAR. Pax supports cpio, tar, bcpio, USTAR, sv4crc, and sv4cpio.
Ufsdump command

For the system administrator, the ufsdump command is very useful and can be used to perform full or incremental dumping on the entire file system.
A full dump backs up the entire file system. It is performed at a long interval, for example, one week or one month.
Incremental dump backs up newly created or modified files. incremental dump is more frequent and may be performed once a day.

The ufsdump command provides dump of different levels, from 0 to 9. the dump level is used to determine which files are backed up. level 0 specifies full dump, and level 1 to 9 specifies incremental dump of different levels. for example, incremental dump (level 1) backs up the files modified or created after the previous low-level (level 0) dump. during file system backup, the system should be transferred to the running level S.

For example, when the system is running level 3, the file may be in use, which may result in invalid backup.

Example:

# Ufsdump 0 UF/dev/RMT/0/export/home

Options and parameters:
0
Specifies the level 0 (full) dump.

U
Update the/etc/dumpdates file to record the successful dump.

F
Together with the following/dev/RMT/0 parameters, determine the tape device to be dumped.
/Dev/RMT/0
Dump tape device.
/Export/home
Specifies the file system to be dumped.

Ufsrestore command
The ufsrestore command Copies files from the backup tape to the current directory.
The ufsrestore command can be used to reload the entire file system or one or more files on the backup.
The ufsrestore command is used to specify the tape device name and the path name of the recovered file.

Recovery Process
Use the ufsrestore command to restore an object by following these steps:
# Cd/newdir
# Ufsrestore Tuf/dev/RMT/0

Gzip command

Syntax: gzip [Option] compressed (decompressed) file name

The options of this command are as follows:

-C writes the output to the standard output and keeps the original file.
-D. decompress the compressed file.
-L the following fields are displayed for each compressed file:
Size of the compressed file; size of the uncompressed file; compression ratio; Name of the uncompressed File
-R recursively searches for the specified directory and compresses all the files or decompress the files.
-T test to check whether the compressed file is complete.
-V displays the file name and compression ratio for each compressed and decompressed file.
-Num: Use the specified numeric num to adjust the compression speed.-1 or -- fast indicates the fastest compression method (low compression ratio ),
-9 or -- best indicates the slowest compression method (high compression ratio ). The default value is 6.

E.g.

Gzip *
% Compress each file in the current directory into A. GZ file.

Gzip-DV *
% Decompress each compressed file in the current directory and list detailed information.

Gzip-L *
% Detailed information of each compressed file in Example 1 is displayed without decompression.

Gzip usr.tar
% Decompress the tar backup file usr.tar. the extension name of the compressed file is .tar.gz.

The tar in Solaris is not combined with gzip, unlike the Z command in Linux tar. If you want tar to be compressed or decompressed at the same time, you can write as follows:
Package Compression
Tar CVF-testfile | gzip> testfile.tar.gz
Unpack
Gunzip-C testfile.tar.gz | tar xvf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.