Archiving and Transferring Files: The Option Directs Tar To List The Contents (Table of Contents, Hence) of The Archive
Archiving and Transferring Files: The Option Directs Tar To List The Contents (Table of Contents, Hence) of The Archive
The following command creates an archive named archive.tar with the contents of file1,
file2, and file3 in the user's home directory.
The t option directs tar to list the contents (table of contents, hence t) of the archive.
By default, when files get extracted from an archive, the umask is subtracted from the
permissions of archive content. To preserve the permissions of an archived file, the p option
when extracting an archive.
List :-
Extract :-
The following example demonstrates how to copy the local /etc/yum.conf and /etc/hosts
files on host, to the remoteuser's home directory on the remotehost remote system:
You can also copy a file in the other direction, from a remote system to the local file system.
In this example, the file /etc/hostname on remotehost is copyed to the local directory
/home/user. The scp command authenticates to remotehost as the user remoteuser.
To copy a whole directory tree recursively, use the -r option. In the following example, the remote
directory /var/log on remotehost is copied recursively to the local directory /tmp/ on host.
To interactively upload or download files from a SSH server, use the Secure File Transfer
Program, sftp. A session with the sftp command uses the secure authentication mechanism
and encrypted data transfer to and from the SSH server.
Just like the scp command, the sftp command uses [user@]host to identify the target system
and user name.
The interactive sftp session accepts various commands that work the same way on the remote file
system as they do in the local file system, such as ls, cd, mkdir, rmdir, and pwd. The put command
uploads a file to the remote system. The get command downloads a file from the remote system.
The exit command exits the sftp session.
To upload the /etc/hosts file on the local system to the newly created directory
/home/remoteuser/hostbackup on remotehost. The sftp session always assumes that the
put command is followed by a file on the local file system and starts in the connecting user's
home directory; in this case, /home/remoteuser:
To download /etc/yum.conf from the remote host to the current directory on the local
system, execute the command get /etc/yum.conf and exit the sftp session with the exit
command.
Use the scp command to recursively copy the /etc/ssh directory from serverb to the
/home/student/serverbackup directory on servera.
You can use rsync to synchronize the contents of a local file or directory with a file or directory on a
remote machine, using either machine as the source. You can also synchronize the contents of two
local files or directories.
For example, to synchronize contents of the /var/log directory to the /tmp directory:
A trailing slash on the source directory synchronizes the content of that directory without
newly creating the subdirectory in the target directory. In this example, the log directory is
not created in the /tmp directory, only the content of /var/log/ is synchronized into /tmp.
Like the scp and sftp commands, rsync specifies remote locations using the [user@]host:/path
format. The remote location can be either the source or destination system, but one of the two
machines has to be local.
In the same way, the /var/log remote directory on remotehost can be synchronized to the
/tmp local directory on host:
Use the rsync command to synchronize the /var/log directory tree on serverb to the
/home/student/serverlogs directory on servera. Note that only the root user can read all
the content in the /var/log directory on serverb. All files are transferred in the initial
synchronization.
As root on serverb, execute the logger "Log files synchronized" command to get a new
entry in the /var/log/messages log file to reflect when the last synchronization took place.