0% found this document useful (0 votes)
25 views

12.1 Archive and Copy Files Between Systems

The document discusses various methods for archiving, compressing, and copying files between systems in Linux. It describes how to create archive files using the tar command, compress archives using gzip, bzip2, and xz, and extract compressed archives. It also explains how to securely copy files between systems using SCP, SFTP, and Rsync, providing examples of common commands and options.

Uploaded by

amit_post2000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

12.1 Archive and Copy Files Between Systems

The document discusses various methods for archiving, compressing, and copying files between systems in Linux. It describes how to create archive files using the tar command, compress archives using gzip, bzip2, and xz, and extract compressed archives. It also explains how to securely copy files between systems using SCP, SFTP, and Rsync, providing examples of common commands and options.

Uploaded by

amit_post2000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Archive and Copy Files Between Systems:

It is useful to store a group of files in one file for easy backup, for transfer to another directory,
or for transfer to another computer. An archive file is a collection of files and directories stored
in one file. Linux offers a rich set of protocols you can use to copy files between computers such
as scp, sftp and rsync.

Archive Files:
An archive file is a collection of files and directories that are stored in one file. The archive file is
not compressed it uses the same amount of disk space as all the individual files and directories
combined. A compressed file is a collection of files and directories that are stored in one file
and stored in a way that uses less disk space than all the individual files and directories
combined. An archive file is not compressed, but a compressed file can be an archive file.

Tar Command:
Tar stand for Tape Archiver. The tar program is used to create, maintain, modify, and extract
files that are archived in the tar format. This is a good way to create backups and archives. The
tar command does not compress the files by default. Archiving and compressing files are useful
when creating backups and transferring data across a network. A leading - is not required for
tar options it can work with - or without -.
Compression Tools:
The Archive can be compressed using compression tools gzip, bzip2, or xz. Gzip compression is
most frequently used to create (.tar.gz) or (.tgz) files, tar command also supports bzip2 and xz
compression. This allows you to create bzip2-compressed files, often named (.tar.bz2), (.tar.bz),
or (.tbz) files. The xz compressed files, named (.tar.xz). To do so, just replace the -z for gzip in
the commands here with a -j for bzip2 and -J for xz. Gzip is faster, but it generally compresses a
bit less, so the get larger file. Bzip2 is slower, but it compresses a bit more, so get a smaller file.
Tar's Options Description
-c Create a new archive (Create)
-j Compress the tar file with bzip2
-z Compress the tar file with gzip
-J Compress the tar file with xz
-x Extract files from an archive (Extract)
-v Displays Verbose Information (Verbose)
-t Lists the contents of an archive (Contents)
-f File name of the archive to work on (File Name)
-u Archives and adds to an existing archive file
-A Concatenates the archive files
-w Verify an archive file.
-C Change the extracted files Location (Change)

1 | P a g e Created by Ahmad Ali E-Mail: [email protected] , Mobile# +966-564303717


Tar Commands Description
# tar -cvf filename.tar File Create archive for one file
# tar -cvf filename.tar File1 File2 File3 Create archive for more than one files
# tar -cvf filename.tar dir1 Create archive for directory
# tar cvf archive.tar file1 file2 Create archive without using – dash
# tar -c -f archive.tar file1 file2 Different way to create archive for files
# tar -tvf filename.tar To list the contents of a tar file
# tar -xvf filename.tar To extract the contents of a tar file
# tar -xzvf filename.tar.gz -C /tmp Extract files to a specific directory or path
# tar -cjvf filename.tbz2 file Create bzip2 compressed tar file
# tar -xjvf filename.tbz2 Extract bzip2 compressed tar file
# tar -czvf filename.tgz file Create gzip compressed tar file
# tar -xzvf filename.tgz Extract gzip compressed tar file
# tar -cJvf filename.txz file Create xz compressed tar file
# tar -xjvf filename.txz Extract xz compressed tar file
Compression Tool Explanation
# gzip file.text Compressed file with gzip
# gunzip file.text.gz Extract file with gunzip
# bzip2 file.text Compressed file with bizp2
# bunzip2 file.text.bz2 Extract file with bunzip2
# xz file.text Compressed file with xz
# unxz file.text.xz Extract file with unxz

Copying Files:
Either a live or home server, moving files between local machines or two remote machines is a
basic requirement in Linux. There are many ways to achieve that such as SCP, SFTP and Rsync.

SCP to Copying Files:


SCP (Secure Copy) is based on SSh (Secure Shell) and SCP is used to transfer file from local host
to remote host securely. It utilizes the SSH server for authentication and encrypted data
transfer. Basic syntax of SCP:
scp source_file_name username@destination_host:destination_folder
Commands Description
# scp ali.txt [email protected]:./Desktop Transfer file remote user ahmad and ip
# scp -v ali.txt [email protected]:. Provide the detail information (Verbose)
# scp -p ali.txt [email protected]:~ An estimated time & the connection speed
# scp -r ali.txt [email protected]:~ Copy directory & files inside directory
# scp f1.txt f2.txt [email protected]:~ Transfer multiple files to user home directory
# scp -C f1.txt f2.txt [email protected]:~ Compress files on the go (Compress)

2 | P a g e Created by Ahmad Ali E-Mail: [email protected] , Mobile# +966-564303717


SFTP to Copy Files:
SFTP, which stands for SSH File Transfer Protocol, or Secure File Transfer Protocol, is a
separate protocol packaged with SSH that works in a similar way over a secure connection. It is
a command-line program for transferring files securely over a network connection. Unlike the
Secure Copy Protocol (SCP), SFTP additionally provides remote file system management
functionality, allowing applications to resume interrupted file transfers, list the contents of
remote directories, and delete remote files.

Commands Description
# sftp username@hostname To connect to remote host
# sftp [email protected] to connect to remote host through IP address
sftp> get remote-File Download file from remote server
sftp> get remote-File local-file Save remote server file with different name
sftp> get -r some-Directory Copy the folder and all its contents
sftp> put local-File Transfer files to the remote server
sftp> get -r Local-Directory Transfer folder to the remote server
sftp> cd Change the directory on the remote host
sftp> lcd Change the directory on the local host
sftp> pwd To check Remote server working directory
sftp> lpwd To check the Local present working directory
sftp> mget *.txt Download multiple files from remote server
sftp> mput *.txt Upload multiple files to remote server
Sftp> help or ? To get sftp commands help
Sftp> bye OR quit OR exit To exit from SFTP prompt

Rsync to Copy Files:


Rsync (Remote Sync) is a most commonly used command for copying and synchronizing files
and directories remotely as well as locally in Linux systems. With the help of rsync command
you can copy and synchronize your data remotely and locally across directories, across disks
and networks, perform data backups and mirroring between two Linux machines.
# rsync options source destination
-z Compress file data -h Human-Readable -r Recursive for folder
-v Verbose -a Archive Mode -n Perform a trial run

Commands Description
# yum install rsync Command to install Rsync
# rsync -zvh backup.tar /tmp/backups/ Copy & sync a file on local computer
# rsync -avzh /root/test /tmp/backups/ Copy & sync a folder on local computer
$ rsync -avz data/ [email protected]:/home/ Copy files from local to remote host
$ rsync -avz [email protected]: data/ /temp/bk Copying files from remote host to local

3 | P a g e Created by Ahmad Ali E-Mail: [email protected] , Mobile# +966-564303717

You might also like