archive

2
Archive and compress lab Lab1 Purpose: Use tar to create and compress archives, as well as for listing contents and extracting files. Procedure: Create some files in /root/archive folder. Use dd and copy. [root@centos63 archive]# ls -lh total 21M -rwxr-xr-x. 1 root root 86K Nov 18 13:05 bc -rw-r--r--. 1 root root 20M Nov 18 13:06 zeroes To create a simple archive: [root@centos63 ~]# tar -cvf archive.tar archive/ Create archive and add gzip compression: [root@centos63 ~]# tar -czvf archive.tar.gz archive/ Archive with bzip2 compression: [root@centos63 ~]# tar -cjvf archive.tar.bzip2 archive/ Note that the simple .tar file is uncompressed. [root@centos63 ~]# ls -l | grep arch drwxr-xr-x. 2 root root 4096 Nov 18 13:05 archive -rw-r--r--. 1 root root 21063680 Nov 18 13:07 archive.tar -rw-r--r--. 1 root root 64164 Nov 18 13:08 archive.tar.gz To extract the entire content of any archive uze x flag. [root@centos63 tmp]# tar -xvf archive.tar.gz List contents with t: [root@centos63 tmp]# tar -tvf archive.tar drwxr-xr-x root/root 0 2012-11-18 13:05 archive/ -rw-r--r-- root/root 20971520 2012-11-18 13:06 archive/zeroes -rwxr-xr-x root/root 87840 2012-11-18 13:05 archive/bc Extracting specific files from one archive requires adding paths (relative to archive) to those files as arguments to tar: [root@centos63 tmp]# tar -xvf archive.tar archive/bc archive/bc

Upload: florinn81

Post on 10-Feb-2016

214 views

Category:

Documents


0 download

DESCRIPTION

creare arhivelor in linux

TRANSCRIPT

Archive and compress lab

Lab1 Purpose: Use tar to create and compress archives, as well as for

listing contents and extracting files.

Procedure:

Create some files in /root/archive folder. Use dd and copy.

[root@centos63 archive]# ls -lh

total 21M

-rwxr-xr-x. 1 root root 86K Nov 18 13:05 bc

-rw-r--r--. 1 root root 20M Nov 18 13:06 zeroes

To create a simple archive:

[root@centos63 ~]# tar -cvf archive.tar archive/

Create archive and add gzip compression:

[root@centos63 ~]# tar -czvf archive.tar.gz archive/

Archive with bzip2 compression:

[root@centos63 ~]# tar -cjvf archive.tar.bzip2 archive/

Note that the simple .tar file is uncompressed.

[root@centos63 ~]# ls -l | grep arch

drwxr-xr-x. 2 root root 4096 Nov 18 13:05 archive

-rw-r--r--. 1 root root 21063680 Nov 18 13:07 archive.tar

-rw-r--r--. 1 root root 64164 Nov 18 13:08 archive.tar.gz

To extract the entire content of any archive uze –x flag.

[root@centos63 tmp]# tar -xvf archive.tar.gz

List contents with –t:

[root@centos63 tmp]# tar -tvf archive.tar

drwxr-xr-x root/root 0 2012-11-18 13:05 archive/

-rw-r--r-- root/root 20971520 2012-11-18 13:06 archive/zeroes

-rwxr-xr-x root/root 87840 2012-11-18 13:05 archive/bc

Extracting specific files from one archive requires adding paths

(relative to archive) to those files as arguments to tar:

[root@centos63 tmp]# tar -xvf archive.tar archive/bc

archive/bc

Lab 2

Purpose: Use gzip and gunzip to compress and extract files. Gzip is

usually used to compress a file in place. GRUB uses this format for

the splashscreen.

Procedure:

To compress one file:

[root@centos63 archive]# gzip bc

[root@centos63 archive]# ls

bc.gz zeroes

Decompressing is pretty simple:

[root@centos63 archive]# gunzip bc.gz

[root@centos63 archive]# ls

bc zeroes

Lab 3

Purpose: Use zip/unzip to manipulate archives that can be easily moved

on windows systems.

Procedure:

To add a file to archive (name of archive is the first argument):

[root@centos63 archive]# zip bc.zip bc

adding: bc (deflated 53%)

[root@centos63 archive]# ls

bc bc.zip zeroes

To add another file to existing archive:

[root@centos63 archive]# zip bc.zip zeroes

adding: zeroes (deflated 100%)

Listing the content required –l switch:

[root@centos63 archive]# unzip -l bc.zip

Archive: bc.zip

Length Date Time Name

--------- ---------- ----- ----

87840 11-18-2012 13:05 bc

20971520 11-18-2012 13:06 zeroes

--------- -------

21059360 2 files

Unzipping is pretty simple also:

[root@centos63 tmp]# unzip bc.zip

Archive: bc.zip

inflating: bc

inflating: zeroes