<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ITEC4B</title>
	<atom:link href="https://itec4b.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://itec4b.com/</link>
	<description>Information Technology Expert Consulting</description>
	<lastBuildDate>Tue, 07 Mar 2023 07:28:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
	<item>
		<title>HTTPS TLS X.509 Certificates</title>
		<link>https://itec4b.com/https-tls-x-509-certificates/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Sun, 05 Mar 2023 20:49:26 +0000</pubDate>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[TLS]]></category>
		<category><![CDATA[X.509 Certificate]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=1646</guid>

					<description><![CDATA[Public Key (Asymmetric) Cryptography Public-key cryptography, or asymmetric cryptography, is the field of cryptographic systems that use pairs of related keys.Each key pair consists of a private key and a corresponding public key.Key pairs are generated with cryptographic algorithms. The main uses of asymmetric cryptography are : &#8211; Encryption (public key)Anyone with a public key &#8230; <p class="link-more"><a href="https://itec4b.com/https-tls-x-509-certificates/" class="more-link">Read more<span class="screen-reader-text"> "HTTPS TLS X.509 Certificates"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>Public Key (Asymmetric) Cryptography</h2>



<p><span style="text-decoration: underline;"><strong>Public-key cryptography</strong>, or <strong>asymmetric cryptography</strong>, is the field of cryptographic systems that use pairs of related keys</span>.<br><span style="text-decoration: underline;">Each key pair consists of a <strong>private key</strong> and a corresponding <strong>public key</strong></span>.<br>Key pairs are generated with cryptographic algorithms.</p>



<p><span style="text-decoration: underline;"><strong>The main uses of asymmetric cryptography are</strong></span> :<br><br>&#8211; <span style="text-decoration: underline;"><strong>Encryption (public key)</strong></span><br>Anyone with a public key can encrypt a message, but only those who own the corresponding private key can decrypt the encrypted message to obtain the original message.<br><br>&#8211; <strong><span style="text-decoration: underline;">Digital Signatures (private key)</span></strong><br>This process proves the Authenticity of the sender and the Integrity of the message.<br><br>In many scenarios, the sender and receiver of a message must be sure that a message has not been altered during transmission.<br>Although encryption hides the contents of a message, it may be possible to alter an encrypted message.<br>If a message is digitally signed, any change in the message after signature invalidates the signature.<br>A message is signed with the sender&#8217;s private key and can be verified by anyone who has access to the sender&#8217;s public key.<br><br>Given a message and a private key, a signing algorithm produces a signature.<br>Given the message, the public key and the signature, a signature verifying algorithm either accepts or rejects the message&#8217;s claim to authenticity.<br><br>Digital signatures may be attached to the message or detached.<br>A detached signature is transmitted separately from the message it signs.</p>



<p class="has-vivid-red-color has-text-color"><strong><span style="text-decoration: underline;">Security of public key cryptography depends on keeping the private key secret, while the public key can be openly distributed.</span></strong></p>



<h2>Transport Layer Security (TLS)</h2>



<p><a href="https://www.internetsociety.org/deploy360/tls/basics">Transport Layer Security (TLS)</a> is a protocol that encrypts data sent over the Internet, the most familiar usage is with HTTPS.<br><br><strong><span style="text-decoration: underline;">TLS uses a combination of symmetric and asymmetric cryptography, as this provides a good compromise between performance and security when transmitting data securely</span></strong>.</p>



<p><strong><span style="text-decoration: underline;">With symmetric cryptography, data is encrypted and decrypted with a secret key known to both sender and recipient</span></strong>, typically 128 but preferably 256 bits in length (anything less than 80 bits is now considered insecure).<br><span style="text-decoration: underline;"><strong>Symmetric cryptography is efficient in terms of computation, but having a common secret key means it needs to be shared in a secure manner</strong></span>.<br><br><strong><span style="text-decoration: underline;">Asymmetric cryptography uses key pairs: a public key, and a private key</span></strong>.<br>The public key is mathematically related to the private key, but given sufficient key length, it is computationally impractical to derive the private key from the public key.<br>This allows the public key of the recipient to be used by the sender to encrypt the data they wish to send to them, but that data can only be decrypted with the private key of the recipient.<br><br><strong><span style="text-decoration: underline;">The advantage of asymmetric cryptography is that the process of sharing encryption keys does not have to be secure</span></strong>, but the mathematical relationship between public and private keys means that much larger key sizes are required.<br><span style="text-decoration: underline;">The recommended minimum key length is 1024 bits, with 2048 bits preferred</span>, but this is up to a thousand times more computationally intensive than symmetric keys of equivalent strength (e.g. a 2048-bit asymmetric key is approximately equivalent to a 112-bit symmetric key) and makes <strong>asymmetric encryption too slow for many purposes</strong>.</p>



<p class="has-text-color" style="color:#1e73be"><strong><span style="text-decoration: underline;">For this reason, TLS uses asymmetric cryptography for securely generating and exchanging a session key</span>.<br><span style="text-decoration: underline;">The session key is then used for encrypting the data transmitted by one party, and for decrypting the data received at the other end</span></strong>.</p>



<p>Once the session is over, the session key is discarded.</p>



<h2>X.509 Certificates</h2>



<p><strong>ITU-T X.509 </strong>|<strong> ISO/IEC 9594-8</strong> is an <a href="https://www.itu.int/ITU-T/recommendations/rec.aspx?rec=14033">International Telecommunication Union (ITU)</a> standard defining the format of public key certificates.<br><br><strong><span style="text-decoration: underline;">In cryptography, a public key certificate, also known as a digital certificate or X.509 certificate is an electronic document used to prove the validity of a public key</span></strong>.<br><br>An X.509 certificate binds an identity to a public key using a digital signature.<br><br><strong><span style="text-decoration: underline;">The certificate includes a public key, information about the identity of its owner (called the subject), and the digital signature of an entity that has verified the certificate&#8217;s contents (called the issuer).</span></strong><br><br>If the signature is valid, and the software examining the certificate trusts the issuer, then it can use that public key to communicate securely with the subject.<br><br>The X.509 standard was first issued in 1988 and is described in several RFCs.<br>X.509 Version 3 Certificate is defined in <a href="https://datatracker.ietf.org/doc/html/rfc5280">RFC 5280 (2008)</a><br><br><strong><span style="text-decoration: underline;">A digital certificate is normally issued by an authority, referred to as a Certification Authority (CA)</span></strong>.<br><span style="text-decoration: underline;">That authority guarantees the validity of the information in the certificate which is valid for a limited period of time</span>.<br><br><strong><span style="text-decoration: underline;">A Certification Authority (CA) is an entity that stores, signs, and issues digital certificates</span></strong>.<br>A digital certificate certifies the ownership of a public key by the named subject of the certificate.<br><br>One particularly common use for Certificate Authorities is to sign certificates used for HTTPS, the secure browsing protocol for Internet.<br><br><strong><span style="text-decoration: underline;">The CA that issues public-key certificates also has the responsibility to indicate the validity of the public-key certificates that it issues</span></strong>. Generally, public-key certificates are subject to possible subsequent revocation. This revocation and a notification of the revocation may be done directly by the same CA that issued the public-key certificate, or indirectly by another authority duly authorized by the CA that issued the public-key certificate.<br><br><strong><span style="text-decoration: underline;">If, for any reason, a CA revokes a previously issued public-key certificate, entities need to be able to learn that revocation has occurred so they do not use an untrustworthy public-key certificate</span></strong>.<br>Revocation lists are one scheme that can be used to notify entities of revocations.<br><br>CAs that do revoke public-key certificates are required to state what mechanism(s) can be used by relying parties to obtain revocation status information about public-key certificates issued by that CA.<br>This includes a <strong>Certificate Revocation List (CRL)</strong> mechanism and Authorization and Validation List (AVL) mechanism, but does not preclude the use of alternative mechanisms.<br><br>One such alternative mechanism is the <strong>Online Certificate Status Protocol (OCSP)</strong> specified in IETF <a href="https://datatracker.ietf.org/doc/html/rfc6960">RFC 6960 (2013)</a>. Using this protocol, a relying party (client) requests the revocation status of a public-key certificate from an OCSP server. The server may use CRLs, or other mechanisms to check the status of the public-key certificate and respond to the client accordingly.</p>



<h2>Steps to get an SSL/TLS certificate from a Certification Authority</h2>



<p>1) Create a private key and a Certificate Signing Request (CSR)<br>2) Send the CSR to the trusted CA<br>3) The CA sends you the certificate signed by its root certificate and private key<br>4) Install the certificate on the web server</p>



<h2>Certificate Signing Request (CSR)</h2>



<p>A Certificate Signing Request (CSR) is the first step to get an SSL/TLS certificate from a Certification Authority.<br><strong><span style="text-decoration: underline;">You normally generate it on the same server you plan to use the certificate (the private key must be kept secret)</span></strong>.<br><strong><span style="text-decoration: underline;">The CSR contains identification information (Country, State/Province, Locality, Organization, Organizational Unit, Common Name, Email) AND the public key that the Certificate Authority (CA) will use to create the certificate</span></strong>.<br>Not all of these fields may be required and will vary depending on the assurance level of your certificate.</p>



<h2>Assurance levels for SSL/TLS certificates</h2>



<p><strong><span style="text-decoration: underline;">Class 1 Certificates</span></strong> are considered to be low assurance, as the verification method simply confirms that the subscriber controls the domain.<br>They can do this by adding a DNS record associated with the domain, the process is automated.<br>No verification checks of the subscriber’s identity are performed.<br>This level of validation is referred to as <strong><span style="text-decoration: underline;">Domain Validation (DV)</span></strong> and is the cheapest.<br><br><strong><span style="text-decoration: underline;">Class 2 Certificates</span></strong> are considered to be medium assurance.<br>They provide a greater level of assurance over Class 1 Certificates, because in addition to domain control, basic verification steps are performed to confirm the identity of the Subscriber.<br>This level of validation is referred to as <strong><span style="text-decoration: underline;">Organization Validation (OV)</span></strong>.<br>Organization Validation SSL/TLS certificates will contain the organization&#8217;s name and address, making them more trustworthy for users than Domain Validation certificates.<br><br><strong><span style="text-decoration: underline;">Class 3 Certificates</span></strong> provide a high level of assurance.<br>They are issued only after rigorous validation of the identity of the Subscriber.<br>This level of validation is referred to as <strong><span style="text-decoration: underline;">Extended Validation (EV)</span></strong>.<br><br><strong><span style="text-decoration: underline;">Extended Validation involves a full background check of the organization</span></strong>.<br><span style="text-decoration: underline;"><strong>The CA will make sure that the organization exists and is legally registered as a business, that they actually are present at the address they list, and so on</strong></span>.<br>This validation level takes the longest and costs the most, but Extended Validation SSL certificates are more trustworthy than other types of SSL certificates.<br><span style="text-decoration: underline;">Consequently, these certificates are necessary for a website&#8217;s address to turn the browser URL bar green, the visual representation for users of a trustworthy TLS-encrypted site</span>.</p>



<h2>PEM Format</h2>



<p><strong><span style="text-decoration: underline;">A CSR is usually in a PKCS#10 format, by default a CSR is created in a Base-64 PEM format</span></strong>, and isn&#8217;t designed to be read by a human.</p>



