Linux Learning notes----7

Source: Internet
Author: User
Tags rsync scp command ssh server

Archive files and copy files between systems

1. Managing Compressed TAR Archives

Archiving and compressing files is useful when you are creating backups and transferring data over the network. One of the most common commands used to create and use backup archives is the TAR command.

With other commands, users can set up large sets of files as a single file (archive). The archive can be compressed using gzip, bzip2, or XZ compression.

Manipulating the tar command

C Create a document

T list the contents of a document

X Extract Files

f filename Specifies the archive file name to manipulate

V details to see what files are added to or extracted from the archive

P Preserve File permissions

Note: The TAR option may not be used before-

The first option to use when creating a new archive is C, followed by F, then the file name of the archive to be created, and finally the list of files and directories that should be added to the archive. The archive is created in the current directory, unless otherwise specified.

Tar cf archive.tar file1 file2 file3

List Tar archive contents

Tar tf Archive.tar

Extract the archive created by tar

Tar Xf/home/lvyang/archive.tar


2. Create a compressed tar archive

The TAR command supports three different compression methods.

Z for gzip compression (suffix. tar.gz or. tgz) The fastest compression, most widely used

J for bzip2 compression (suffix. tar.bz2) smaller file generation

J used for XZ compression (suffix. tar.xz) is relatively new and usually provides the best compression ratio in the available mode

Example:

Tar czf/etc/etcbackup.tar.gz/etc compression

Tar xzf/etc/etcbackup.tar.gz Decompression

gzip, bzip2, XZ can also be used to compress individual files separately

Gzip/path/filename.tar.gz/path/filename

Corresponding decompression commands Gunzip, BUNZIP2, Unxz

Gunzip/path/filename.tar.gz


3. Securely copy files between systems

The SCP command transfers files from the remote host to the local, or vice versa. It leverages the SSH server for authentication and encrypted data transfer. The user must pass validation before initiating the transfer.

SCP file1 file2 [email protected]:/path copy files to a remote host

SCP [email protected]:/path/file/path copy files from remote host to local

To replicate recursively, you can use the-r option

Scp-f/home/lvyang [Email protected]:/home/james


Remotely transfer files using SFTP

Interactive tool, a session similar to a typical FTP session, but also a secure authentication and encrypted data transfer function using an SSH server

Establish an SFTP session

SFTP [email protected]

Prompt sftp>

The SFTP session accepts a variety of commands, running in the same way as the local system. Use the put and get commands for uploading and downloading files, using Exit to exit an SFTP session.

Example: Copy the local/etc/hosts to the 192.168.10.3/home/lvyang directory and then download it to the local current directory

SFTP [email protected]

Sftp>mkdir/home/lvyang

Sftp> Cd/home/lvyang

Sftp>put/etc/hosts

Sftp>get/home/lvyang/hosts


4, in the system between the security of synchronization files

The Rsync tool is another way to securely copy files between systems. It differs from the SCP in that, if two files or directories are similar between the two systems, rsync only needs to replicate the differences between the systems, and the SCP copies all the content

One of the most important options for rsync is the-n option, which is used to perform empty runs. Air Lines are simulations of what happens when a command is actually executed, and it is recommended that you perform an empty run before any rsync operation to ensure that important files are not overwritten or deleted.

-R to recursively synchronize the entire directory

-L Synchronous Symbolic link

-P Reserved Permissions

-T retention timestamp

-G reserved Group ownership

-O Keep File owner

-D Synchronizing device files

-V to add details to the output when synchronizing

-A represents the archive mode

Example

Rsync-av/var/log [email protected]:/tmp synchronizing the local log directory to an offsite/tmp

RAYNC-AV [email protected]:/var/log/tmp remote Log directory channel Local/tmp

Linux Learning notes----7

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.