Friday, January 1, 2016

RHEL7 tar,rsync and SCP examples

[root@new-host-4 ~]# cat myetc2.txt>>myetc.txt
[root@new-host-4 ~]# ls -lh
total 58M
-rw-------. 1 root root 1.5K Dec 27 14:23 anaconda-ks.cfg
dr-xr-xr-x. 8 root root 2.0K Dec  9 18:14 cdrom
-rw-------. 1 root root 1.5K Dec 28 15:44 initial-setup-ks.cfg
-rw-r--r--. 1 root root  13M Jan  1 22:38 myetc1.txt
-rw-r--r--. 1 root root  13M Jan  1 22:38 myetc2.txt
-rw-r--r--. 1 root root  20M Jan  1 22:39 myetc.txt
drwxr-xr-x. 3 root root   16 Dec 28 17:19 sam
[root@new-host-4 ~]# tar -czvf compress.tat.gz myetc1.txt myetc2.txt myetc.txt
myetc1.txt
myetc2.txt
myetc.txt
[root@new-host-4 ~]# tar -czvf compress.tar.bz2 myetc1.txt myetc2.txt myetc.txt
myetc1.txt
myetc2.txt
jmyetc.txt
[root@new-host-4 ~]# tar -cjvf compress.tar.bz2 myetc1.txt myetc2.txt myetc.txt
myetc1.txt

^C
[root@new-host-4 ~]# rm compress.tar.bz2
rm: remove regular file âcompress.tar.bz2â? y
[root@new-host-4 ~]# tar -cjvf compress.tar.bz2 myetc1.txt myetc2.txt myetc.txt
myetc1.txt




^C
[root@new-host-4 ~]# tar -cJvf compress.tar.xz myetc1.txt myetc2.txt myetc.txt
myetc1.txt
myetc2.txt
myetc.txt
[root@new-host-4 ~]# tar -cjvf compress.tar.bz2 myetc1.txt myetc2.txt myetc.txt
myetc1.txt
myetc2.txt
myetc.txt
[root@new-host-4 ~]#






[root@ashok ~]# pwd
/root
[root@ashok ~]# ls -ltr
total 33638
dr-xr-xr-x. 8 root root     2048 Dec  9 18:14 cdrom
-rw-------. 1 root root     1474 Dec 27 14:23 anaconda-ks.cfg
-rw-------. 1 root root     1499 Dec 28 15:44 initial-setup-ks.cfg
drwxr-xr-x. 3 root root       16 Dec 28 17:19 sam
-rw-r--r--. 1 root root 13424400 Jan  1 22:38 myetc1.txt
-rw-r--r--. 1 root root     5100 Jan  1 22:38 myetc2.txt.xz
-rw-r--r--. 1 root root 20136600 Jan  1 22:39 myetc.txt
-rw-r--r--. 1 root root   513080 Jan  1 22:40 compress.tar.gz
-rw-r--r--. 1 root root    10200 Jan  1 22:42 compress.tar.xz
-rw-r--r--. 1 root root   328309 Jan  1 22:44 compress.tar.bz2

[root@ashok ~]# chmod 777 initial-setup-ks.cfg
[root@ashok ~]# scp initial-setup-ks.cfg kamal@192.168.10.110:/var/tmp
The authenticity of host '192.168.10.110 (192.168.10.110)' can't be established.
RSA key fingerprint is c4:dd:1b:00:b0:91:28:b4:83:14:0d:55:be:8f:4f:0a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.110' (RSA) to the list of known hosts.


kamal@192.168.10.110's password:
initial-setup-ks.cfg                                      100% 1499     1.5KB/s   00:00
[root@ashok ~]# scp initial-setup-ks.cfg kamal@192.168.10.110:/var/tmp^C
[root@ashok ~]# ls -l /var/tmp/initial-setup-ks.cfg
ls: cannot access /var/tmp/initial-setup-ks.cfg: No such file or directory
[root@ashok ~]# scp kamal@192.168.10.110:/var/tmp/initial-setup-ks.cfg /var/tmp

kamal@192.168.10.110's password:
initial-setup-ks.cfg                                      100% 1499     1.5KB/s   00:00
[root@ashok ~]# ls -l /var/tmp/initial-setup-ks.cfg
-rwxr-xr-x. 1 root root 1499 Jan  1 22:51 /var/tmp/initial-setup-ks.cfg
[root@ashok ~]#






for directory, use -r option
$ scp source_file user@destination_location
$ scp -r source_dir user@destination_dir

$ scp user@remote_source_file local_location
$ scp -r user@source_dir local_destination_dir


[root@ashok ~]# scp initial-setup-ks.cfg kamal@192.168.10.110:/var/tmp
[root@ashok ~]# scp kamal@192.168.10.110:/var/tmp/initial-setup-ks.cfg /var/tmp



using scp

[root@ashok ~]# sftp kamal@192.168.10.110

kamal@192.168.10.110's password:
Connected to 192.168.10.110.
sftp> pwd
Remote working directory: /home/kamal
sftp> mkdir ashok
sftp> mput *.cfg
Uploading anaconda-ks.cfg to /home/kamal/anaconda-ks.cfg
anaconda-ks.cfg                                           100% 1474     1.4KB/s   00:00
Uploading initial-setup-ks.cfg to /home/kamal/initial-setup-ks.cfg
initial-setup-ks.cfg                                      100% 1499     1.5KB/s   00:00
sftp> cd ashok
sftp> pwd
Remote working directory: /home/kamal/ashok
sftp> lcd
You must specify a path after a lcd command.
sftp> ls -l
sftp> ls -la
drwxrwxr-x    2 kamal    kamal        4096 Jan  1 22:58 .
drwx------   69 kamal    kamal        4096 Jan  1 22:58 ..
sftp> mput *.cfg
Uploading anaconda-ks.cfg to /home/kamal/ashok/anaconda-ks.cfg
anaconda-ks.cfg                                           100% 1474     1.4KB/s   00:00
Uploading initial-setup-ks.cfg to /home/kamal/ashok/initial-setup-ks.cfg
initial-setup-ks.cfg                                      100% 1499     1.5KB/s   00:00
sftp> ls
anaconda-ks.cfg        initial-setup-ks.cfg
sftp> ls -l
-rw-------    1 kamal    kamal        1474 Jan  1 22:59 anaconda-ks.cfg
-rwxrwxr-x    1 kamal    kamal        1499 Jan  1 22:59 initial-setup-ks.cfg
sftp> exit

#

to get a file
sftp> lcd /var/tmp
sftp> get anaconda-ks.cfg
sftp> exit



using rsync


$ rsync sourcefile user@destination_server:/location

$ rsync user@remote_server_sourcefile local_location

[root@ashok ~]# rsync -av compress.tar.gz compress.tar.bz2 myetc2.txt.xz anaconda-ks.cfg newcom.tar.xz kamal@sama.expanor.local:/var/tmp/myrsync



No comments:

Post a Comment