<p><strong><span style="text-decoration: underline;">PEM (originally &#8216;Privacy Enhanced Mail&#8217;) is a standard and the most common format for X.509 certificates, CSRs, and cryptographic keys</span></strong>.<br><br>A PEM file is a text file containing one or more items (defined by <code>&lt;type&gt;</code>) in Base64 ASCII encoding, each with plain-text headers and footers :<br><br>starting with<br><code>-----BEGIN &lt;type&gt;-----</code><br><br>and ending with:<br><code>-----END &lt;type&gt;-----</code><br><br>Everything in between is base64 encoded (uppercase and lowercase letters, digits, +, / and =).<br>Base64 is a binary-to-text encoding scheme. It represents binary data in a printable ASCII string format by translating it into a radix-64 representation.<br>It is defined in <a href="https://datatracker.ietf.org/doc/html/rfc4648">RFC 4648 (2006)</a><br><br>The PEM file will tell you what it is used for in the header (if it is a private key, a CSR, a certificate)<br><br><code>-----BEGIN PRIVATE KEY-----</code><br>…<br><code>-----END PRIVATE KEY-----</code><br><br><code>-----BEGIN CERTIFICATE REQUEST-----</code><br>…<br><code>-----END CERTIFICATE REQUEST-----</code><br><br><code>-----BEGIN CERTIFICATE-----</code><br>…<br><code>-----END CERTIFICATE-----</code><br><br><strong><span style="text-decoration: underline;">Thus, a Certificate Signing Request (CSR) is a request sent to a Certification Authority to sign your public key and associated informations</span></strong>.<br><br><span style="text-decoration: underline;"><strong>The CSR is signed by the applicant&#8217;s private key, this proves to the CA that the applicant has possession and control of the private key that corresponds to the public key included in the CSR</strong></span>.<br><br>The CA first verifies the PKCS#10 signature with the public key placed in the PKCS#10.<br><strong><span style="text-decoration: underline;">Once the signature is successfully verified, the requested information in the CSR passes a vetting process and domain control is established, the CA signs the applicant&#8217;s public key so that it can be publicly trusted</span></strong>. <br><br><strong><span style="text-decoration: underline;">It becomes a trusted signed certificate that internet browsers will be able to verify when communication is made to your server</span></strong>.<br><br>Most internet browsers and operating systems hold a copy of root CA certificates of all the trusted certified Certificated Authorities.<br><br>On Debian it is located in <code><strong>/usr/share/ca-certificates/mozilla/</strong></code> (package <strong>ca-certificates</strong>)<br>It contains the certificate authorities shipped with Mozilla&#8217;s browser to allow SSL-based applications to check for the authenticity of SSL connections.<br><br>That’s the reason internet browsers won’t show any security messages when you visit websites using https with a certificate issued from a trusted and well-known commercial Certificate Authority.<br><br><strong><span style="text-decoration: underline;">You can also sign the CSR yourself but this will cause browsers to display warning messages to users attempting to reach your server until they explicitly grant their browsers permission to communicate with it</span></strong>.<br><strong><span style="text-decoration: underline;">If you use a self-signed certificate, your browser will throw a security warning</span></strong>.<br>The reason is that internet browsers only trust certificates from a trusted Certificate Authority.<br><br>For this reason it is recommended only to self-sign a certificate for testing purposes or only if your server needs to be reached internally.</p>



<h2>Install OpenSSL (Debian)</h2>



<pre class="wp-block-code"><code># apt install openssl</code></pre>



<p>The <code><strong>/etc/ssl/certs</strong></code> directory is used to store the public certificates, it should already exists on the server.<br>You may need to create an <strong><code>/etc/ssl/private</code></strong> directory as well, to store the private keys.<br>Since the secrecy of those private keys is essential for security, it’s important to lock down the permissions to prevent unauthorized access.</p>



<pre class="wp-block-code"><code># mkdir /etc/ssl/private

$ ls -l /etc/ssl
drwxr-xr-x   root root      certs
-rw-r--r--   root root      openssl.cnf
drwx--x---   root ssl-cert  private</code></pre>



<h2>Generate a private key + Certificate Signing Request</h2>



<pre class="wp-block-code"><code><span style="text-decoration: underline;"><strong>Create a specific directory to store CSRs</strong></span>

# mkdir /etc/ssl/csr</code></pre>



<pre class="wp-block-code"><code><span style="text-decoration: underline;"><strong>Create a private key and generate a Certificate Signing Request from it</strong></span>

# openssl genrsa -out /etc/ssl/private/domain-name.key 2048
# openssl req -new -key /etc/ssl/private/domain-name.key -out /etc/ssl/csr/domain-name.csr

OR 

# openssl req -newkey rsa:2048 -nodes -keyout /etc/ssl/private/domain-name.key -out /etc/ssl/csr/domain-name.csr

You may be prompted to enter extra attributes including an optional challenge password.
Just skip this step by hitting the enter button.</code></pre>



<pre class="wp-block-code"><code><span style="text-decoration: underline;">Examine and verify Certificate Signing Request</span>

$ openssl req -in /etc/ssl/csr/domain-name.csr -text -verify -noout</code></pre>



<h2>What is a Self Signed Certificate?</h2>



<p>A self-signed certificate is an SSL/TSL certificate not signed by a public or private Certification Authority.<br>Instead, it is signed by the creator’s own private key or root CA certificate.<br><br>Many organizations use self-signed certificated for their internal applications that are not internet-facing.<br>These certificates are generated using the organization’s internal PKI infrastructure.<br><br>A self-signed certificate will encrypt communication between your server and any clients.<br>However, because it is not signed by any of the trusted certificate authorities included with web browsers, users cannot use the certificate to validate the identity of your server automatically.</p>



<h2>Create a private key AND a self-signed public certificate with OpenSSL &#8211; Method 1</h2>



<pre class="wp-block-code"><code># openssl req -x509 -sha256 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/ssl/private/hostname.key -out /etc/ssl/certs/selfsigned-hostname.crt</code></pre>



<p><code>openssl req</code><br>OpenSSL command line tool, PKCS#10 X.509 Certificate Signing Request (CSR) Management.<br><br><code>-x509</code><br>This option tells openssl you want to make a self-signed certificate instead of generating a certificate signing request.<br><br><code>-sha256</code><br>This option tells openssl to sign with a sha256 message digest<br><br><code>-nodes</code><br>This option tells openssl not to encrypt the private key with a passphrase.<br>The web server needs to be able to read the file without user intervention, when the server starts up.<br>A passphrase would prevent this from happening because you would have to enter it after every restart.<br><br><code>-days 3650</code><br>This option sets how many days the certificate will be considered valid (3650 = 10 years)<br><br><code>-newkey rsa:2048</code><br>This option specifies that you want to generate a new private key at the same time.<br>(RSA key that is 2048 bits long)<br><br><code>-keyout</code><br>This option tells openssl where to place the generated private key file<br><br><code>-out</code><br>This option tells openssl where to place the self-signed certificate<br><br>Note: It is important that you enter your domain/host name or your server’s IP address when you’re prompted for the Common Name.</p>



<pre class="wp-block-code"><code><span style="text-decoration: underline;">Display the contents of the certificate</span>
$ openssl x509 -in /etc/ssl/certs/selfsigned-hostname.crt -text -noout</code></pre>



<h2>Create a private key AND a self-signed public certificate with OpenSSL – Method 2</h2>



<pre class="wp-block-code"><code><strong><span style="text-decoration: underline;">Step 1 - Create a private key</span></strong>
# openssl genrsa -out /etc/ssl/private/hostname.key 2048

<strong><span style="text-decoration: underline;">Step 2 - Create a CSR</span></strong>
# openssl req -new -key /etc/ssl/private/hostname.key -out /etc/ssl/csr/hostname.csr

<strong><span style="text-decoration: underline;">NOTE: Step 1 and 2 can be combined in one line</span></strong>
# openssl req -new --nodes newkey rsa:2048 -keyout /etc/ssl/private/hostname.key -out /etc/ssl/csr/hostname.csr

<strong><span style="text-decoration: underline;">Step 3 - Check the CSR</span></strong>
$ openssl req -in /etc/ssl/csr/hostname.csr -text -noout

<strong><span style="text-decoration: underline;">Step 4 - Create Self-signed Certificate</span></strong>
# openssl x509 -req -days 3650 -in /etc/ssl/csr/hostname.csr -signkey /etc/ssl/private/hostname.key -out /etc/ssl/certs/selfsigned-hostname.crt
</code></pre>



<h2>Create a private key AND a self-signed public certificate with OpenSSL – Method 3: own Certification Authority (CA)</h2>



<pre class="wp-block-code"><code><strong><span style="text-decoration: underline;">IMPORTANT</span></strong>
<strong><span style="text-decoration: underline;">For security reasons, Certification Authority's private key and certificate SHOULD BE safeguarded on a separate machine.</span></strong>

# mkdir /etc/ssl/MyOwnCA


<strong><span style="text-decoration: underline;">Step 1 - Create Certification Authority rootCA.key and rootCA.crt</span></strong>
We will use the rootCA.key and rootCA.crt to sign the SSL/TLS certificate.

# openssl req -x509 -nodes  -newkey rsa:2048 -keyout /etc/ssl/MyOwnCA/rootCA.key -days 3650 -sha256 -out /etc/ssl/MyOwnCA/rootCA.crt

Country Name (2 letter code) &#91;]: FR
State or Province Name (full name) &#91;]: *
Locality Name (eg, city) &#91;]:
Organization Name (eg, company) &#91;]: COMPANY  
Organizational Unit Name (eg, section) &#91;]: PKI ADMINISTRATION
Common Name (e.g. server FQDN or YOUR name) &#91;]: COMPANY-ROOT-CA
Email Address &#91;]:

<strong><span style="text-decoration: underline;">Step 2 - Create the Host Private Key and Certificate Signing Request</span></strong>
# openssl req -newkey rsa:2048 -nodes -keyout /etc/ssl/private/hostname.key -out /etc/ssl/csr/hostname.csr

<strong><span style="text-decoration: underline;">Step 3 - Generate X.509 certificate signed with own CA</span></strong>
# openssl x509 -req -in /etc/ssl/csr/hostname.csr -CA /etc/ssl/MyOwnCA/rootCA.crt -CAkey /etc/ssl/MyOwnCA/rootCA.key -CAcreateserial -days 3650 -sha256 -out /etc/ssl/certs/ownCAsigned-hostname.crt
</code></pre>



<h2>Install X.509 Certificate on Web Server (Apache &#8211; Debian)</h2>



<p>In order to set up and use a (self-signed) certificate, you first have to be sure that Apache ssl module which provides support for SSL encryption, is installed and enabled on the server.</p>



<pre class="wp-block-code"><code># a2enmod ssl</code></pre>



<p>Create an Apache directory for the hosts certificates and private keys</p>



<pre class="wp-block-code"><code># mkdir /etc/apache2/certificates</code></pre>



<pre class="wp-block-code"><code>Set up the virtual host to use the certificate

# vi /etc/apache2/sites-available/website.conf

&lt;VirtualHost *:443>
...
        SSLEngine on
        SSLCertificateFile /etc/apache2/certificates/website.crt
        SSLCertificateKeyFile /etc/apache2/certificates/website.key
&lt;/VirtualHost>


Optionally, you may want to automatically redirect HTTP traffic to HTTPS

&lt;VirtualHost *:80>
...
        Redirect "/" "https://website"
&lt;/VirtualHost></code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>rsync: Remote Synchronization</title>
		<link>https://itec4b.com/rsync-remote-synchronization/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Thu, 02 Mar 2023 12:44:17 +0000</pubDate>
				<category><![CDATA[Application]]></category>
		<category><![CDATA[Data Transfer]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=989</guid>

					<description><![CDATA[rsync is a complete and powerful open source utility that provides fast incremental files transfer.It efficiently transfers and synchronizes files/directories between storage drive(s) and across networked hosts. It was created in 1996 by Andrew Tridgell and Paul Mackerras.It is currently maintained by Wayne Davison. rsync is freely available under the GNU General Public License.rsync source &#8230; <p class="link-more"><a href="https://itec4b.com/rsync-remote-synchronization/" class="more-link">Read more<span class="screen-reader-text"> "rsync: Remote Synchronization"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><span style="text-decoration: underline;"><strong><a href="https://rsync.samba.org">rsync</a> is a complete and powerful open source utility that provides fast incremental files transfer</strong></span>.<br>It efficiently transfers and synchronizes files/directories between storage drive(s) and across networked hosts.</p>



<p>It was created in 1996 by Andrew Tridgell and Paul Mackerras.<br>It is currently maintained by Wayne Davison.<br><br>rsync is freely available under the GNU General Public License.<br><a href="https://git.samba.org/?p=rsync.git;a=tree">rsync source code is here</a> <br><br>The rsync algorithm is a type of delta encoding, and is used for minimizing network usage.<br><span style="text-decoration: underline;"><strong>It efficiently computes/identify which parts (splitted blocks by <strong>fragmentation</strong>) of a source file match some part of an existing destination file (those parts don&#8217;t need to be sent across the communication link), thus minimizing the amount of data to transfer by only moving the portions of files that have changed</strong></span>.<br><br>For further speed improvements, the data sent to the receiver can be compressed using any of the supported algorithms.<br><br><strong>ssh is the default remote shell for rsync since <a href="https://download.samba.org/pub/rsync/NEWS#2.6.0">version 2.6.0 (January 1st 2004)</a></strong></p>



<pre class="wp-block-code"><code>Install rsync (Debian)
# apt install rsync

rsync version
$ rsync -V</code></pre>



<h2>Usage</h2>



<p><strong><span style="text-decoration: underline;">Local SRC &gt; Local DST</span></strong><br><code>rsync [OPTIONS] SRC [DST]</code></p>



<p><strong><span style="text-decoration: underline;">Push (Local SRC > Remote DST)</span></strong> <code>rsync [OPTIONS] SRC [USER@]HOST:DST</code><br><strong><span style="text-decoration: underline;">Pull (Local DST &lt; Remote SRC)</span></strong> <code>rsync [OPTIONS] [USER@]HOST:SRC [DST]</code><br><br>Usages with just one SRC arg and no DST arg will list the source files instead of copying:<br><code><strong>&lt;type>&lt;perms_rwx> &lt;size_bytes> &lt;mtime YYYY/MM/DD> &lt;mtime hh:mm:ss> &lt;relative_path></strong></code><br><br><strong><span style="text-decoration: underline;">IMPORTANT: rsync must be installed on both the source and destination machines</span></strong><br><br>If you still has this error:<br><code>rsync: command not found<br>rsync: connection unexpectedly closed (0 bytes received so far) [sender]<br>rsync error: error in rsync protocol data stream ...</code><br><br>It means Local rsync cannot find the remote rsync executable.<br>In this case you need to know the path of the remote host&#8217;s rsync binary and make it part of the command with <code><strong>--rsync-path=/path/to/remote/rsync</strong></code></p>



<pre class="wp-block-code"><code>$ which rsync
/usr/bin/rsync  (Debian)</code></pre>



<h2>Options</h2>



<p><span style="text-decoration: underline;"><strong>If <code>--delete </code>option is specified, rsync will identify the files NOT present on the sender and delete them on the receiver</strong></span>. This option can be dangerous if used incorrectly! It is recommended to do a simulation run before, using the <code><strong>--dry-run</strong></code> option (<code><strong>-n</strong></code>) to find out which files are going to be deleted.<br><br>Each file from the list generated by rsync will be checked to see if it can be skipped.<br><span style="text-decoration: underline;"><strong>In the most common mode of operation, files are not skipped if the modification time or size differs</strong></span>.</p>



<p>rsync performs a slower but comprehensive check if invoked with <code><strong>--checksum</strong></code> option.<br>This forces a full checksum comparison on every file present on both systems.<br><br><code><span style="text-decoration: underline;"><strong>--checksum, -c</strong></span></code><br><strong><span style="text-decoration: underline;">Skip files based on checksum, not mtime AND size</span></strong>.<br>This changes the way rsync checks if the files have been changed and are in need of a transfer.<br>Without this option, rsync uses a &#8220;quick check&#8221; that (by default) checks if each file&#8217; size and time of last modification match between the sender and receiver.<br>This option changes this to compare a 128-bit checksum for each file that has a matching size.<br>Generating the checksums means that both sides will expend a lot of disk I/O reading all the data in the files in the transfer, so this can slow things down significantly (and this is prior to any reading that will be done to transfer changed files)</p>



<p><code><strong><span style="text-decoration: underline;">--human-readable, -h</span></strong></code><br>Output numbers in a more human-readable format.<br>Unit letters: K (Kilo), M (Mega), G (Giga), T (Tera), or P (Peta).</p>



<p><strong><span style="text-decoration: underline;"><code>--dry-run, -n</code></span></strong><br>Simulation run (no changes made)</p>



<p><code><strong><span style="text-decoration: underline;">--verbose, -v</span></strong></code><br>Increases the amount of information you are given during the transfer.<br>By default, rsync works silently.<br>A single -v will give you information about what files are being transferred and a brief summary at the end.<br>Two -v options will give you information on what files are being skipped and slightly more information at the end.<br>More than two -v options should only be used if you are debugging rsync.</p>



<p><code><strong><span style="text-decoration: underline;">--quiet, -q</span></strong></code><br>Decreases the amount of information you are given during the transfer, notably suppressing information messages from the remote server. This option is useful when invoking rsync from cron.</p>



<p><strong><span style="text-decoration: underline;"><code>--info=FLAGS</code></span></strong><br>Choose the information output<br>An individual flag name may be followed by a level number, with 0 meaning to silence that output, 1 being the default output level, and higher numbers increasing the output of that flag (for those that support higher levels).<br><code>$ rsync --info=help</code><br><code>$ <strong>rsync -av --info=progress2 SRC/ DST/</strong></code></p>



<p><span style="text-decoration: underline;"><code><strong>--progress</strong></code></span><br>Print information showing the progress of the transfer.<br>This is the same as specifying <code>'<strong>--info=flist2,name,progress</strong>'</code> but any user-supplied settings for those info flags takes precedence (e.g. <code>--info=flist0 --progress</code>).</p>



<p>While rsync is transferring a regular file, it updates a progress line that looks like this:<br><code><strong>&lt;reconstructed_bytes&gt; &lt;%_current_file&gt; &lt;throughput/sec&gt; &lt;remaining_time&gt;</strong></code></p>



<p>When the file transfer is done, rsync replaces the progress line with a summary line that looks like this:<br><code><strong>&lt;filesize_bytes&gt; 100% &lt;throughput/sec&gt; &lt;elapsed_time&gt; (xfr#?, to-chk=???/N)</strong></code><br>where ? is the nth transfer, ??? is the remaining files for the receiver to check (to see if they are uptodate or not)<br><br>In an incremental recursion scan (<code><strong>--recursive</strong></code>), rsync doesn&#8217;t know the total number of files in the files list until it reaches the end of the scan. Since it starts transfering files during the scan, it displays a line with the text &#8220;ir-chk&#8221; (for incremental recursion check) instead of &#8220;to-chk&#8221; until it knows the full size of the list, at which point it switches to &#8220;to-chk&#8221;. &#8220;ir-chk&#8221; lets you know that the number of files in the files list is still going to increase.</p>



<p><strong><span style="text-decoration: underline;"><code>--archive, -a</code></span></strong><br><strong>It is equivalent to <code>-rlptgoD</code></strong><br>This is a quick way of saying you want recursion and want to preserve almost everything.<br><span style="text-decoration: underline;"><strong>Be aware that it does not include preserving ACLs (<code>-A</code>), xattrs (<code>-X</code>), atimes (<code>-U</code>), crtimes (<code>-N</code>), nor the finding and preserving of hardlinks (<code>-H</code>)</strong></span>.<br>The only exception to the above equivalence is when <code>--files-from</code> is specified, in which case <code>-r</code> is not implied.</p>



<p><strong><span style="text-decoration: underline;"><code>--recursive, -r</code></span></strong><br>This tells rsync to copy directories recursively. See also <code>--dirs</code> (<code>-d</code>).<br>Beginning with rsync 3.0.0, the recursive algorithm used is now an incremental scan that uses much less memory than before and <span style="text-decoration: underline;"><strong>begins the transfer after the scanning of the first few directories have been completed</strong></span>.<br>It is only possible when both ends of the transfer are at least version 3.0.0.<br><br><span style="text-decoration: underline;">Some options require rsync to know the full files list, these options disable the incremental recursion mode.<br>These include: <code>--delete-before</code>, <code>--delete-after</code>, <code>--prune-empty-dirs</code>, and <code>--delay-updates</code></span>.</p>



<p>Because of this, <strong><span style="text-decoration: underline;">the default delete mode when you specify <code>--delete</code> is now <code>--delete-during</code> when both ends of the connection are at least 3.0.0</span></strong> (use <code>--del</code> or <code>--delete-during</code> to request this improved deletion mode explicitly).<br>See also the &#8211;delete-delay option that is a better choice than using &#8211;delete-after.</p>



<p>Incremental recursion can be disabled using the <code>--no-inc-recursive</code> option or its shorter <code>--no-i-r </code>alias.</p>



<p><strong><code><span style="text-decoration: underline;">--delete-during, --del</span></code></strong><br>Request that the file deletions on the receiving side be done incrementally as the transfer happens.<br>The per-directory delete scan is done right before each directory is checked for updates, so it behaves like a more efficient <code>--delete-before</code>. This option was first added in rsync version 2.6.4. See <code>--delete</code> (which is implied) for more details on file deletion.</p>



<p><strong><code><span style="text-decoration: underline;">--delete-before</span></code></strong><br>Request that the file deletions on the receiving side be done before the transfer starts.<br>It does imply a delay before the start of the transfer, and this delay might cause the transfer to timeout (if <code>--timeout</code> was specified). It also forces rsync to use the old, non-incremental recursion algorithm that requires rsync to scan all the files in the transfer into memory at once (see <code>--recursive</code>).</p>



<p><strong><span style="text-decoration: underline;"><code>--delete-after</code></span></strong><br>Request that the file deletions on the receiving side be done after the transfer has completed.<br><span style="text-decoration: underline;">Important: this option forces rsync to use the old, non-incremental recursion algorithm that requires rsync to scan all the files in the transfer into memory at once (see <code>--recursive</code>)</span>. Use <code>--delete-delay</code> instead.</p>



<p><code><strong><span style="text-decoration: underline;">--delete-delay</span></strong></code><br>Request that the file deletions on the receiving side be computed during the transfer (like &#8211;delete-during), but removed after the transfer completes. <span style="text-decoration: underline;">This is more efficient than using <code>--delete-after</code></span>.<br>If the number of removed files overflows an internal buffer, a temporary file will be created on the receiving side to hold the names. If the creation of the temporary file fails, rsync will try to fall back to using <code>--delete-after</code> (which it cannot do if <code>--recursive</code> is doing an incremental scan).</p>



<p><strong><span style="text-decoration: underline;"><code>--links, -l</code></span></strong><br>By default, symbolic links are not transferred at all.<br>A message <code>"skipping non-regular"</code> file is emitted for any symlinks that exist.<br>If <code>--links</code> is specified, then symlinks are recreated with the same target on the destination.<br>Note that <code>--archive</code> implies <code>--links</code>.</p>



<p><strong><span style="text-decoration: underline;"><code>--perms, -p</code></span></strong><br>Preserve permissions<br>This option causes the receiving rsync to <strong><span style="text-decoration: underline;">set the destination permissions to be the same as the source permissions</span></strong>.<br>(See also the <code>--chmod</code> option for a way to modify what rsync considers to be the source permissions)<br><br><span style="text-decoration: underline;">When this option is off, permissions are set as follows</span>:<br><br>&#8211; Existing files (including updated files) retain their existing permissions, though the <code>--executability</code> option might change just the execute permission for the file.<br><br>&#8211; New files get their <code>"</code>normal<code>"</code> permission bits set to the source file&#8217;s permissions masked with the receiving directory&#8217;s default permissions (either the receiving umask, or the permissions specified via the destination directory&#8217;s default ACL), AND their special permission bits disabled except in the case where a new directory inherits a setgid bit from its parent directory.</p>



<p>Thus, when<code> --perms</code> and <code>--executability</code> are both disabled, rsync&#8217;s behavior is the same as that of other file copy utilities, such as cp(1) and tar(1).</p>



<p>In summary:<br><span style="text-decoration: underline;"><strong>To give destination files (both existing and new) the source permissions, use <code>--perms</code></strong></span>.<br>To give new files the destination default permissions (while leaving existing files unchanged), make sure that the <code>--perms</code> option is off and use <code>--chmod=ugo=rwX</code> (which ensures that all non-masked bits get enabled).</p>



<p>The preservation of the destination&#8217;s setgid bit on newly-created directories when &#8211;perms is off was added in rsync 2.6.7.</p>



<p><strong><span style="text-decoration: underline;"><code>--times, -t</code></span></strong><br><strong><span style="text-decoration: underline;">Preserve modification times</span></strong><br>This tells rsync to transfer modification times along with the files and update them on the remote system.<br>Note that if this option is not used, the optimization that excludes files that have not been modified cannot be effective.<br>In other words, a missing <code>-t</code> or <code>-a</code> will cause the transfer to behave as if it used <code>--ignore-times</code>, causing all files to be updated (though rsync&#8217;s delta-transfer algorithm will make the update fairly efficient if the files haven&#8217;t actually changed, you&#8217;re much better off using <code>-t</code>).</p>



<p><strong><span style="text-decoration: underline;"><code>--ignore-times, -I</code></span></strong><br>Normally rsync will skip any files that are already the same size and have the same modification timestamp.<br>This option turns off this <code>"</code>quick check<code>"</code> behavior, causing all files to be updated.</p>



<p><strong><span style="text-decoration: underline;"><code>--atimes, -U</code></span></strong><br><strong><span style="text-decoration: underline;">Preserve access times</span></strong><br>This tells rsync to <strong><span style="text-decoration: underline;">set the access (use) times of the destination files to the same value as the source files</span></strong>.<br><strong><span style="text-decoration: underline;">nanoseconds are not preserved (set to .000000000</span>)<span style="text-decoration: underline;">, command <code>cp -a</code> does</span></strong>.</p>



<p><strong><span style="text-decoration: underline;">IMPORTANT</span>:<br>There is no option to preserve ctime <code>"</code>status time<code>"</code></strong><br><strong>(the timestamp used to record when the inode changed, it is specific to a filesystem)</strong><br>An inode changes if any of its attributes are updated:<br>&#8211; at creation time (new file)<br>&#8211; file name<br>&#8211; mode/permissions<br>&#8211; owner/group<br>&#8211; hard link count<br>etc.<br><br>The creation of a file is one of the conditions listed above (creation of inode/file).<br>ctime cannot be preserved when files are brought into a new filesystem.</p>



<p><strong><span style="text-decoration: underline;"><code>--open-noatime</code></span></strong><br><strong><span style="text-decoration: underline;">Avoid changing the atime on opened file</span></strong><br>This tells rsync to open files with the <code>O_NOATIME</code> flag (on systems that support it) to avoid changing the access time of the files that are being transferred. If your OS does not support the <code>O_NOATIME</code> flag then rsync will silently ignore this option. Note also that some filesystems are mounted to avoid updating the atime on read access even without the <code>O_NOATIME</code> flag being set.</p>



<p><strong><span style="text-decoration: underline;"><code>--crtimes, -N</code></span></strong><br><strong>MAY NOT BE SUPPORTED, DEPENDS ON THE FILESYSTEM</strong>.<br>This tells rsync to set the create times (newness) of the destination files to the same value as the source files.</p>



<p><strong><span style="text-decoration: underline;"><code>--group, -g</code></span></strong><br><strong>Preserve group</strong><br>This option causes rsync to <strong><span style="text-decoration: underline;">set the group of the destination file to be the same as the source file</span></strong>.<br><span style="text-decoration: underline;">If the receiving program is not running as the super-user (or if <code>--no-super</code> was specified), only groups that the invoking user on the receiving side is a member of will be preserved</span>. Without this option, the group is set to the default group of the invoking user on the receiving side.</p>



<p><strong><span style="text-decoration: underline;"><code>--owner, -o</code></span></strong><br>This option causes rsync to <strong><span style="text-decoration: underline;">set the owner of the destination file to be the same as the source file, but only if the receiving rsync is being run as the super-user</span></strong> (see also the <code>--super</code> and <code>--fake-super</code> options).<br>Without this option, the owner of new and/or transferred files are set to the invoking user on the receiving side.</p>



<p><strong><span style="text-decoration: underline;"><code>--acls, -A</code></span></strong><br>This option causes rsync to <strong><span style="text-decoration: underline;">update the destination ACLs to be the same as the source ACLs</span></strong>.<br>The option also implies <code>--perms</code>.<br>The source and destination systems must have compatible ACL entries for this option to work properly.<br>See the <code>--fake-super</code> option for a way to backup and restore ACLs that are not compatible.</p>



<p><strong><span style="text-decoration: underline;"><code>--xattrs, -X</code></span></strong><br>This option causes rsync to update the destination extended attributes to be the same as the source ones.</p>



<p><strong><span style="text-decoration: underline;"><code>--hard-links, -H</code></span></strong><br>This tells rsync to look for hard-linked files in the source and link together the corresponding files on the destination. Without this option, hard-linked files in the source are treated as though they were separate files.<br><br>This option does NOT necessarily ensure that the pattern of hard links on the destination exactly matches that on the source.</p>



<h2>Usual Usage</h2>



<p><strong><span style="text-decoration: underline;">Local SRC_DIR > Local DST_DIR</span></strong><br>NOTE: By default, if Local DST_DIR does not exist it is created</p>



<pre class="wp-block-code"><code><span style="text-decoration: underline;">Copy SRC_DIR inside /path/to/local/DST_DIR/ : /path/to/local/DST_DIR/SRC_DIR</span>
$ rsync -av --info=progress2 /path/to/local/SRC_DIR /path/to/local/DST_DIR

<span style="text-decoration: underline;">Copy &lt;src_path>'s content inside &lt;dst_path>/</span>
$ rsync -av --info=progress2 &lt;src_path><strong>/</strong> &lt;dst_path>/
$ rsync -av --info=progress2 &lt;src_path><strong>/*</strong> &lt;dst_path>/</code></pre>



<p><strong><span style="text-decoration: underline;">Local SRC_FILE > Local DST</span></strong></p>



<pre class="wp-block-code"><code>$ rsync -av --info=progress2 /path/to/local/SRC_FILE /path/to/local/DST</code></pre>



<p><span style="text-decoration: underline;">IF DST is a directory</span>, it copies SRC_FILE inside DST (DIR)<br><br><span style="text-decoration: underline;">IF DST is a file</span>, its content is replaced with the content of SRC_FILE<br>(with -a option ONLY mtime is the same, atime, ctime are different, you may use -U + -N options)<br><br><span style="text-decoration: underline;">If DST does not exist</span> :<br>&#8211; if there is a trailing slash &#8216;/&#8217; it creates the directory DST (only for a direct subdirectory of an existing path &#8220;mkdir -p does not work&#8221; ) AND copies SRC_FILE inside DST<br><br>&#8211; otherwise it creates file DST (copy of SRC_FILE)</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>qpdf: PDF Transformation Software</title>
		<link>https://itec4b.com/qpdf-pdf-transformation-software/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Sat, 25 Feb 2023 17:16:05 +0000</pubDate>
				<category><![CDATA[Application]]></category>
		<category><![CDATA[File Manipulation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[qpdf]]></category>
		<category><![CDATA[file manipulation]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[pdf]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=1573</guid>

					<description><![CDATA[qpdf is both a free command-line program and a C++ library (open source PDF manipulation library) for structural, content-preserving transformations on PDF files.qpdf has been designed with very few external dependencies and is intentionally very lightweight. It was created in 2005 by Jay Berkenbilt. One of the main features is the capability to merge and &#8230; <p class="link-more"><a href="https://itec4b.com/qpdf-pdf-transformation-software/" class="more-link">Read more<span class="screen-reader-text"> "qpdf: PDF Transformation Software"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><a href="http://qpdf.sourceforge.net">qpdf</a> is both a free command-line program and a C++ library (open source PDF manipulation library) for structural, content-preserving transformations on PDF files.<br>qpdf has been designed with very few external dependencies and is intentionally very lightweight.<br><br>It was created in 2005 by Jay Berkenbilt.<br><br><strong><span style="text-decoration: underline;">One of the main features is the capability to merge and split PDF files by selecting pages from one or more input files</span></strong>.<br><span style="text-decoration: underline;"><strong>It is also capable of performing a variety of transformations such as linearization (known as web optimization or fast web viewing), encryption, and decryption of PDF files</strong></span>.<br><br><a href="https://qpdf.readthedocs.io/en/stable/cli.html">qpdf Online Documentation</a><br><br><span style="text-decoration: underline;">qpdf Local Documentation</span>: /usr/share/doc/qpdf/qpdf-manual.html</p>



<h2>Portable Document Format</h2>



<p><a href="https://www.adobe.com/acrobat/about-adobe-pdf.html">Adobe created the PDF in 1992 by Dr. John Warnock</a>, offering an easy, reliable way to present and exchange documents regardless of the software, hardware, or operating systems being used.<br>Today, it is one the most trusted file formats around the world, it can be easily viewed on any operating system.<br><br><span style="text-decoration: underline;">PDF was standardized as ISO 32000 in 2008 as an open standard</span>.<br>The PDF format is now maintained by the International Organization for Standardization (ISO).<br><span style="text-decoration: underline;">ISO 32000-2:2020 edition was published in December 2020, it does not include any proprietary technologies</span>.</p>



<p>The PDF specification also provides for encryption (in which case a password is needed to view or edit the contents), digital signatures (to provide secure authentication), file attachments, and metadata.<br>PDF 2.0 defines 256-bit AES encryption as standard for PDF 2.0 files.<br><br>The standard security provided by PDF consists of two different passwords:<br><br>&#8211; user password, which encrypts the file and prevents opening<br><br>&#8211; owner password, which specifies operations that should be restricted even when the document is decrypted, which can include modifying, printing, or copying text and graphics out of the document, or adding or modifying text notes.</p>



<p>The user password encrypts the file, the owner password does not, instead relying on client software to respect content restrictions.<br>An owner password can easily be removed by software.<br>Thus, the used restrictions that an author places on a PDF document are not secure, and cannot be assured once the file is distributed.</p>



<p>Metadata includes information about the document and its content, such as the author’s name, document title, description, creation/modification dates, application used to create the file, keywords, copyright information, etc.</p>



<h2>Install qpdf (Debian)</h2>



<pre class="wp-block-code"><code># apt install qpdf</code></pre>



<h2>Usage</h2>



<p><code>--linearize</code><br>Create linearized (web-optimized) output file.<br>Linearized files are formatted in a way that allows compliant readers to begin displaying a PDF file before it is fully downloaded.<br>Ordinarily, the entire file must be present before it can be rendered because important cross-reference information typically appears at the end of the file.</p>



<pre class="wp-block-code"><code>$ qpdf --linearize infile.pdf  outfile.pdf</code></pre>



<h2>Merge PDF files with pages selection</h2>



<p>qpdf allows you to use the <code>--pages</code> option to select pages from one or more input files.</p>



<pre class="wp-block-code"><code>$ qpdf primary_input_file.pdf --pages . &#91;--password=password] &#91;page-range] &#91; ... ] -- outputfile.pdf

Within &#91; ... ] you may repeat the following:  inputfile_N.pdf &#91;--password=password] &#91;page-range]</code></pre>



<p>The special input file <code>'.'</code> can be used as an alias for the primary input file.<br>Multiple input files may be specified and you can select specific pages from it.<br>For each inputfile that pages should be extracted from, specify the filename, a password (if needed) to open the file, and a page range.<br>Note that <code>'--'</code> terminates parsing of page selection flags.<br><br><code>--password=password</code> specifies a password for accessing encrypted files<br>The password option is only needed for password-protected files<br><br>The page range may be omitted. In this case, all pages are included.<br><br>Document-level information (metadata, outline, etc.) is taken from the primary input file (in the above example, <code>primary_input_file.pdf</code>) and is preserved in <code>outputfile.pdf</code><br><strong><span style="text-decoration: underline;">You can use <code>--empty</code> in place of the primary input file to start from an empty file (without any metadata, outline, etc.) and just merge selected pages from input files</span></strong>.<br><br><strong><span style="text-decoration: underline;">In most cases you will most likely use this following syntax</span></strong></p>



<pre class="wp-block-code"><code>$ qpdf --empty --pages inputfile_1.pdf &#91;page-range] inputfile_2.pdf &#91;page-range] inputfile_3.pdf &#91;page-range] &#91; ... ] -- outputfile.pdf</code></pre>



<p>The page-range is a set of numbers separated by commas, ranges of numbers separated dashes, or combinations of those.<br>The character <code>'z'</code> represents the last page.<br>A number preceded by an <code>'r'</code> indicates to count from the end, so <code>r3-r1</code> would be the last three pages of the document.<br>Pages can be specified in any order (selection of any pages).<br>Ranges can be specified in any order (ascending or descending): a high number followed by a low number causes the pages to appear in reverse.<br>Numbers may be repeated in a page range.<br>A page range may be optionally appended with <code>:even</code> or <code>:odd</code> to indicate only the even or odd pages in the given range.<br>Note that even and odd refer to the positions within the specified, range, not whether the original number is even or odd.<br><br><span style="text-decoration: underline;">Example page ranges</span>:<br><br>1,3,5-9,15-12<br>Pages 1, 3, 5, 6, 7, 8, 9, 15, 14, 13, and 12 in that order</p>



<p>z-1<br>All pages in the document in reverse</p>



<p>r3-r1<br>The last three pages of the document</p>



<p>r1-r3<br>The last three pages of the document in reverse order</p>



<p>1-20:even<br>Even pages from 2 to 20</p>



<p>5,7-9,12:odd<br>Pages 5, 8 and 12, which are the pages in odd positions from among the original range (pages 5, 7, 8, 9, and 12)</p>



<pre class="wp-block-code"><code>Example, to extract pages 1 through 5 from infile.pdf while preserving all metadata associated with that file in outfile.pdf
$ qpdf infile.pdf --pages . 1-5 -- outfile.pdf

If you want pages 1 through 5 from infile.pdf without any metadata, use
$ qpdf --empty --pages infile.pdf 1-5 -- outfile.pdf

Merge all .pdf files
$ qpdf --empty  --pages *.pdf -- outfile.pdf</code></pre>



<h2>Split a PDF into separate PDF files</h2>



<p><code>--split-pages[=n]</code><br>Write each group of n pages to a separate output file.<br>If n is not specified, create single pages.<br><br>Output file names are generated as follows:<br>If the string %d appears in the output file name, it is replaced with a range of zero-padded page numbers starting from 1.<br>Otherwise, if the output file name ends in .pdf (case insensitive), a zero-padded page range, preceded by a dash, is inserted before the file extension.<br>Otherwise, the file name is appended with a zero-padded page range preceded by a dash.<br><br>Zero padding is added to all page numbers in file names so that all the numbers are the same length, which causes the output filenames to sort lexically in numerical order.<br><br>Page ranges are a single number in the case of single-page groups or two numbers separated by a dash otherwise.<br><br>Here are some examples. In these examples, infile.pdf has 20 pages</p>



<pre class="wp-block-code"><code>Output files are 01-outfile through 20-outfile with no extension
$ qpdf --split-pages infile.pdf %d-outfile

Output files are outfile-01.pdf through outfile-20.pdf
$ qpdf --split-pages infile.pdf outfile.pdf

Output files are outfile-01-04.pdf, outfile-05-08.pdf, outfile-09-12.pdf, outfile-13-16.pdf, outfile-17-20.pdf
$ qpdf --split-pages=4 infile.pdf outfile.pdf

Output files are outfile.notpdf-01 through outfile.notpdf-20
The extension .notpdf is not treated in any special way regarding the placement of the number
$ qpdf --split-pages infile.pdf outfile.notpdf</code></pre>



<p>Note that metadata, outline, etc, and other document-level features of the original PDF file are not preserved.<br>For each page of output, this option creates an empty PDF and copies a single page from the output into it.<br>If you require the document-level data, you will have to run qpdf with the <code>--pages</code> option once for each page.<br>Using <code>--split-pages</code> is much faster if you don’t require the document-level data.<br><br><span style="text-decoration: underline;">If you don’t want to split out every page, use page ranges to select the pages you only want to extract</span>.<br>The page range is used to specify the pages or ranges you want, <span style="text-decoration: underline;">but each extracted page is still stored in a single PDF</span>.</p>



<pre class="wp-block-code"><code>$ qpdf --split-pages infile.pdf outfile.pdf --pages infile.pdf 4-5,8,9-13 --</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Linux: ASCII random string generator</title>
		<link>https://itec4b.com/linux-ascii-random-string-generator/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Thu, 23 Feb 2023 16:20:49 +0000</pubDate>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[password]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=1567</guid>

					<description><![CDATA[https://github.com/ITEC4B/ASCII-random-string-generator]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code><strong><span style="text-decoration: underline;">Generate a random ASCII string (40 printable characters without empty spaces)</span></strong>

$ cat /dev/urandom | tr -dc '&#91;:graph:]' | head -c 40
OR
$ cat /dev/urandom | tr -dc '&#91;:alnum:]&#91;:punct:]' | head -c 40

&#91;:lower:]   All lower case letters     abcdefghijklmnopqrstuvwxyz
&#91;:upper:]   All upper case letters     ABCDEFGHIJKLMNOPQRSTUVWXYZ
&#91;:alpha:]   All letters
&#91;:digit:]   All digits                 0123456789
&#91;:alnum:]   All letters and digits
&#91;:punct:]   All punctuation characters !"#$%&amp;'()*+,-./:;&lt;=>?@&#91;\]^_`{|}~
&#91;:graph:]   All printable characters, not including space
&#91;:print:]   All printable characters, including space</code></pre>



<p><a href="https://github.com/ITEC4B/ASCII-random-string-generator">https://github.com/ITEC4B/ASCII-random-string-generator</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Linux Symbolic/Hard Links</title>
		<link>https://itec4b.com/linux-symbolic-hard-links/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Sun, 12 Feb 2023 20:03:14 +0000</pubDate>
				<category><![CDATA[File System]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[inode]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=1309</guid>

					<description><![CDATA[To understand links in a file system, you first have to understand what an inode is. In linux there are two types of links :&#8211; Soft/Symbolic Links&#8211; Hard Links Hard Links Every file on the Linux filesystem starts with a single hard link.The link is between the filename and the actual data stored on the &#8230; <p class="link-more"><a href="https://itec4b.com/linux-symbolic-hard-links/" class="more-link">Read more<span class="screen-reader-text"> "Linux Symbolic/Hard Links"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><span style="text-decoration: underline;">To understand links in a file system, you first have to understand <a href="https://itec4b.com/linux-filesystem-directory-entries-inodes-datablocks">what an inode is</a></span>.<br><br><span style="text-decoration: underline;"><strong>In linux there are two types of links</strong></span> :<br>&#8211; <strong>Soft/Symbolic Links</strong><br>&#8211; <strong>Hard Links</strong></p>



<h2>Hard Links</h2>



<p><span style="text-decoration: underline;">Every file on the Linux filesystem starts with a single hard link</span>.<br>The link is between the filename and the actual data stored on the filesystem (directory entry &gt; inode &gt; data blocks).<br><br><strong><span style="text-decoration: underline;">When you create a hard link you create a file that gets the same inode as the target file</span></strong>.<br><span style="text-decoration: underline;"><strong>You have different file names/paths for a unique physical file on a partition (pointing to the same inode)</strong></span> </p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-hardlink-inodes-datablocks.png"><img decoding="async" src="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-hardlink-inodes-datablocks.png" alt="" class="wp-image-1321" width="697" height="393" srcset="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-hardlink-inodes-datablocks.png 929w, https://itec4b.com/wp-content/uploads/2023/02/linux-schema-hardlink-inodes-datablocks-300x169.png 300w, https://itec4b.com/wp-content/uploads/2023/02/linux-schema-hardlink-inodes-datablocks-768x433.png 768w" sizes="(max-width: 697px) 100vw, 697px" /></a></figure></div>


<p class="has-vivid-red-color has-text-color"><strong><span style="text-decoration: underline;">Hard links can only be created for regular files (not directories or special files) and ONLY within the same filesystem.<br>A hard link cannot span multiple filesystems</span></strong>.</p>



<p class="has-black-color has-text-color">If you delete the <code>"</code>original file<code>"</code>, you can still access it via any remaining hard link having the same inode.<br>Apart from the filename/filepath, you cannot tell which one is the hard link since they share the same inode.</p>



<pre class="wp-block-code"><code>$ ln /path/to/target_file /path/to/hardlink</code></pre>



<pre class="wp-block-code"><code><strong><span style="text-decoration: underline;">List inodes files from &lt;dir>, Recursive, No Sort, date (mtime)</span></strong>
<strong>CMD_LS_RECURSIVE_INODE_MTIME_NOSORT</strong>
<strong><span style="text-decoration: underline;">OUTPUT</span>:</strong>
<strong>&lt;inode> &lt;mode?rwx> &lt;links> &lt;uname> &lt;gname> &lt;size_bytes> &lt;date YYYY-MM-DD> &lt;time hh:mm:ss> &lt;filepath></strong>

$ LC_ALL=C ls -ilR --time-style='+%F %T' &lt;dir> 2>/dev/null | sed -e '/:$/,/^total &#91;0-9]\{1,\}/d' -n -e '/^&#91;0-9]\{1,\} -/p' | tr -s '\n'


<strong><span style="text-decoration: underline;">List inodes with hard link(s) from &lt;dir>, Recursive, Natural Sort (inode first), date (mtime)</span></strong>
<strong><span style="text-decoration: underline;">OUTPUT</span>:</strong>
<strong>&lt;inode> &lt;mode?rwx> &lt;links> &lt;uname> &lt;gname> &lt;size_bytes> &lt;date YYYY-MM-DD> &lt;time hh:mm:ss> &lt;filepath></strong>

$ &lt;CMD_LS_RECURSIVE_INODE_MTIME_NOSORT> | awk '$3 > 1 {print $0}' | sort


<span style="text-decoration: underline;"><strong>Find inodes with hard link(s)</strong></span>
<strong><span style="text-decoration: underline;">OUTPUT</span>:</strong> <strong>&lt;inode></strong>
$ &lt;CMD_LS_RECURSIVE_INODE_MTIME_NOSORT> | awk '$3 > 1 {print $1}' | sort -u</code></pre>



<h2>Soft/Symbolic Links</h2>



<p><strong><span style="text-decoration: underline;">When you create a soft link, you create a new file with a new inode, which points to the target path</span></strong>.<br><strong><span style="text-decoration: underline;">It doesn&#8217;t reference the target inode</span></strong>. <strong><span style="text-decoration: underline;">If the target&#8217;s path/name changes or is deleted, the reference breaks (pointing to a nonexistent file path)</span></strong>.<br><br>Symbolic links can link together non-regular and regular files.<br><span style="text-decoration: underline;"><strong>They also can span multiple filesystems</strong></span>.<br><br><strong><span style="text-decoration: underline;">A symbolic link is identified by the mode lrwxrwxrwx, you cannot change it</span></strong>, so it is easy to identify them.<br>The symbolic link&#8217; size is the target&#8217;s path length.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-softlink-inodes-datablocks.png"><img decoding="async" loading="lazy" src="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-softlink-inodes-datablocks.png" alt="" class="wp-image-1322" width="721" height="393" srcset="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-softlink-inodes-datablocks.png 961w, https://itec4b.com/wp-content/uploads/2023/02/linux-schema-softlink-inodes-datablocks-300x164.png 300w, https://itec4b.com/wp-content/uploads/2023/02/linux-schema-softlink-inodes-datablocks-768x419.png 768w" sizes="(max-width: 721px) 100vw, 721px" /></a></figure></div>


<p>Changing owner, group, permissions of a symbolic link only has effect on the target file, in this case target file&#8217;s ctime is updated.<br><br>A change to a symlink name, updates its access time (atime) and status time (ctime).<br>That is the only thing you can change for the symbolic file itself.</p>



<pre class="wp-block-code"><code>$ ln -s /path/to/target_file /path/to/symlink</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Linux Filesystem: Directory Entries, Inodes, Data Blocks</title>
		<link>https://itec4b.com/linux-filesystem-directory-entries-inodes-datablocks/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Sat, 11 Feb 2023 17:00:39 +0000</pubDate>
				<category><![CDATA[File System]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[inode]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=1126</guid>

					<description><![CDATA[An inode is a unique number assigned to each Linux file and directory in a filesystem (except for hard links), it is used as an index (Index Node). Inodes store metadata (attributes) about the files they refer to (it is like the "file&#8217;s identity card" without the name)ANDBecause the data of a file is actually &#8230; <p class="link-more"><a href="https://itec4b.com/linux-filesystem-directory-entries-inodes-datablocks/" class="more-link">Read more<span class="screen-reader-text"> "Linux Filesystem: Directory Entries, Inodes, Data Blocks"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><span style="text-decoration: underline;"><strong>An inode is a unique number assigned to each Linux file and directory in a filesystem (except for <a href="https://itec4b.com/linux-symbolic-hard-links">hard links</a>), it is used as an index (Index Node)</strong></span>.<br><br><strong><span style="text-decoration: underline;">Inodes store metadata (attributes) about the files they refer to (it is like the <code>"</code>file&#8217;s identity card<code>"</code> without the name)</span></strong><br><strong>AND</strong><br>Because the data of a file is actually stored into data blocks on a physical drive, <strong><span style="text-decoration: underline;">serve as a reference to the disk blocks locations of the data they point to (via data block pointers)</span></strong>.<br><span style="text-decoration: underline;">Note that this information is not directly accessible to the user</span>.<br><br>Thus, an inode is a data structure in a Unix-style filesystem that describes a filesystem object such as a file or a directory.<br><br><span style="text-decoration: underline;">A <strong>block device</strong> is a storage device from which you can read/write data blocks</span>.<br>You create partitions on it and then format it with a <strong>filesystem</strong> that dictates how the files are organized/managed.<br><span style="text-decoration: underline;">Every filesystem needs to split up a partition into data blocks to store files and file parts</span>.<br><br>A <strong>data block</strong> is the basic unit of data storage in a filesystem.<br>It is the smallest unit of data that can be read or written in a single operation.<br>In most filesystems, each data block has a fixed size, typically between 512 and 4096 bytes.<br><span style="text-decoration: underline;"><strong>Today the default is usually 4096 bytes for storage I/O and filesystems</strong></span>.<br><br>With a default filesystem block size of 4096 bytes, if you have a data file of 3 bytes (logical size), it will take away 1 block (4096 bytes: physical size on storage device) from your disk&#8217;s capacity, since that is the smallest unit of the filesystem.<br>If you have a data file of 4097 bytes it will take 2 blocks.</p>



<pre class="wp-block-code"><code><strong><span style="text-decoration: underline;">NOTE</span></strong>:
'stat' command provides 'Size:' and 'Blocks:' informations
'Size:' is the data file' size in bytes (logical size)
'Blocks:' is the real disk usage in blocks of 512 bytes (physical size)

<strong><span style="text-decoration: underline;">List size files from DIR</span></strong>
<strong>OUTPUT: &lt;logical_size_bytes> &lt;physical_size_bytes> &lt;filepath></strong>

$ LC_ALL=C find DIR -type f -exec stat -c '%s %b %B %n' {} + 2>/dev/null | awk '{ fname=""; for (i=4; i &lt;= NF; i++) fname=fname $i " "; print $1" "($2*$3)" "fname }'</code></pre>



<p>Linux ext filesystem uses a default 4096 bytes for a block size because that&#8217;s the default pagesize of CPUs, so there&#8217;s an easy mapping between memory-mapped files and disk blocks.<br>The hardware (specifically, the Memory Management Unit, which is part of the CPU) determines what page sizes are possible. It is the smallest unit of data for memory management in a virtual memory operating system. Almost all architectures support a 4kB page size. Modern architectures support larger pages (and a few also support smaller pages), but <strong><span style="text-decoration: underline;">4kB is a very widespread default</span></strong>.</p>



<pre id="block-5bda9865-bf3c-48ec-b7c1-7ad5af414fbc" class="wp-block-code"><code><span style="text-decoration: underline;">Get the filesystem block size in bytes</span>
(size used internally by kernel, it may be modified by filesystem driver on mount)
# blockdev --getbsz /dev/&lt;device&gt;

<span style="text-decoration: underline;">Get the system's page size</span>
(number of bytes in a memory page, where "page" is a fixed-length block, the unit for memory allocation and file mapping)
$ getconf PAGE_SIZE
$ getconf PAGESIZE</code></pre>



<pre class="wp-block-code"><code><span style="text-decoration: underline;">Print inode's metadata for a specific file/dir using stat command</span>
$ LC_ALL=C stat /path/to/file_or_dir
$ LC_ALL=C stat -c '%i %y %A %U %s %N' /path/to/file_or_dir | sed -e 's;&#91;.]&#91;0-9]\{9\} +&#91;0-9]\{4\};;g'

<span style="text-decoration: underline;">Get inode number(s) with ls -i</span>
$ ls -i1 /path/to/file_or_dir</code></pre>



<pre class="wp-block-code"><code>Get the number of blocks a file uses on disk, so you can calculate disk space really used per file (physical file size).
<span style="text-decoration: underline;"><strong>IMPORTANT</strong></span>:
<strong><span style="text-decoration: underline;">By default 'ls', 'du' and 'df' commands use 1block=1024bytes which may differ from the filesystem unit</span>. <span style="text-decoration: underline;">You can use --block-size option or <a href="https://www.gnu.org/software/coreutils/manual/html_node/Block-size.html">set environment variables</a></span></strong>:
Display values are in units of the first available SIZE from --block-size, DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

$ du --block-size=4096 /path/to/file
$ ls -s --block-size=4096 /path/to/file

<span style="text-decoration: underline;">ls -l prints the data size in bytes (logical file size), which is less than the actual used space on disk</span>.</code></pre>



<h2><strong>Inodes Metadata</strong></h2>



<pre class="wp-block-code"><code>$ man inode</code></pre>



<p>&#8211; <span style="text-decoration: underline;"><strong>Inode number</strong></span><br>Each file in a filesystem has a unique inode number (except for hard links).<br>Inode numbers are guaranteed to be unique only within a filesystem (i.e. <span style="text-decoration: underline;"><strong>the same inode numbers may be used by different filesystems, which is the reason that hard links may not cross filesystem boundaries</strong></span>).</p>



<p>&#8211; <strong><span style="text-decoration: underline;">Device where inode resides</span></strong><br>Each inode (as well as the associated file) resides in a filesystem that is hosted on a device.<br>That device is identified by the combination of its major ID (which identifies the general class of device) and minor ID (which identifies a specific instance in the general class).<br><br>&#8211; <strong><span style="text-decoration: underline;">Device represented by this inode</span></strong><br>If the current file (inode) represents a device, then the inode records the major and minor ID of that device.<br><br>&#8211; <strong><span style="text-decoration: underline;">Links count</span></strong> (number of hard links to the file)<br><br>&#8211; <strong><span style="text-decoration: underline;">User ID</span></strong> (of the owner of the file)<br><br>&#8211; <strong><span style="text-decoration: underline;">Group ID</span></strong> (of the file)<br><br>&#8211; <strong><span style="text-decoration: underline;">Mode</span></strong>: <strong><span style="text-decoration: underline;">File Type</span></strong> + <strong><span style="text-decoration: underline;">Permissions</span></strong> (read, write and execute permissions of the file for the owner, group and others)<br>The standard Unix file types are regular, directory, symbolic link, FIFO (named pipe), block device, character device, and socket as defined by POSIX.<br><br>&#8211; <span style="text-decoration: underline;"><strong>File size (in bytes)</strong></span><br>This field gives the size of the file (if it is a regular file) in bytes.<br>The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.<br>Default size for a directory is usually one block size (4096 bytes on most ext4 filesystems).<br><br>&#8211; <strong><span style="text-decoration: underline;">Preferred block size for I/O operations (in bytes)</span></strong><br>This field gives the <code>"</code>preferred<code>"</code> block size for efficient filesystem I/O operations.<br>(Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite)<br><br>&#8211; <strong><span style="text-decoration: underline;">Number of blocks allocated to the file</span></strong><br>This field indicates the <strong>number of blocks allocated to the file in 512-byte units</strong><br><br>&#8211; <strong><span style="text-decoration: underline;">File creation (birth) timestamp (btime)</span></strong><br>This is set on file creation and not changed subsequently.<br>The btime timestamp was not historically present on UNIX systems and is not currently supported by most Linux filesystems.<br><br>&#8211; <strong><span style="text-decoration: underline;">Last modification timestamp (mtime)</span></strong><br>This is the file&#8217;s last modification timestamp. It is changed by file modifications (file&#8217;s content: data).<br>Moreover, the mtime timestamp of a directory is changed by the creation or deletion of files in that directory.<br><span style="text-decoration: underline;">The mtime timestamp is not changed for changes in file&#8217;s name, owner, group, hard link count, or mode.</span><br><br>&#8211; <strong><span style="text-decoration: underline;">Last access timestamp (atime)</span></strong><br>It is changed by file accesses.<br><br>&#8211; <strong><span style="text-decoration: underline;">Last status change timestamp (ctime)</span></strong><br>It is changed by modifying file&#8217;s metadata information (i.e. file&#8217;s name, owner, group, link count, mode, etc.).</p>



<p><span style="text-decoration: underline;"><strong>According to The POSIX standard an inode is a <code>"</code>file serial number<code>"</code>, defined as a per-filesystem unique identifier for a file.<br>Combined together with the device ID of the device containing the file, they uniquely identify the file within the whole system</strong></span>.</p>



<p>Two files can have the same inode, but only if they are part of different partitions (except for hard links).<br><strong><span style="text-decoration: underline;">Inodes are only unique on a partition level, not on the whole system</span></strong>.</p>



<h2>Directory Entry</h2>



<p>You may have noticed that inodes do not contain the file&#8217;s name.<br><strong><span style="text-decoration: underline;">The file’s name is not stored in the inode metadata but in its directory structure</span></strong>.<br><strong><span style="text-decoration: underline;">UNIX systems use a directory stream mapping system: directory entries contain the filenames and their inodes number</span></strong>.<br><br><strong>From a user perspective a directory contains files, technically a directory is a structure used to locate other files/directories.<br>In most Unix filesystems, a directory is a mapping from filenames to inode numbers</strong>.<br><strong>There&#8217;s a separate table mapping inode numbers to inode data</strong>.<br><br><span style="text-decoration: underline;">The header file <code><strong>dirent.h</strong></code> describes the format of a directory entry</span>.<br><br>Format of a Directory Entry<br><a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html">https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html</a><br><a href="https://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html">https://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html</a><br><br><span style="text-decoration: underline;">In the glibc implementation, the <strong>dirent structure</strong> is defined as follows</span>:</p>



<pre class="wp-block-code"><code>struct dirent {
   ino_t   d_ino;              /* Inode number */
   off_t   d_off;              /* Not an offset */
   unsigned short   d_reclen;  /* Length of this record */
   unsigned char   d_type;     /* Type of file; not supported by all filesystem types */
   char d_name&#91;256];           /* Null-terminated filename */
};</code></pre>



<p><strong><span style="text-decoration: underline;">The only fields in the <code>dirent</code> structure that are mandated by POSIX.1 are <code>d_name</code> and <code>d_ino</code></span></strong>.<br>The other fields are unstandardized, and not present on all systems.</p>



<pre class="wp-block-code"><code>/* This is the data type of directory stream objects. */
typedef struct __dirstream DIR;

The DIR data type represents a directory stream.
You shouldn’t ever allocate objects of the struct dirent or DIR data types, since the directory access functions do that for you. Instead, you refer to these objects using the pointers returned by the <a href="https://www.gnu.org/software/libc/manual/html_node/Opening-a-Directory.html">functions</a>.
Directory streams are a high-level interface.</code></pre>



<p><span style="text-decoration: underline;">The design of data block pointers is actually more complex than the schema illustrates below</span>, it also depends on the filesystem. For ext filesystem an inode pointer structure is used to list the addresses of a file&#8217;s data blocks (around 15 direct/indirect data blocks pointers).</p>



<div style="height:18px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-dir-inodes-datablocks.jpg"><img decoding="async" loading="lazy" src="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-dir-inodes-datablocks.jpg" alt="" class="wp-image-1160" width="697" height="361" srcset="https://itec4b.com/wp-content/uploads/2023/02/linux-schema-dir-inodes-datablocks.jpg 929w, https://itec4b.com/wp-content/uploads/2023/02/linux-schema-dir-inodes-datablocks-300x155.jpg 300w, https://itec4b.com/wp-content/uploads/2023/02/linux-schema-dir-inodes-datablocks-768x398.jpg 768w" sizes="(max-width: 697px) 100vw, 697px" /></a></figure></div>


<h2>Filesystem</h2>



<p><strong><span style="text-decoration: underline;">Linux uses filesystems to manage data stored on storage devices</span></strong>.<br>The filesystem manages a map (inodes table) to locate each file placed in the storage device.<br>The filesystem divides the partition into blocks: small contiguous areas.<br>The size of these blocks is defined during creation of the filesystem.<br><br><span style="text-decoration: underline;"><strong>Before you can mount a drive partition, you must format it using a filesystem</strong></span>.<br><br><span style="text-decoration: underline;"><strong>The default filesystem used by most Linux distributions is ext4</strong></span>.<br>ext4 filesystem provides journaling, which is a method of tracking data not yet written to the drive in a log file, called the journal. If the system fails before the data can be written to the drive, the journal data can be recovered and stored upon the next system boot.<br><br>After creating a partition, you need to create a filesystem (mkfs program is specifically dedicated for that)</p>



<pre class="wp-block-code"><code>#  LC_ALL=C mkfs -t ext4 /dev/&lt;partition_id&gt;</code></pre>



<p><strong><span style="text-decoration: underline;">Some filesystems (ext4 included), allocate a limited number of inodes when created</span></strong>.<br><strong><span style="text-decoration: underline;">If the filesystem runs out of inode entries in the table, you cannot create any more files, even if there is still space available on the drive: that may happen with a multitude of very small files</span></strong>.<br>When a file is created on the partition or volume, a new entry in the inode table is created.<br>Using the <code>-i</code> option with the <code>df</code> command will show you the percentage of inodes used.<br>It is theoretically possible (although uncommon) that you could run out of available inodes while still having actual space left on your partition, so it’s worth keeping that in mind.<br><br><span style="text-decoration: underline;"><strong>Report file system disk space usage</strong></span></p>



<pre class="wp-block-code"><code><span style="text-decoration: underline;">By blocks (most important)</span>
$ LC_ALL=C df -Th --block-size=4096 -x tmpfs -x devtmpfs -x squashfs 2&gt;/dev/null

<span style="text-decoration: underline;">By inodes</span>
$ LC_ALL=C df -Ti -x tmpfs -x devtmpfs -x squashfs 2&gt;/dev/null</code></pre>



<p>Linux uses <code><strong>e2fsprogs</strong></code> package to provide utilities for working with ext filesystems</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Debian: C/C++ Development Environment</title>
		<link>https://itec4b.com/debian-c-c-development-environment/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Wed, 01 Feb 2023 17:59:40 +0000</pubDate>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=919</guid>

					<description><![CDATA[The GNU C Library (glibc) Reference ManualThe GNU C++ LibraryGCC online documentationGNU Make Manual ISO C programming language standardISO C++ Standards Package: build-essentialThis package is normally required for building Debian packages, it is OK to install it since it includes all what is necessary to get a C/C++ Development Environment. Package: gcc-docDocumentation for the GNU &#8230; <p class="link-more"><a href="https://itec4b.com/debian-c-c-development-environment/" class="more-link">Read more<span class="screen-reader-text"> "Debian: C/C++ Development Environment"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><a href="https://www.gnu.org/software/libc/manual">The GNU C Library (glibc) Reference Manual</a><br><a href="https://gcc.gnu.org/onlinedocs/libstdc++">The GNU C++ Library</a><br><a href="https://gcc.gnu.org/onlinedocs">GCC online documentation</a><br><a href="https://www.gnu.org/software/make/manual">GNU Make Manual</a><br><br><a href="https://www.open-std.org/JTC1/SC22/WG14/www/projects#9899">ISO C programming language standard</a><br><a href="https://www.open-std.org/JTC1/SC22/WG21/docs/standards">ISO C++ Standards</a></p>



<p><br><span style="text-decoration: underline;">Package: <strong>build-essential</strong></span><br>This package is normally required for building Debian packages, it is OK to install it since it includes all what is necessary to get a C/C++ Development Environment.</p>



<pre class="wp-block-code"><code># apt install build-essential</code></pre>



<p><span style="text-decoration: underline;">Package: <strong>gcc-doc</strong></span><br>Documentation for the GNU compilers (gcc, gobjc, g++)</p>



<pre class="wp-block-code"><code># apt install gcc-doc</code></pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p><span style="text-decoration: underline;">Virtual Package: <strong>libc-dev</strong></span><br>Package: <strong>libc<span style="text-decoration: underline;">&lt;version&gt;</span>-dev</strong><br>GNU C Library: Development Libraries and Header Files<br>Contains the symlinks, headers, and object files needed to compile and link programs which use the standard C library<br><br><span style="text-decoration: underline;">Package: <strong>libstdc++-&lt;version&gt;-dev</strong></span><br>GNU Standard C++ Library v3 (development files)<br>This package contains the headers and static library files necessary for building C++ programs which use libstdc++.<br><br><span style="text-decoration: underline;">Package: <strong>libstdc++-&lt;version&gt;-doc</strong></span><br>GNU Standard C++ Library v3 (documentation files)<br>This package contains documentation files for the GNU stdc++ library.<br><br><span style="text-decoration: underline;">Package: <strong>gcc</strong></span><br>GNU C compiler<br>This is the GNU C compiler, a fairly portable optimizing compiler for C.<br><br><span style="text-decoration: underline;">Package: <strong>g++</strong></span><br>GNU C++ compiler<br>This is the GNU C++ compiler, a fairly portable optimizing compiler for C++.</p>



<p><span style="text-decoration: underline;">Package: <strong>make</strong></span><br>Utility for directing compilation<br>GNU make is a utility which controls the generation of executables and other target files of a program from the program&#8217;s source files.<br>It determines automatically which pieces of a large program need to be (re)created, and issues the commands to (re)create them.<br>make can be used to organize any task in which targets (files) are to be automatically updated based on input files whenever the corresponding input is newer. It is not limited to building computer programs. Indeed, make is a general purpose dependency solver.<br><br><span style="text-decoration: underline;">Package: <strong>manpages-dev</strong></span><br>Manual pages about using GNU/Linux for development<br>These man pages describe the Linux programming interface, including these two sections:<br>2 = Linux system calls.<br>3 = Library calls (note that a more comprehensive source of information may be found in the glibc-doc and glibc-doc-reference packages).<br><br><span style="text-decoration: underline;">Package: <strong>ccache</strong></span><br>Compiler cache for fast recompilation of C/C++ code<br>It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Debian: List/Check Installed Packages</title>
		<link>https://itec4b.com/debian-list-check-installed-packages/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Wed, 01 Feb 2023 16:43:02 +0000</pubDate>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[packages]]></category>
		<category><![CDATA[shell script]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=916</guid>

					<description><![CDATA[List All Installed Packages Look For Specific Package(s)]]></description>
										<content:encoded><![CDATA[
<h3>List All Installed Packages</h3>



<pre class="wp-block-code"><code>$ LC_ALL=C dpkg-query -f '${Package} ${Version} ${Status}\n' -W | awk '{print $1" "$2" "$4" "$5}' | column -t</code></pre>



<h3>Look For Specific Package(s)</h3>



<pre class="wp-block-code"><code>Multiple package names and glob patterns works

$ LC_ALL=C dpkg-query -f '${Package} ${Version} ${Status}\n' -W &lt;pkg_name&gt; | awk '{print $1" "$2" "$4" "$5}' | column -t</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>C/C++ Compiler Operations</title>
		<link>https://itec4b.com/c-compiler-operations/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Mon, 30 Jan 2023 13:36:52 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=643</guid>

					<description><![CDATA[Sources : Delroy A. Brinkerhoff : Object-Oriented Programming using C++Brian Gough, Richard M. Stallman : An Introduction to GCC The process of translating source code into an executable program is called &#8220;compiling the program&#8221; or just &#8220;compiling&#8221;.We usually view the compilation process as a single action and generally refer to it as such.Nevertheless, a modern &#8230; <p class="link-more"><a href="https://itec4b.com/c-compiler-operations/" class="more-link">Read more<span class="screen-reader-text"> "C/C++ Compiler Operations"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p>Sources : <br><span style="text-decoration: underline;">Delroy A. Brinkerhoff : Object-Oriented Programming using C++</span><br><span style="text-decoration: underline;">Brian Gough, Richard M. Stallman : An Introduction to GCC</span></p>



<p><br><span style="text-decoration: underline;"><strong>The process of translating source code into an executable program is called &#8220;compiling the program&#8221; or just &#8220;compiling&#8221;</strong></span>.<br>We usually view the compilation process as a single action and generally refer to it as such.<br>Nevertheless, a <span style="text-decoration: underline;"><strong>modern compiler actually consists of 4 separate programs</strong></span>:</p>



<pre class="wp-block-code"><code>- <strong>Preprocessor</strong>
  Expand macros and included header files

- <strong>Compiler</strong>
  Convert source code to assembly language

- <strong>Assembler</strong>
  Convert assembly language to machine code

- <strong>Linker</strong>
  Link object files and binary libraries, Create the final executable</code></pre>



<p>So here is the process :</p>



<p class="has-text-color" style="color:#0a58ca"><span style="text-decoration: underline;"><strong>Source Code &gt; Preprocessor &gt; Compiler &gt; Assembler &gt; Linker &gt; Executable Program</strong></span></p>



<p>A single program usually consist of multiple source code files.<br>It is both awkward and inconvenient to deal with large programs in a single source code file, and spreading them over multiple files has many advantages:</p>



<p>1. It breaks large, complex programs into smaller, independent conceptual units<br>Easier to understand, follow and maintain.<br><br>2. It allows multiple programmers to work on a single program at the same time<br>Each programmer works on a separate set of files.<br><br>3. It may speed up compilation (depending on the compiler system options used)<br>The compiler system stores the generated machine code in an object file, one object file for each source code file. The compiler system may not delete the object files, so if the source code file is unchanged, the linker uses the existing object code file.<br><br>4. It permits related programs to share files<br>For example, office suites often include a word processor, a slide show editor, and a spreadsheet.<br>By maintaining the User Interface code in one shared file, they can present a consistent User Interface.<br><br>5. Although less important, it allows software developers to market software as object code organized as (binary black box) libraries, which is useful when supplying code that interfaces with applications.</p>



<p></p>



<h2>Preprocessor</h2>



<p><strong><span style="text-decoration: underline;">The Preprocessor takes the source code, removes the comments, includes headers, and replaces macros</span></strong>.<br><br>The preprocessor handles statements or lines of code that begin with the &#8220;#&#8221; character, which are called &#8220;<strong>preprocessor directives</strong>&#8220;.<br><br>Note that directives are not C/C++ statements (and therefore do not end with a semicolon) but rather instruct the preprocessor to carry out some action.<br><br><span style="text-decoration: underline;">For each .c/.cpp file, the preprocessor handles directives that begin with the # character and creates a temporary file to store its output</span>.<br>The preprocessor reads and processes each file one at a time from top to bottom.<br><span style="text-decoration: underline;"><strong>It does not change the content of any of the source files it processes</strong></span>.<br><br><span style="text-decoration: underline;">The results are files which contains the source code merged with headers files and with all macros expanded</span>.<br>By convention, preprocessed files are given the file extension .i for C programs and .ii for C++ programs.<br>In practice, the preprocessed file is not saved to disk unless the <code>-save-temps</code> option is used.</p>



<p>Two of the most common directives, and the first that we will use, are <strong>#include</strong> and <strong>#define</strong>.</p>



<p><strong><span style="text-decoration: underline;">The #include Directive</span></strong><br><br><span style="text-decoration: underline;">When the preprocessor encounters the #include directive, it opens the <strong>header file</strong> and adds its contents into the temporary file</span>.<br>The symbols surrounding the name of the header file are important and determine where the preprocessor looks for the file.</p>



<p><code>#include &lt;name&gt;</code><br>The angle brackets denote a system include file that is part of the compiler itself (think of it as &#8220;library&#8221; code)<br>and directs the preprocessor to search for the file where the system header files are located (which varies from one compiler to another and from one Operating System to another).<br><br><code>#include "name.h"</code><br>The double quotation marks identify a header file that is written as a part of a program.<br>The quotation marks instruct the preprocessor to look for the header file in the current directory (i.e., in the same directory as the source code).<br>Header files that a programmer writes as part of an application program typically end with a .h extension.<br><br>You might see two kinds of system header files in a C++ program :<br>Older system header files end with a &#8220;.h&#8221; extension: &lt;name.h&gt;.<br>These header files were originally created for C programs, but may also be used with C++.<br>Newer system header files do not end with an extension: &lt;name&gt;, may only be used with C++.<br><br>File names appearing between &lt; and &gt; refer to system header files<br>File names appearing between an opening and closing &#8221; refer to header files written by the programmer as a part of the program.<br><br><span style="text-decoration: underline;">Note</span>:<br>The include directive does not end with a semicolon and there must be at least one space between the directive and the file name.</p>



<p></p>



<p><strong><span style="text-decoration: underline;">The #define Directive and Symbolic Constants</span></strong></p>



<p>The #define directive introduces a programming construct called a <strong>macro</strong>.<br>A simple macro only replaces one string of characters with another string.<br><br><span style="text-decoration: underline;">The #define directive is one (old) way of creating a symbolic constant</span> (also known as a named or manifest constant).<br><span style="text-decoration: underline;">The <strong>const</strong> and <strong>enum</strong> keywords are newer techniques for creating constants</span>.<br>It is a well-accepted naming practice to write the names of symbolic constants with all upper-case characters (this provides a visual clue that the name represents a constant).<br><br><span style="text-decoration: underline;">Note</span>:<br>The define directive does not end with a semicolon and there must be at least one space between the directive and the identifier, and between the identifier and the defined value; the defined value (the third part of the directive) is optional.</p>



<pre class="wp-block-code"><code>Stop after the Preprocessing stage. 
<span style="text-decoration: underline;">The output is in the form of preprocessed source code, which is sent to the standard output</span>.
Input files that don't require preprocessing are ignored.

$ gcc -E &lt;program_file_1&gt;.c &lt;program_file_2&gt;.c ... &lt;program_file_n&gt;.c

$ g++ -E &lt;program_file_1&gt;.cpp &lt;program_file_2&gt;.cpp ... &lt;program_file_n&gt;.cpp</code></pre>



<h2>Compiler</h2>



<p><span style="text-decoration: underline;"><strong>The Compiler translates source code into assembly code</strong></span><strong><span style="text-decoration: underline;"> for a specific processor</span></strong>.<br><br>As the Preprocessor processes each source code file one at a time and produces a single temporary file (for each source code file).<br>Similarly, the Compiler processes each temporary file one at a time and produces one assembly code file for each temporary file.<br><br><span style="text-decoration: underline;">The Compiler also detects syntax errors and provides the diagnostic output programmers use to find and correct those errors.<br></span>Despite all that the compiler does, its operation is transparent to programmers for the most part.</p>



<pre class="wp-block-code"><code>Stop after the stage of Compilation, do not Assemble. 
<span style="text-decoration: underline;">The output is in the form of an assembler code file</span> for each non-assembler input file specified.
By default, the assembler file name for a source file is made by replacing the suffix .c, .cpp, .i, .ii, etc., with .s
Input files that don't require compilation are ignored.

$ gcc -S &lt;program_file_1&gt;.c &lt;program_file_2&gt;.c ... &lt;program_file_n&gt;.c

$ g++ -S &lt;program_file_1&gt;.cpp &lt;program_file_2&gt;.cpp ... &lt;program_file_n&gt;.cpp</code></pre>



<h2>Assembler</h2>



<p><strong><span style="text-decoration: underline;">The Assembler translates assembly code into machine code the processor understands and can execute</span></strong>.<br><br><span style="text-decoration: underline;">The purpose of the Assembler is to convert assembly language into <strong>machine code</strong> and generate an <strong>object file</strong></span>. <br><br>When there are calls to external functions in the assembly source file, the Assembler leaves the addresses of the external functions undefined, to be filled in later by the linker.</p>



<pre class="wp-block-code"><code>Compile AND Assemble the source files, but do not Link.
<span style="text-decoration: underline;">The output is in the form of an object file for each source file</span>.
By default, the object file name for a source file is made by replacing the suffix .c, .cpp, .i, .ii, .s, etc., with .o
Unrecognized input files, not requiring compilation or assembly, are ignored.

$ gcc -c &lt;program_file_1&gt;.c &lt;program_file_2&gt;.c ... &lt;program_file_n&gt;.c

$ g++ -c &lt;program_file_1&gt;.cpp &lt;program_file_2&gt;.cpp ... &lt;program_file_n&gt;.cpp</code></pre>



<h2>Linker</h2>



<p>The final stage of compilation is the <strong><span style="text-decoration: underline;">linking of object files to create an executable program</span></strong>.<br><br>Object files contain machine code and information that the Linker uses to complete its tasks.<br>(Note that &#8220;object&#8221; in this context has nothing to do with the objects involved in Object-Oriented Programming)<br><br><strong>This is where all of the object files and any additional binary libraries are linked together to make the final program.</strong></p>



<p><span style="text-decoration: underline;"><strong>It takes each object files created by the Assembler and links them together, along with system and runtime libraries, to form a complete, executable program</strong></span>.<br><br><strong>An executable requires many external functions from system and runtime libraries</strong>.<br><span style="text-decoration: underline;"><strong>They contain functions that are necessary to run a program on a given architecture</strong></span><br>(linux-vdso.so.n, libc.so.n, ld-linux-x86-64.so.n (amd64), ld-linux.so.n (i386), etc.)</p>



<p><span style="text-decoration: underline;">A library is a binary file (usually not directly executable) containing compiled functions/programming code that may be used/called by other programs/applications</span>.<br><br>As a convention, a library name starts with &#8216;lib&#8217;, and the extension determines the type of the library:<br><strong>.a</strong> stands for <strong>archive (static library)</strong><br><strong>.so</strong> stands for <strong>shared object</strong> <strong>(dynamic library)</strong><br><br><strong><span style="text-decoration: underline;">Static Linking</span></strong> :<br><strong>The linker adds all the libraries the program needs inside the final executable file</strong> (<strong>content is included</strong>).<br>Static linking may simplify the process of distributing a program to multiple similar environments, since <strong>it already has everything it needs to run</strong>. But any update to the libraries dependencies won&#8217;t be effective until you perform a whole compilation and linking process again.<br><br><strong><span style="text-decoration: underline;">Dynamic Linking</span></strong> :<br><strong>The linker only places a reference to the required libraries in the final program</strong> (<strong>content is not included</strong>).<br><span style="text-decoration: underline;"><strong>The actual linking happens when the program is executed (loaded at runtime</strong>)</span>.<br>You don&#8217;t need to recompile the program if any update occurs to the libraries dependencies, but they all <strong>need to be present/installed on the system for the program to work</strong>.<br></p>



<pre class="wp-block-code"><code><strong><span style="text-decoration: underline;">Libraries </span></strong><span style="text-decoration: underline;"><strong>(binaries) </strong></span><strong><span style="text-decoration: underline;">Location</span></strong>

<strong>GNU C Library: Shared libraries   (package: libc&lt;n&gt;)</strong>
Contains the standard libraries that are used by nearly all programs on the system.

<strong>GNU Standard C++ Library v3       (package: libstdc++&lt;n&gt;)</strong>
Contains an additional runtime library for C++ programs built with the GNU compiler. 

Symbolic link /lib -&gt; /usr/lib
On Debian 64-bits amd64 architecture:   /lib/x86_64-linux-gnu/
On Debian 32-bits i386 architecture:    /lib/i386-linux-gnu/

<strong><span style="text-decoration: underline;">List of paths that ld (the linker) will search for libraries</span></strong>
The directories are searched in the order in which they are specified
$ ld --verbose | grep SEARCH_DIR | sed 's/; /\n/g'</code></pre>



<p></p>



<p>The name of the executable file depends on the hosting Operating System:<br>On Linux, Unix, and macOS systems, the linker produces a file named &#8216;a.out&#8217; by default.<br>On a Windows computer, the linker produces a file whose name ends with a .exe extension.</p>



<p>Users may also specify a name that overrides the default.<br><br>For example, if you want gcc to generate an executable with a specific name, use the -o option followed with the desired name:</p>



<pre class="wp-block-code"><code>$ gcc -o &lt;program_name&gt; &lt;program_file_1&gt;.c &lt;program_file_2&gt;.c ... &lt;program_file_n&gt;.c

$ g++ -o &lt;program_name&gt; &lt;program_file_1&gt;.cpp &lt;program_file_2&gt;.cpp ... &lt;program_file_n&gt;.cpp</code></pre>



<p>When the compiling finishes, temporary/intermediate files are removed.</p>



<pre class="wp-block-code"><code>This command shows all shared library dependencies (what libraries the executable requires)

$ ldd &lt;program_name&gt;</code></pre>



<pre class="wp-block-code"><code>readelf displays information about ELF format object files. 
The options control what particular information to display.
This program performs a similar function to objdump but it goes into more detail

$ readelf -a &lt;program_name&gt;</code></pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://itec4b.com/wp-content/uploads/2023/01/g-compilation-process.png"><img decoding="async" loading="lazy" src="https://itec4b.com/wp-content/uploads/2023/01/g-compilation-process.png" alt="" class="wp-image-841" width="757" height="459" srcset="https://itec4b.com/wp-content/uploads/2023/01/g-compilation-process.png 1009w, https://itec4b.com/wp-content/uploads/2023/01/g-compilation-process-300x182.png 300w, https://itec4b.com/wp-content/uploads/2023/01/g-compilation-process-768x466.png 768w" sizes="(max-width: 757px) 100vw, 757px" /></a><figcaption class="wp-element-caption"><strong>g++ Compiler Operations</strong></figcaption></figure></div>


<h2><strong>Loader</strong></h2>



<p>This stage happens when the program starts up.<br>The program is scanned for references to shared libraries.<br>Any references found are resolved and the libraries are mapped into the program.</p>



<pre class="wp-block-code"><code>The <strong>dynamic linker/loader programs</strong> <strong>ld.so</strong> (or<strong> ld.so.n</strong>) and <strong>ld-linux.so</strong> (or <strong>ld-linux.so.n</strong>) find and load the shared objects (shared libraries) needed/used by a program, prepare the program to run, and then run it.

In Debian:
$ ls -l /lib/$( arch )-linux-gnu/ld-linux*

$ &lt;loader_program&gt; &lt;program_name&gt;</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Computer Programming</title>
		<link>https://itec4b.com/computer-programming/</link>
		
		<dc:creator><![CDATA[author]]></dc:creator>
		<pubDate>Sat, 28 Jan 2023 19:13:28 +0000</pubDate>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">https://itec4b.com/?p=465</guid>

					<description><![CDATA[Computers can only understand binary language (sequences of instructions made of 1s and 0s) called machine code or machine language. To command a computer you need to speak its language.Not all the computers &#8220;speak the same way&#8221;, there are different technical implementations and representation of instructions. The instructions that a machine can understand is called &#8230; <p class="link-more"><a href="https://itec4b.com/computer-programming/" class="more-link">Read more<span class="screen-reader-text"> "Computer Programming"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><strong><span style="text-decoration: underline;">Computers can only understand bi</span></strong><span style="text-decoration: underline;"><strong>nary language (sequences of instructions made of 1s and 0s)</strong></span> called <strong>machine code</strong> or <strong>machine language</strong>.</p>



<p>To command a computer you need to speak its language.<br>Not all the computers &#8220;speak the same way&#8221;, there are different technical implementations and representation of instructions.</p>



<p>The instructions that a machine can understand is called the <strong>instruction set</strong> (range of instructions that a CPU can execute).</p>



<p>The <strong>Central Processing Unit (CPU)</strong>, also called processor, is the electronic component that executes instructions.<br>It is one of the most important parts of any computer.<br>Every CPU has a set of built-in commands (the instruction set), these &#8220;basic&#8221; operations are hardwired into the CPU.<br>CPUs only understand those operations encoded in <strong>binary code</strong>, the low-level machine code language (native code).<br><span style="text-decoration: underline;">Instructions are sequentially mixed together to make what is known a <strong>program</strong></span>.</p>



<p>In computer science, an <strong>Instruction Set Architecture (ISA)</strong> is an abstract model of a computer.<br>A device that executes instructions described by an ISA, such as a CPU, is called an implementation.<br><br><span style="text-decoration: underline;">The only way you can interact with the hardware is through the instruction set of the processor</span>.<br>The ISA specifies what the processor is capable of doing.<br><br>It is basically the interface between the hardware and the software.<br>It defines the supported data types, the registers, how the hardware manages main memory, key features (such as the memory consistency, addressing modes, virtual memory), which instructions a microprocessor can execute, and the input/output model of a family of implementations of the ISA.</p>



<p>It can be viewed as a &#8220;programmer’s manual&#8221;, the technical description of how it works and what you can do with it.</p>



<p>Each operation to perform from an instruction set is identified by a binary code known as an <strong>opcode</strong> (Operation Code).<br>The opcode is the first part of an instruction (the first bits).<br>It&#8217;s a unique code that identifies a specific operation.<br><br>On traditional architectures, an instruction includes an opcode that specifies the operation to perform AND zero or more <strong>operand</strong> specifiers, which may be registers, memory addresses, or literal data the operation will use or manipulate.<br><br>In Very Long Instruction Word (VLIW) architectures, multiple simultaneous opcodes and operands are specified in a single instruction.<br><br><span style="text-decoration: underline;">The number of operands is one of the factors that may give an indication about the performance of the instruction set</span>.<br><br><span style="text-decoration: underline;">A <strong>word</strong> is the fixed-sized piece of data handled as a unit by the processor</span>.</p>



<p><span style="text-decoration: underline;">The number of bits in a word (word size) is an important characteristic of any specific processor design or computer architecture</span>, it implies how many operations the computer is capable in a single word.</p>



<h2>Computer Architecture</h2>



<p>The <strong><span style="text-decoration: underline;">von Neumann architecture</span></strong> is a computer architecture based on a 1945 description by John von Neumann, and by others, in the <strong><span style="text-decoration: underline;">First Draft of a Report on the EDVAC</span></strong> (Electronic Discrete Variable Automatic Computer) <strong>one of the earliest electronic computers</strong>.</p>



<p>The report is an incomplete 101-page document written by hand by John von Neumann.<br><span style="text-decoration: underline;"><strong>It contains the first published description of the logical design of a computer using the stored-program concept</strong>, which has controversially come to be known as the von Neumann architecture</span>.</p>



<p>The document describes a <span style="text-decoration: underline;"><strong>design architecture for an electronic digital computer</strong></span> with these components:<br>&#8211; A Processing Unit with both an Arithmetic Logic Unit and processor registers<br>&#8211; A Control Unit that includes an Instruction Register and a Program Counter<br>&#8211; Memory that stores data and instructions<br>&#8211; External mass storage<br>&#8211; Input and output mechanisms<br><br>The von Neumann architecture is not perfect, an instruction fetch and a data operation cannot occur at the same time since they share a common bus. This is referred to as the von Neumann bottleneck, which limits the performance of the corresponding system.<br><br><span style="text-decoration: underline;">A stored-program digital computer keeps both <strong>program instructions and data</strong> in read–write, <strong>random-access memory (RAM)</strong></span></p>



<p>The vast majority of modern computers use the same memory for both data and program instructions, but have <span style="text-decoration: underline;"><strong>caches</strong> between the CPU and memory</span>, and, for the caches closest to the CPU, have separate caches for instructions and data, so that most instruction and data fetches use separate buses (split cache architecture)<br><br>If based on the von Neumann architecture, processors contain at least a <strong>Control Unit</strong> (CU), an <strong>Arithmetic Logic Unit</strong> (ALU), and <strong>processor registers</strong>.</p>



<p>Every modern processor includes very small super-fast memory banks, called registers.<br><strong><span style="text-decoration: underline;">The registers are the fastest accessible memory location for the CPU and sit on the top of the memory hierarchy</span></strong>.<br>They can be read and written at high speed since they are internal to the CPU.<br>They are much smaller in size than local memory (size of a word: usually 64 or 32 bits) and are used to store machine instructions, memory addresses, and certain other values.<br><br>Data is loaded from the main memory to the registers (via the CPU cache) after which it undergoes various arithmetic operations.<br><br>The manipulated data is then written back to the memory via the CPU cache.<br><br><span style="text-decoration: underline;"><strong>CPU&#8217;s cache memory</strong> is dedicated to hold (inside or close to the CPU) the most commonly used memory words, in order to avoid slower accesses to main memory (RAM)</span>.<br><br><span style="text-decoration: underline;">Most CPUs have a hierarchy of multiple cache levels, with specific instruction and data caches at Level 1</span>.<br>The L1 cache or first-level cache is the closest to the CPU, making it the type of cache with the highest speed and lowest latency of the entire cache hierarchy.<br><br>Instruction cache: used to speed up executable instruction fetch<br>Data cache: used to speed up data fetch and store</p>



<h2>Instruction Cycle</h2>



<p>A program is a sequence of instructions in memory.<br><br><span style="text-decoration: underline;">The CPU executes operations through a cycle known as &#8220;Fetch, Decode, and Execute&#8221;</span>.<br><br>The most important registers (Control Unit) are :<br>&#8211; <strong>Program Counter (PC)</strong>, which points (holds the memory address) to the next instruction to be fetched for execution<br>&#8211; <strong>Instruction Register (IR)</strong>, which holds the instruction currently being executed<br></p>



<pre class="wp-block-code"><code>1. Fetch the instruction from memory into the Instruction Register
2. Change the Program Counter register to point to the next instruction
3. Decode the instruction
      Determine the type of instruction (opcode)
      If the instruction operand is a word in memory: 
         Determine where it is located (memory address)
         Retrieve the data from memory into a register
4. Execute the instruction (ALU)
5. Go to step 1 to begin executing the next instruction</code></pre>



<p>The operation code tells the ALU what operation to perform, the operands are used in the operation</p>



<h2>Technology Evolution</h2>



<p>Since the invention of the <strong>transistor</strong> (electronic switch) in 1947 by John Bardeen, Walter Brattain, William Shockley<br>AND the <strong>Silicon Integrated Circuit</strong> in 1958 by Jack Kilby and Robert Noyce<br><span style="text-decoration: underline;">The computer industry development has never stopped</span>, advances in technology has revolutionized computers, leading to smaller, faster, better products at lower prices.</p>



<p>Manufacturers have packed more and more transistors per chip every year, meaning larger memories and more powerful processors.</p>



<p><span style="text-decoration: underline;"><strong>Latest processors contains billions of transistors</strong></span>.</p>



<p>Moore&#8217;s law is the observation that the number of transistors in an Integrated Circuit doubles about every two years.<br>It is an observation and projection of a historical trend since 1965.</p>



<p>While Moore’s law will probably continue to be proven for some years, it has a limit:<br>First, you cannot shrink a transistor size more than you can.<br>Second, you have <span style="text-decoration: underline;"><strong>problems of power consumption and heat dissipation</strong></span>.</p>



<p>Smaller transistors make it possible to run at higher clock frequencies, but also requires using a higher voltage.<br>That is, going faster (clock speed) means having more heat to get rid of.</p>



<p>The solution is the <strong>multi-core processor architecture</strong>: two identical CPUs on a chip consume less power than one CPU at twice the speed.<br><span style="text-decoration: underline;">That is one of the reasons why processors have more and more cores and larger caches rather than higher clock speeds</span>.</p>



<p><span style="text-decoration: underline;">Taking advantage of these multiprocessors poses great challenges to programmers, it requires knowledge to explicitly control/manage parallel execution</span>.</p>



<h2>CPU Core</h2>



<p>Before multi-core processor architecture, computers only had one CPU: the processor could only perform one instruction at a time.<br><span style="text-decoration: underline;">A CPU core is a physical hardware processor with all the architecture that comes with it</span>.<br><span style="text-decoration: underline;">We now have multiple processors grouped inside one Integrated Circuit (single chip), running independently: This is real <strong>hardware parallelism</strong> (as long as the Operating System uses it)</span>.<br>The design is far more advanced, it requires a different architecture to orchestrate all this (controllers, buses, memory access, etc.). <br><br><span style="text-decoration: underline;">This technology has allowed <strong>Machine Virtualization</strong> (standard practice in enterprise IT architecture), which is the foundation of <strong>Cloud Computing</strong></span>.<br><br><span style="text-decoration: underline;">It allows the hardware elements of a single computer (processors, memory, storage, and more) to be divided into multiple virtual computers, commonly called <strong>Virtual Machines</strong> (<strong>VM</strong>)</span>. Each VM runs its own Operating System (OS) and behaves like an independent computer, even though it is running on just a portion of the actual underlying computer hardware.<br><br><span style="text-decoration: underline;">The more cores there are in a CPU, the more efficient it is and the more you can do</span>.</p>



<h2>CPU Thread</h2>



<p><strong>Simultaneous MultiThreading</strong> (SMT) is a technique for improving the overall efficiency of CPUs with hardware multithreading.<br>SMT allows to better use the resources provided by modern processor architectures.<br><br>When SMT is operational, the Operating System sees the processor as having &#8220;double the cores&#8221; (<strong>Logical Processors</strong>).<br>Two logical cores can work through tasks more efficiently than a native single-threaded core, by taking advantage of idle time when the core would formerly be waiting for other tasks to complete.<br>It improves CPU throughput (usage optimization).</p>



<h2>CPU Clock Speed</h2>



<p>The clock speed measures the number of cycles your CPU executes per second, measured in GHz (gigahertz).<br>A cycle is the basic unit that measures a CPU’s speed.<br>During each cycle, billions of transistors within the processor open and close.<br><br>A CPU with a clock speed of 3.4 GHz executes 3.4 billion cycles per second. (Older CPUs had speeds measured in MegaHertz, or millions of cycles per second)<br><br>Sometimes, multiple instructions are completed in a single clock cycle. <br>In other cases, one instruction might be handled over multiple clock cycles.</p>



<h2>How Do We Communicate With The Processor ?</h2>



<p>Unless you are a supernatural alien coming from another galaxy, we use <strong><span style="text-decoration: underline;">programming languages</span></strong><br>(created by skillful and talented people)<br><br>Programming languages are often categorized as <strong>low-level</strong>, <strong>mid-level</strong> or <strong>high-level</strong>  depending on <br>&#8220;how close you are from the hardware&#8221;.</p>



<h2>Low-Level Programming Languages</h2>



<p><span style="text-decoration: underline;">low-level programming languages are <strong>hardware-dependent</strong> and <strong>machine-centered</strong> (tied to the hardware, providing operations matching the hardware&#8217;s capabilities)</span>.<br><br>low-level programs execute faster than high-level programs, with a small memory footprint.</p>



<p><strong>Assembly</strong> language (asm), is any low-level programming language with a <span style="text-decoration: underline;">very strong correspondence between the instructions in the language and the processor&#8217;s<strong> </strong>instruction set</span>.<br><br>Assembly is very close to machine code but is &#8220;more readable&#8221; and uses mnemonics.<br>You need to have a strong technical knowledge to use it (interaction with the hardware), Assembly is not easy.<br><br>The statements are made up of opcodes and operands (processor registers, memory addresses, etc.), which are translated into machine code (instructions that the processor understands).<br><br>One line of assembly equals one line of machine code.<br><br>Assembly code is <span style="text-decoration: underline;">converted into executable machine code by a utility program referred to as an <strong>assembler</strong></span>.<br><br><span style="text-decoration: underline;">Each assembly language is specific to a particular computer architecture, it is not portable to a different type of architecture</span>.</p>



<h2>Mid-Level, High-Level Programming Languages</h2>



<p><span style="text-decoration: underline;">Most programming is done using high-level <strong>compiled</strong> or <strong>interpreted</strong> languages, which are easier for humans to understand, write, debug and do not require knowledge of the the system (hardware) running the program</span>.</p>



<p><span style="text-decoration: underline;">These languages need to be compiled (translated into system-specific machine code) by a <strong>compiler</strong>, or run through other system-specific compiled programs</span>.<br><br>High-level programming languages are generally <strong>hardware-independent</strong> and <strong>problem-centered</strong> (providing operations supporting general problem-solving).<br><span style="text-decoration: underline;">Programmers can move hardware-independent code from one computer to another fairly easily</span>.</p>



<p><span style="text-decoration: underline;">Delroy A. Brinkerhoff, Ph.D</span> :</p>



<p>The <strong>C</strong> programming language is deemed a mid-level language because it allows programmers more access to the hardware than other higher-level languages.<br><br>We can locate <strong>C++</strong> at two different places in this spectrum.<br><br>First, it represents a mid-level language because it retains C&#8217;s access to the hardware.<br>But second, it also represents a high-level language because it supports <strong>object-orientation</strong>, a problem-centered approach to programming.<br><br>The combination of high- and mid-level features makes C++ a popular choice for writing Operating Systems, games and large industrial applications.</p>



<p><span style="text-decoration: underline;">Computers can&#8217;t directly execute programs written in high-level languages</span>,<br>so there must be some way of translating a program written in a high-level language into machine language.</p>



<p>Two kinds of computer programs perform the necessary translation: <span style="text-decoration: underline;">compilers and interpreters</span>.</p>



<p><span style="text-decoration: underline;">A compiler is a program that translates other programs written in a high-level programming language like C or C++ into machine code or machine language</span>.</p>



<p>Some languages such as <strong>Java</strong> and <strong>C#</strong> take a different route.<br>Compilers for these languages translate the <span style="text-decoration: underline;">high-level source code into an intermediate form</span> (a representation that lies somewhere between the high-level and true machine code) called <strong>virtual machine code</strong>.<br><br><span style="text-decoration: underline;">The virtual machine code then becomes the input to another program called an interpreter or Virtual Machine (VM), a program that simulates a hardware CPU</span>. <span style="text-decoration: underline;">Note here that VM is a software component dedicated to run <span style="text-decoration: underline;">virtual machine code</span> (runtime environment for applications), it is different from Hardware Virtualization</span>.</p>



<p>Other languages, such as <strong>Javascript</strong> and <strong>Perl</strong>, are <span style="text-decoration: underline;"><strong>completely interpreted</strong></span>.<br><span style="text-decoration: underline;">These languages don&#8217;t use compilers at all</span>.<br>The interpreter reads the source code, written in the high-level language, and <span style="text-decoration: underline;">interprets the instructions one at a time</span>.<br>That is, the interpreter itself carries out each instruction in the program.</p>



<p></p>



<p><strong><span style="text-decoration: underline;">Compiling and running a program written in a language that produces machine code</span></strong><br>The compiler reads the C/C++ source code from a file that ends with .c or .cpp and produces a machine code file that is executable.<br>See <a href="https://itec4b.com/c-compiler-operations">C/C++ Compiler Operations</a><br></p>



<p><strong><span style="text-decoration: underline;">Compiling and running a program written in a language that produces virtual machine code</span></strong><br>Languages like Java and C# are hybrid languages because they use both a compiler and a Virtual Machine.<br><span style="text-decoration: underline;">They first compile the source code to <strong>virtual machine code</strong></span>, that is, to machine code for a virtual computer (a computer that doesn&#8217;t exist but is simulated by another computer).<br>After compiling the source code, a <strong><span style="text-decoration: underline;">Virtual Machine (VM)</span></strong><span style="text-decoration: underline;"><strong> executes the code</strong></span> by simulating the actions of a real computer.<br>The Operating System loads the VM into main memory and runs it.<br>It is the VM that reads and runs the virtual machine code.</p>



<p><strong><span style="text-decoration: underline;">Running a program written in a purely interpreted language</span></strong><br>Languages like Javascript and Perl <span style="text-decoration: underline;">do not compile the source code at all</span>.<br>Like the hybrid languages (Java and C#), the Operating System run the interpreter or VM.<br><span style="text-decoration: underline;">The interpreter reads the source code file and <strong>executes the program one statement at a time</strong> without translating the whole program to any other language</span>.<br>Web browsers incorporate interpreters for some languages (like Javascript) while the Operating System runs the interpreters for other languages (like Perl) as application programs.</p>



<h2>High-Level Programming Languages Advantages and Disadvantages</h2>



<p>Each approach to running a program written in a high-level programming language has advantages and disadvantages.<br><br><span style="text-decoration: underline;"><strong>Programs written in fully compiled languages (e.g., C and C++) execute faster than programs written in partially compiled languages (e.g., Java and C#) and run much faster than programs written in fully interpreted languages (e.g., Javascript and Perl)</strong></span>.<br><br>To give some idea of the difference in performance, let&#8217;s say that a C++ program, once compiled, executes in time 1.<br>A program in a hybrid language (compiled and interpreted) will generally run in time 3 to 10.<br>In a purely interpreted language, the same program runs in a time of about 100.</p>



<p>Contemporary versions of the Java and C# VMs use a Just In Time (JIT) interpreter that compiles some of the virtual code to machine code while processing it.<br>JIT processors reduce run time to about 1.5 times that of purely compiled language systems.</p>



<p>&#8220;How does Java compare in terms of speed to C or C++ or C# or Python? <span style="text-decoration: underline;">The answer depends greatly on the type of application you&#8217;re running</span>. No benchmark is perfect, but <a href="https://benchmarksgame-team.pages.debian.net/benchmarksgame">The Computer Language Benchmarks Game</a> is a good starting point.&#8221;<br><br><span style="text-decoration: underline;">On the other hand, once we compile a program written in purely compiled languages, we can&#8217;t easily move the resulting executable machine code to a different platform (e.g., you can&#8217;t run a Windows program to an Apple computer)</span>.<br><br><span style="text-decoration: underline;">In contrast, we can easily move programs we write in interpreted languages between different computers</span>.</p>



<p>Interpreted programs are portable because they run on a VM or interpreter.<br>From the hardware and Operating System&#8217;s perspective, the interpreter is the running program.<br><span style="text-decoration: underline;">Interpreters and VMs are written in purely compiled languages, so they are not portable, but the programs that they run are</span>.<br>Once we install the interpreter on a system, we can move interpretable programs to the system and run them without further processing.<br><br><span style="text-decoration: underline;"><strong>Execution speed is not the only criteria to take into consideration, there is also the speed/ease of development</strong></span>.</p>



<p><a href="https://wiki.python.org/moin/PythonSpeed">here is an article about Python speed</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
