> For the complete documentation index, see [llms.txt](https://alicenab.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alicenab.gitbook.io/linux/redhat/redhat-administration-1-rh124/chapter-13.md).

# Chapter 13

## ARCHIVING AND TRANSFERRING FILES

By default tar command is not storing extended attributes (SELinux permissions), to store them, you must use `--xattr` option.

```
# to archive files with extended attributes use --xattr option:
tar --xattr -cvf archive.tar file1 file2 file3
# -c for          : archive.tar
# -z or --gzip    : archive.tar.gz or archive.tgz
# -j or --bzip2   : archive.tar.bz2
# -J or -xz       : archive.tar.xz


# to list files in archive file use -t option:
tar -tf archive.tar

# to extract tar file use -x option:
tar -xvf archive.tar
```

## TRANSFERRING FILES BETWEEN SYSTEMS SECURELY

remote system to local system:

```
scp -r username@remotehost:/remote/directory/path localFolder
```

local system to remote system:

```
scp -r localFolder username@remotehost:/remote/directory/path
```

## TRANSFERRING FILES USING THE SECURE FILE TRANSFER PROGRAM

```
sftp remoteuser@remotehost
mkdir remoteFolder
cd remoteFolder
put /etc/hosts    # upload hosts file to remote
get /etc/yum.conf # download yum.conf from remote
exit
```

## SYNCHRONIZING FILES BETWEEN SYSTEMS SECURELY

```
rsync -av root@serverb:/var/log ~/serverlogs

# it can also be used for syncronizing local directories:
rsync -av /var/log /tmp
```

|                 |                                                  |
| --------------- | ------------------------------------------------ |
| -v, --verbose   |                                                  |
| -A              | to preserve ACLs                                 |
| -X              | to preserve SELinux contexts                     |
| -a, --archive   | APPLIES ALL OPTIONS DOWN BELOW:                  |
| -r, --recursive | synchronize recursively the whole directory tree |
| -l, --links     | synchronize symbolic links                       |
| -p, --perms     | preserve permissions                             |
| -t, --times     | preserve time stamps                             |
| -g, --group     | preserve group ownership                         |
| -o, --owner     | preserve the owner of the files                  |
