<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gilbert Nkolo Acquostic</title>
    <description>The latest articles on DEV Community by Gilbert Nkolo Acquostic (@gilbskk).</description>
    <link>https://dev.to/gilbskk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1696290%2Ffb4d5258-52ba-4f5d-b76b-89dc5772f126.png</url>
      <title>DEV Community: Gilbert Nkolo Acquostic</title>
      <link>https://dev.to/gilbskk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gilbskk"/>
    <language>en</language>
    <item>
      <title>How to use the Find command on Linux</title>
      <dc:creator>Gilbert Nkolo Acquostic</dc:creator>
      <pubDate>Thu, 27 Jun 2024 23:41:14 +0000</pubDate>
      <link>https://dev.to/gilbskk/how-to-use-the-find-command-on-linux-2p6a</link>
      <guid>https://dev.to/gilbskk/how-to-use-the-find-command-on-linux-2p6a</guid>
      <description>&lt;h2&gt;
  
  
  What Is The Linux Terminal Find Command
&lt;/h2&gt;

&lt;p&gt;The “find” command on the Linux terminal is a powerful tool used to locate files and directories within a specified directory or throughout the entire file system. It allows users to search for files by name, size, type, modified date, and other criteria. The find command also has advanced features such as searching based on permission settings and executing actions on the found files.&lt;/p&gt;

&lt;p&gt;It is commonly used by system administrators and developers to efficiently manage their file systems and perform complex tasks such as backups, data transfers, and performing bulk operations. With its versatile capabilities, the find command offers users a comprehensive solution for navigating through large amounts of data quickly and efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Linux Terminal Commands:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To navigate through these directories efficiently, you should familiarize yourself with some basic commands. These are:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd&lt;/code&gt; or Change Directory: This command allows you to move from one directory to another.&lt;br&gt;
&lt;code&gt;ls&lt;/code&gt; or List: This command lists all the files and folders present in the current working directory.&lt;br&gt;
&lt;code&gt;pwd&lt;/code&gt; or Print Working Directory: This command displays the full path of your current working directory.&lt;br&gt;
&lt;code&gt;find&lt;/code&gt; or Find Specific File or Directory: The “find” command as mentioned above it allows you to find files and directories.&lt;/p&gt;
&lt;h2&gt;
  
  
  How To Find A Specific Directory or File:
&lt;/h2&gt;

&lt;p&gt;Here is the find command in its most simplest form. If you need a more detailed explanation. I have one below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find / -type d -name "*insert search term*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the find command structure. It comes equipped with many options which I have listed below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find [directory] [options] [expression]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;find&lt;/code&gt; command has many options that can be used to customize the search criteria.&lt;br&gt;
-&lt;code&gt;name&lt;/code&gt;: This option allows you to specify the name or pattern of the file you want to find. For example, “-name *.txt” will search for all files with .txt extension.&lt;br&gt;
-&lt;code&gt;type&lt;/code&gt;: With this option, you can specify whether the file should be a regular file (-type f), directory (-type d), or symbolic link (-type l).&lt;br&gt;
-&lt;code&gt;size&lt;/code&gt;: This option lets you search for files based on their size. You can use modifiers like + (greater than), — (less than), or c (bytes) to refine your search.&lt;br&gt;
-&lt;code&gt;user/-group&lt;/code&gt;: These options allow you to find files owned by a specific user/group.&lt;br&gt;
-&lt;code&gt;mtime/-atime/-ctime&lt;/code&gt;: Using these options, you can search for files based on their modification/access/change time respectively.&lt;br&gt;
-perm: With this option, you can find files based on their permissions using octal numbers as arguments.&lt;br&gt;
-&lt;code&gt;maxdepth/mindepth&lt;/code&gt;: These options let you limit the depth of subdirectories that are searched while finding files.&lt;br&gt;
-&lt;code&gt;exec/-ok&lt;/code&gt;: These options allow executing commands on found items either automatically (‘-exec’) or after user confirmation (‘-ok’).&lt;br&gt;
-&lt;code&gt;prune&lt;/code&gt;: This option excludes specified directories from being searched within while finding files recursively in a given path(s).&lt;br&gt;
-&lt;code&gt;newer/!newer&lt;/code&gt;: The ‘newer’ operator finds only those items modified more recently than the reference item defined as an argument whereas ‘!newer’ does vice versa.&lt;br&gt;
— &lt;code&gt;help/ — version (dash-dash)&lt;/code&gt;: These two common help switches print usage information and version details respectively when provided with other valid arguments.&lt;/p&gt;

