ARCHIVING
1. The Tar Command
File archiving and compression are used when backing up and transferring data over certain networks. One command that is often used is to use the "tar" command. With the tar command, users can collect large files into one file or called an archive. The archive can be compressed using gzip, bzip2, or xz compression.
2. Tar Options
-c, --create
-> to creates a new archive.
-x, --extract
-> to extract from an existing archive.
-t, --list
-> to list an archive's content.
-u, --update
-> to update the existing files in the archive with a newer version.
-r, --append
-> to appends files to an existing archive.
--delete
-> to deletes a member from the archive.
-v, --verbose
-> to shows which files get archived or extracted.
-f, --file=
-> to specifies the file or
specifying filename as archive argument to operate.
-p, --preserve-permissions
-> to control file permissions with tar when extracting an archive.
-z, --gzip
-> to use gzip compression (.tar.gz)
-j, --bzip2
-> to use bzip2 compression (.tar.bz2)
-J, --xz
-> to use xz compression (.tar.xz)
3. Tar Command Syntax and Example
a. Create a tar Archive
To make a tar archive, use :
tar -cf <archive name>.tar file
- For example, create an archive named agung.tar with the contents of biodata in the user's home directory :
[user@host ~]$tar -cf agung.tar biodata
b. Extracting Files from an Archive
For extracting from a tar archive use :
tar -xf <archive name>.tar
- For example, create an archive named myAddress.tar, then extract it in the Address directory as content as user root :
[root@host ~]# mkdir Address
[root@host ~]# cd Address
[root@host Address]# tar -xf myAddress.tar
c. Creating a Compressed Archive
To create a tar.gz Compressed Archive, use :
tar czf <archive name>.tar.gz <file or location>
- For exmple, create a gzip compressed archive named agung.tar.gz, with the contents from the alamat directory on host :
[root@host ~]# tar -czf agung.tar.gz alamat
tar: Removing leading `/' from member names
d. List Archive Contents
Use the following command to list an archive's contents :
tar -tf files.tar.gz
- For example, list the files and directories in the files.tar archive :
[root@host ~]#tar tf files.tar.gz
files
files/file1.txt
files/file2.txt
files/file3.txt
TRANSFERRING FILES
1 . Transferring Files Using (SCP)
SCP DEFINITION
SCP (Secure Copy Protocol) is the command line used to securely copy files and directories between two locations. SCP protects your data while copying across an SSH (Secure Shell) connection by encrypting the files and the passwords. Therefore, even if the traffic is intercepted, the information is still encrypted.
Use SCP when :
a. Copying files from a local host to a remote host.
- For example, to copy contoh files from local host to remote server, you use:
scp Desktop/contoh.txt root@146.174.142.28:/home/tugas_agung
- Desktop/contoh.txt -the name of the file being copied and its location.
- root@146.174.142.28 - the username and IP address of the remote server.
- /home/tugas_agung βthe location where to store the copied file.
b. Copying files from a remote host to a local host.
- For example, to copy a contoh file from a remote host to a local host, you use :
scp 147.182.143.27:/home/tugas_agung/contoh.txt home/tugas
- root@147.182.143.27 -the username and IP address of the remote server from where the file is currently located.
- /home/tugas_agung/contoh.txt -the name of the file being copied and its location.
- home/tugas βthe location where to store the copied file.
c. Copy a File from One Remote Server to Another
- For example, to copy a file from one remote server to another remote server using the scp command :
scp root@147.182.143.27:/home/tugas_agung/contoh.txt looctos@146.153.129.25:home/tugas
- root@147.182.143.27 -the username and IP address of the remote server from where the file is currently located.
- /home/tugas_agung/contoh.txt -the name of the file being copied and its location.
- looctos@146.153.129.25 -the username and IP address of the remote server where we want to copy the file.
- home/tugas βthe location where to store the copied file on the remote server.
2. Transferring Files Using (SFTP)
SFTP DEFINITION
SFTP (Secure File Transfer Protocol) is a file transfer protocol that uses SSH encryption to transfer files between systems securely.
Example to Transfer Files Using SFTP
a. Transfer Remote Files to a Local System
Note
Use the get command in the SFTP interface to transfer a file from a remote server to your local system:
get [path to file]
b. Transfer Local Files to a Remote Server
Note
To transfer files from a local system to a remote server, use the put command. The put command uses the same syntax and options as the get command.
put [path to file]
THAT'S ALL FROM ME, THANKS
Top comments (0)