L in u X ba sics for h acke rs g e t t I n g s t a r t e d w I t h




Download 7,3 Mb.
Pdf ko'rish
bet104/125
Sana14.05.2024
Hajmi7,3 Mb.
#232858
1   ...   100   101   102   103   104   105   106   107   ...   125
Bog'liq
linuxbasicsforhackers

Tarring Files Together
Usually, the first thing you do when compressing files is to combine them into 
an archive. In most cases, when archiving files, you’ll use the 
tar
command. 
Tar stands for tape archive, a reference to the prehistoric days of computing 
when systems used tape to store data. The 
tar
command creates a single file 
from many files, which is then referred to as an archivetar file, or tarball.
For instance, say you had three script files like the ones we used in 
Chapter 8, named hackersarise1hackersarise2, and hackersarise3. If you navi-
gate to the directory that holds them and perform a long listing, you can 
clearly see the files and the details you’d expect, including the size of the 
files, as shown here:
kali >
ls -l
-rwxr-xr-x 1 root root 22311 Nov 27 2018 13:00 hackersarise1.sh
-rwxr-xr-x 1 root root 8791 Nov 27 2018 13:00 hackersarise2.sh
-rwxr-xr-x 1 root root 3992 Nov 27 2018 13:00 hackersarise3.sh
Let’s say you want to send all three of these files to another hacker you’re 
working with on a project. You can combine them and create a single archive 
file using the command in Listing 9-1.
kali >
tar -cvf HackersArise.tar hackersarise1 hackersarise2 hackersarise3
hackersarise1


Compressing and Archiving
95
hackersarise2
hackersarise3
Listing 9-1: Creating a tarball of three files
Let’s break down this command to better understand it. The archiving 
command is 
tar
, and we’re using it here with three options. The 
c
option 
means create, 
v
(which stands for verbose and is optional) lists the files that 
tar
is dealing with, and 
f
means write to the following file. This last option 
will also work for reading from files. Then we give the new archive the file-
name you want to create from the three scripts: HackersArise.tar.
In full, this command will take all three files and create a single file, 
HackersArise.tar, out of them. When you do another long listing of the direc-
tory, you will see that it also contains the new .tar file, as shown next:
kali >
ls -l
--
snip
--
-rw-r--r-- 1 root root 40960 Nov 27 2018 13:32 HackersArise.tar
--
snip
--
kali >
Note the size of the tarball here: 40,960 bytes. When the three files are 
archived, 
tar
uses significant overhead to perform this operation: whereas the 
sum of the three files before archiving was 35,094 bytes, after archiving, the 
tarball had grown to 40,960 bytes. In other words, the archiv ing process has 
added over 5,000 bytes. Although this overhead can be significant with small 
files, it becomes less and less significant with larger and larger files.
We can display those files from the tarball, without extracting them, by 
using the 
tar
command with the 
-t
content list switch, as shown next:
kali >

Download 7,3 Mb.
1   ...   100   101   102   103   104   105   106   107   ...   125




Download 7,3 Mb.
Pdf ko'rish

Bosh sahifa
Aloqalar

    Bosh sahifa



L in u X ba sics for h acke rs g e t t I n g s t a r t e d w I t h

Download 7,3 Mb.
Pdf ko'rish