&lt;p&gt;Some common examples of using the “find” command are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finding all files with a specific name:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find /home/user -name example.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will search for all files named “example.txt” under the “/home/user” directory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finding all directories with a specific permission:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find /var/www -type d -perm 755
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will search for all directories under “/var/www” that have read, write, and execute permissions for the owner (7) and read/execute permissions for others (5).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finding recently modified files:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find ~/Documents -type f -mtime -1 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  shows everything modified before the last 24 hours, 2 days ago and beyond
&lt;/h1&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find ~/Documents -type f -mtime +1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will search for all files in the “~/Documents” directory using the last modified option.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How To Use The -exec Option on Files Filtered by The Find Command
The -exec option allows for the execution of a specified command on every file that is discovered during the search.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This option must be followed by the desired command and its corresponding arguments, with {} serving as placeholders for each file’s path.&lt;/p&gt;

&lt;p&gt;To denote the completion of the -exec command, \; (a backward slash and semi-colon) must be included.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo find /var/www -name "*.html" -exec mv {} ~/html \;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we execute the move (mv) command on all .html files within the /var/www directory to the home HTML directory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How To Use The Find -ok Option on Files&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The -ok option functions similarly to the -exec option, except that it prompts for confirmation before executing the operation on each file. This is a highly useful command as it allows you to review which files will be affected before proceeding with the specific operation.&lt;/p&gt;

&lt;p&gt;You also have the choice to decline if you are uncertain or do not want to apply the command.&lt;/p&gt;

&lt;p&gt;For instance, let’s attempt to move all .txt files into another directory using this feature.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find ~/tmp -name "*.txt" -ok mv {} ~/tmp/final \;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we’re iterating over every text file within the ./tmp directory and manually choosing whether or not we want to move the file into the &lt;code&gt;./tmp/final directory&lt;/code&gt;. You need to type “yes” or “no”.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How To Use -delete with The Find Command&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The -delete option can be useful if you need to free up space on your computer or if you want to remove certain files that are no longer needed. It is important to use this option carefully because it permanently deletes the files without any confirmation, so make sure you are certain about which files you want to delete before using it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -name "*.html" -delete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This deletes all HTML files within the current directory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Combining multiple conditions using logical operators:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo find /var -type f \( -name "*.conf" \) ! \( -user ubuntu \)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will find all files in the “/etc” directory, with names ending in “.conf”, but not owned by user “root”. It will list them all out for you.&lt;/p&gt;

&lt;p&gt;Linux Tip: Don’t Forget To Use Wildcards With Your Search If Needed&lt;br&gt;
Sometimes we may not remember the exact name or spelling of a particular folder but know certain keywords associated with it. In such cases using wildcards can be helpful.&lt;/p&gt;

&lt;p&gt;For instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To search for all folder names starting with “intro”, use intro*&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To find all folders ending with “music”, try *music&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The asterisk (*) acts as a placeholder for unknown characters.&lt;/p&gt;

&lt;p&gt;For more information about available options and expressions, you can refer to the manual page of “find”. You can access it by typing &lt;code&gt;man find&lt;/code&gt; in your terminal or online resources such as &lt;a href="https://linux.die.net/man/1/find"&gt;https://linux.die.net/man/1/find&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Run Redis Locally</title>
      <dc:creator>Gilbert Nkolo Acquostic</dc:creator>
      <pubDate>Thu, 27 Jun 2024 23:34:25 +0000</pubDate>
      <link>https://dev.to/gilbskk/run-redis-locally-260g</link>
      <guid>https://dev.to/gilbskk/run-redis-locally-260g</guid>
      <description>&lt;p&gt;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.&lt;/p&gt;

&lt;p&gt;To run the redis install any latest version of redis . We did the cluster setup on redis 4.0.14&lt;/p&gt;

