Search notes:

ar fileformat

In order to examine the ar fileformat, we're first going to create an archive:
rm -f an-archive
ar cr an-archive
Github repository about-GNU-Binutils, path: /ar/fileformat/00-create-archive
ar cr …. creates an archive: a file which, incidentally, is called an-archive.
In order to examine the content of the archive, we use cat:
cat an-archive
Github repository about-GNU-Binutils, path: /ar/fileformat/cat-archive
prints
!<arch>
We're adding the file file_01.txt:
This is file_01.txt
It consists of four
lines. It's size
is 71 bytes. 
Github repository about-GNU-Binutils, path: /ar/fileformat/file_01.txt
The file is added with ar r:
ar r an-archive file_01.txt
Github repository about-GNU-Binutils, path: /ar/fileformat/01-add-a-file
The content of an-archive has now changed to
!<arch>
file_01.txt/    0           0     0     644     71        `
This is file_01.txt
It consists of four
lines. It's size
is 71 bytes. 
Similarly, we're adding two files in one go:
ar r an-archive file_02.txt file_03.txt
Github repository about-GNU-Binutils, path: /ar/fileformat/02-add-two-files
an-archive now has the following content
!<arch>
file_01.txt/    0           0     0     644     71        `
This is file_01.txt
It consists of four
lines. It's size
is 71 bytes. 

file_02.txt/    0           0     0     644     48        `
This is file_02.txt.
Two lines, size: 48 bytes.
file_03.txt/    0           0     0     644     24        `
FILE 03
FILE 03
FILE 03
Note the extra line between file_01.txt and file_02.txt. This is because ar stores files on even byte boundaries. file_01.txt has an uneven number of bytes, hence the additional newline.

Index