&lt;p&gt;First we need to create the conf file for the replication .port` we are going to use 3 master nodes and 3 slave nodes .&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
create 6 config files with port ranging from 7001 to 7006 .&lt;br&gt;
config file for each node should be different like the below&lt;br&gt;
dbfile name should be unique&lt;br&gt;
port 7001                       &lt;br&gt;
cluster-enabled yes                       &lt;br&gt;
cluster-config-file cluster-node-1.conf                       cluster-node-timeout 5000&lt;br&gt;
appendonly yes                       &lt;br&gt;
appendfilename node-1.aof                       &lt;br&gt;
dbfilename dump-1.rdb&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
Now we run all the redis-server by using the “redis-server” command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
redis-server node1.conf &lt;br&gt;
redis-server node2.conf &lt;br&gt;
redis-server node3.conf &lt;br&gt;
redis-server node4.conf &lt;br&gt;
redis-server node5.conf &lt;br&gt;
redis-server node6.conf&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can see all nodes are running , but there is no communication between the nodes&lt;/p&gt;

&lt;p&gt;Run the below command from the “src” folder of redis server&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006&lt;br&gt;
Once it asks for the nodes to join , please opt of “Yes” . We can see it choose node 1,2,3 as master nodes and node 4,5,6 as slave nodes&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Stop one of the master node , Lets stop node 1 .&lt;/p&gt;

&lt;p&gt;As node 1 is stopped now , we will see that one of the slave node promoted master node . for our case node 5 becomes master .&lt;/p&gt;

&lt;p&gt;Once we start the node 1 , it will be re considered as slave node as we have already 3 master nodes available .&lt;/p&gt;

&lt;p&gt;Similarly when you do the data replication , data will be moving from master to slave accordingly&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to use the If...else conditional statement in Bash</title>
      <dc:creator>Gilbert Nkolo Acquostic</dc:creator>
      <pubDate>Thu, 27 Jun 2024 23:24:00 +0000</pubDate>
      <link>https://dev.to/gilbskk/my-first-post-1fa8</link>
      <guid>https://dev.to/gilbskk/my-first-post-1fa8</guid>
      <description>&lt;p&gt;In this article, I will walk you through the basics of the bash if...else statement and how to use it in your shell scripts to automate system processes.&lt;/p&gt;

&lt;p&gt;Decision-making is one of the most fundamental concepts of computer programming. Like in any other programming language, if, if...else, if...elif...else, and nested if statements in Bash are used to execute code when a specific condition is met.&lt;/p&gt;

&lt;p&gt;Bash if...else Statement&lt;/p&gt;

&lt;p&gt;This article will walk you through the basics of the bash if...else statement and explain you how to use it in your shell scripts.&lt;/p&gt;

&lt;p&gt;Decision-making is one of the most fundamental concepts of computer programming. Like in any other programming language, if, if...else, if...elif...else, and nested if statements in Bash are used to execute code when a specific condition is met.&lt;/p&gt;

&lt;h2&gt;
  
  
  The if Statement
&lt;/h2&gt;

&lt;p&gt;Bash if conditionals can have different forms. The most basic if statement takes the following form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if TEST-COMMAND
then
  STATEMENTS
fi
Copy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The if statement starts with the if keyword followed by the conditional expression and the then keyword. The statement ends with the fi keyword.&lt;/p&gt;

&lt;p&gt;If the TEST-COMMAND evaluates to True, the STATEMENTS are executed. If the TEST-COMMAND returns False, nothing happens; the STATEMENTS are ignored.&lt;/p&gt;

&lt;p&gt;Generally, it is always good practice to indent your code and separate code blocks with blank lines. Most people choose to use either 4-space or 2-space indentation. Indentations and blank lines make your code more readable and organized.&lt;/p&gt;

&lt;p&gt;Let’s look at the following example script that checks whether a given number is greater than 10:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

echo -n "Enter a number: "
read VAR

if [[ $VAR -gt 10 ]]
then
  echo "The variable is greater than 10."
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the code in a file and run it from the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bash test.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter a number for example 12 to test the If statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The variable is greater than 10.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The &lt;code&gt;if...else&lt;/code&gt; Statement
&lt;/h2&gt;

&lt;p&gt;The Bash if...else statement takes the following form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if TEST-COMMAND
then
  STATEMENTS1
else
  STATEMENTS2
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the TEST-COMMAND evaluates to True, the STATEMENTS1 will be executed. Otherwise, if TEST-COMMAND returns False, the STATEMENTS2 will be executed. You can have only one else clause in the statement.&lt;/p&gt;

&lt;p&gt;Let’s add an else clause to the previous example script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

echo -n "Enter a number: "
read VAR

if [[ $VAR -gt 10 ]]
then
  echo "The variable is greater than 10."
else
  echo "The variable is equal or less than 10."
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's run the script again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bash test.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time around, enter a number less than 10 and notice the output changes to the else message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The variable is equal or less than 10.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter a number greater than 10.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The variable is greater than 10.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the code and enter a number, the script will print a different message based on whether the number is greater or less/equal to 10.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
