<?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: Zaki Arrozi Arsyad</title>
    <description>The latest articles on DEV Community by Zaki Arrozi Arsyad (@zakiarsyad).</description>
    <link>https://dev.to/zakiarsyad</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%2F388628%2Fd3b2dda5-1acc-490a-8049-91ba3dd5ff1b.jpeg</url>
      <title>DEV Community: Zaki Arrozi Arsyad</title>
      <link>https://dev.to/zakiarsyad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zakiarsyad"/>
    <language>en</language>
    <item>
      <title>docker : basic commands</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Sun, 12 Jul 2020 16:55:47 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/docker-basic-commands-2ngg</link>
      <guid>https://dev.to/zakiarsyad/docker-basic-commands-2ngg</guid>
      <description>&lt;h1&gt;
  
  
  Docker info
&lt;/h1&gt;

&lt;h3&gt;
  
  
  check the version or if docker is already installed
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nt"&gt;--verison&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show system information regarding docker installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker info
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show stats of runnign container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker stats
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show container log
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker logs &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show processes of container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker top &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show detailed info of container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker inspect &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show modified files in a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker diff &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show mapped ports in a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker port &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Help / manual
&lt;/h1&gt;

&lt;h3&gt;
  
  
  list available commands
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  manual for specific command
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &amp;lt;COMMAND&amp;gt; &lt;span class="nt"&gt;--help&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Run a new container
&lt;/h1&gt;

&lt;h3&gt;
  
  
  create a new container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// create from latest version
&lt;span class="nv"&gt;$ &lt;/span&gt;docker create &amp;lt;IMAGE&amp;gt;

// create from specific version
&lt;span class="nv"&gt;$ &lt;/span&gt;docker create &amp;lt;IMAGE[:TAG]&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  start a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker start &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run (create and start) a new container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// create from latest version
&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &amp;lt;IMAGE&amp;gt;

// create from specific version
&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &amp;lt;IMAGE[:TAG]&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run in the background
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run and assign it a name
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; &amp;lt;CONTAINER_NAME&amp;gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run and map a port
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; &amp;lt;HOST_PORT&amp;gt;:&amp;lt;CONTAINER_PORT&amp;gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run and map all port
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-P&lt;/span&gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run and assign a hostname
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;--hostname&lt;/span&gt; &amp;lt;HOSTNAME&amp;gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run and add a dns entry
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;--add-host&lt;/span&gt; &amp;lt;HOSTNAME&amp;gt;:&amp;lt;IP&amp;gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run and map a local dir
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-v&lt;/span&gt; &amp;lt;HOST_DIR&amp;gt;:&amp;lt;TARGET_DIR&amp;gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  run and change the entry point
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;--executable&lt;/span&gt; &amp;lt;COMMAND&amp;gt; &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Manage Container
&lt;/h1&gt;

&lt;h3&gt;
  
  
  show list of all running container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show list of all container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker ps &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  stop a running container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker stop &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  kill a running container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;kill&lt;/span&gt; &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  start a stopped container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker start &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  restart a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker restart &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  suspend a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker pause &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  resume a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker unpause &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  rename a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker rename &amp;lt;OLD_NAME&amp;gt; &amp;lt;NEW_NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  start shell inside a running container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker exce &lt;span class="nt"&gt;-it&lt;/span&gt; &amp;lt;CONTAINER_ID&amp;gt; &amp;lt;COMMAND&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  copy a file from host to container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;cp&lt;/span&gt; &amp;lt;SOURCE&amp;gt; &amp;lt;CONTAINER_ID&amp;gt;:&amp;lt;DESTINATION&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  copy a file from container to host
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;cp&lt;/span&gt; &amp;lt;CONTAINER_ID&amp;gt;:&amp;lt;SOURCE&amp;gt; &amp;lt;DESTINATION&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  delete a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;rm&lt;/span&gt; &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  destroy (kill + rm) a running container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  delete all stopped containers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker container prune
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  create an image out of container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker commit &amp;lt;CONTAINER_ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Manage Images
&lt;/h1&gt;

&lt;h3&gt;
  
  
  download an image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker pull &amp;lt;IMAGE[:TAG]&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  upload an image to repository
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker push &amp;lt;IMAGE[:TAG]&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  show list of images
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  build an image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker build &amp;lt;DIRECTORY&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  build and tag the image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; &amp;lt;IMAGE[:TAG]&amp;gt; &amp;lt;DIRECTORY&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  tag an image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker tag &amp;lt;SOURCE_IMAGE[:TAG]&amp;gt; &amp;lt;TARGET_IMAGE[:TAG]&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  delete an image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker rmi &amp;lt;IMAGE&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  delete dangling images
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker image prune
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  delete all unused images
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker image prune &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  save an image to tar file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker save &amp;lt;IMAGE&amp;gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &amp;lt;FILE.tar&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  load an image from tar file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker load &lt;span class="nt"&gt;-i&lt;/span&gt; &amp;lt;FILE.tar&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>docker : installation</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Sun, 12 Jul 2020 16:55:13 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/docker-installation-1fjg</link>
      <guid>https://dev.to/zakiarsyad/docker-installation-1fjg</guid>
      <description>&lt;p&gt;Run commands to install docker in an ubuntu machine&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Engine
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// download the script
&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; get.docker.com &lt;span class="nt"&gt;-o&lt;/span&gt; get-docker.sh

// create permission
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x get-docker.sh

//run the script 
&lt;span class="nv"&gt;$ &lt;/span&gt;sh get-docker.sh

// check &lt;span class="k"&gt;if &lt;/span&gt;it is successfully installed
&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Docker Compose
&lt;/h1&gt;

&lt;p&gt;Docker Compose helps us to running multi-container Docker applications with a YAML file configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// download docker-compose
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;curl &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="s2"&gt;"https://github.com/docker/compose/releases/download/1.26.2/docker-compose-&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; /usr/local/bin/docker-compose

// Apply docker-compose
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo chmod&lt;/span&gt; +x /usr/local/bin/docker-compose

// check &lt;span class="k"&gt;if &lt;/span&gt;it is successfully installed
&lt;span class="nv"&gt;$ &lt;/span&gt;docker-compose &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Docker Machine
&lt;/h1&gt;

&lt;p&gt;Docker Machine lets us install Docker Engine on virtual hosts, and manage the hosts with docker-machine commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// &lt;span class="nb"&gt;install &lt;/span&gt;docker-machine
&lt;span class="nv"&gt;$ base&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://github.com/docker/machine/releases/download/v0.16.0 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
  curl &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="nv"&gt;$base&lt;/span&gt;/docker-machine-&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;-&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/tmp/docker-machine &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
  &lt;span class="nb"&gt;sudo mv&lt;/span&gt; /tmp/docker-machine /usr/local/bin/docker-machine &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
  &lt;span class="nb"&gt;chmod&lt;/span&gt; +x /usr/local/bin/docker-machine

// check &lt;span class="k"&gt;if &lt;/span&gt;it is successfully installed
&lt;span class="nv"&gt;$ &lt;/span&gt;docker-machine &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;note : adding our user to the “docker” group, so that we can use docker as a non-root user&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; docker your-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>git : basic usage</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Mon, 22 Jun 2020 17:23:33 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/git-basic-commands-29kn</link>
      <guid>https://dev.to/zakiarsyad/git-basic-commands-29kn</guid>
      <description>&lt;p&gt;First thing first, we need to make sure if we already have git installed in our machine, by running one of these commands&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git --verison&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Cloning a repo
&lt;/h1&gt;

&lt;p&gt;I prefer to use SSH instead of HTTP.&lt;br&gt;
If you haven't set up the key, please read &lt;a href="https://dev.to/zakiarsyad/git-getting-started-with-git-31m6"&gt;this post&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone git@github.com:zakiarsyad/js-snake.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Check remote repository
&lt;/h1&gt;

&lt;p&gt;Remote repository is versions of our project that are hosted on the Internet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;
origin git@github.com:zakiarsyad/js-snake.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
origin git@github.com:zakiarsyad/js-snake.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default we will work with the origin remote.&lt;/p&gt;

&lt;p&gt;We can have more than one remote, if we need to pulling from other repositories.&lt;/p&gt;




&lt;h1&gt;
  
  
  Check status
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git status
On branch master
nothing to commit, working tree clean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command tells us which branch we are in. If there are any changes in our code, those will be displayed here as well, as long as we don't commit the changes yet.&lt;/p&gt;

&lt;p&gt;The main branch in git is master. Basically we don't work directly in master branch.&lt;br&gt;
We might need another branch like &lt;code&gt;development&lt;/code&gt; or other environment to test the code before we put our code in the main branch. We also might need a new branch every time we build a new feature or fixing a bug. &lt;/p&gt;


&lt;h1&gt;
  
  
  Create a new branch
&lt;/h1&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; &lt;span class="s2"&gt;"our-branch"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run this command to create a new branch from branch we are in previously.&lt;/p&gt;

&lt;p&gt;This command will create a branch from our origin remote repository. If we We also can branch out directly from other remote repository.&lt;/p&gt;


&lt;h1&gt;
  
  
  Add changes
&lt;/h1&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git add &amp;lt;file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After creating changes in our code, we need to add it to be committed in git. So that we can track our changes later.&lt;/p&gt;

&lt;p&gt;We can add the file one by one, or just run &lt;code&gt;git add .&lt;/code&gt;  to add all changes we have made.&lt;/p&gt;

&lt;p&gt;As long as we don't commit the changes yet, we can unstage our changes to be committed by running this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; &amp;lt;file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or use &lt;code&gt;git restore --staged .&lt;/code&gt; to unstage all changes.&lt;/p&gt;




&lt;h1&gt;
  
  
  Commit changes
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"put-our-message-here"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commit is like when we save our changes. Every time we save, git creates an unique ID that tells us what changes were made when and by who. We also need to put the message which is a brief description of what changes were made.&lt;/p&gt;

&lt;p&gt;The commit ID or commit hash is a unique identifier for changes that have made. If needed, in the future we can easily revert the code to any version anytime in one click.&lt;/p&gt;




&lt;h1&gt;
  
  
  View log
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can easily track our changes by using this command. All changes in our branch are listed with its commit ID and message.&lt;/p&gt;




&lt;h1&gt;
  
  
  Push changes
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin our-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll need to put our code in our online repository.&lt;/p&gt;




&lt;h1&gt;
  
  
  Create a Pull Request
&lt;/h1&gt;

&lt;p&gt;To combine our changes to master branch or other base branch, we need to create a Pull Request.&lt;/p&gt;

&lt;p&gt;Open a pull request from our branch to the base. Put title and brief description about what we have done. Then ask others to review.&lt;/p&gt;




&lt;h1&gt;
  
  
  Merge a Pull Request
&lt;/h1&gt;

&lt;p&gt;If everything is ok, then it time to update the base branch by merging our changes.&lt;/p&gt;

</description>
      <category>git</category>
      <category>cli</category>
    </item>
    <item>
      <title>git : getting started with git</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Sun, 21 Jun 2020 17:20:48 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/git-getting-started-with-git-31m6</link>
      <guid>https://dev.to/zakiarsyad/git-getting-started-with-git-31m6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/"&gt;Git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git is the most commonly used for version control. Git help us to makes collaboration easy. Even we work by our self, we will love it.&lt;/p&gt;

&lt;p&gt;Git runs in our local machine. We also can use online host such as Github, Gitlab, and Bitbucket.&lt;/p&gt;




&lt;h1&gt;
  
  
  Installing git
&lt;/h1&gt;

&lt;p&gt;We can easily download git from this &lt;a href="https://git-scm.com/downloads"&gt;Download page&lt;/a&gt;.&lt;br&gt;
For MacOs, I prefer to use homebrew instead. Just simply type this command &lt;code&gt;brew install git&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And in linux, I will do &lt;code&gt;apt-get install git&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;git&lt;/code&gt; in our terminal to check if it's successfully installed.&lt;/p&gt;


&lt;h1&gt;
  
  
  Connecting to github with SSH
&lt;/h1&gt;

&lt;p&gt;There are two ways if we want to communicate with github.&lt;/p&gt;

&lt;p&gt;First one is using HTTP, and the second one is using SSH. Actually we don't need anything else if we want to clone a github repository using HTTP, but we will need some configurations if we want to use SSH.&lt;/p&gt;

&lt;p&gt;This example is explaining in linux machine, need a little adjustment if we run MacOs or Windows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generating a new SSH key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run this terminal command to create a new SSH key&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; rsa &lt;span class="nt"&gt;-b&lt;/span&gt; 4096 &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"our_email@example.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, the key will saved in this path &lt;code&gt;~/.ssh/id_rsa.pub&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding the SSH key to our github account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Copy the &lt;code&gt;id_rsa.pub&lt;/code&gt; file generated by previous command.&lt;/p&gt;

&lt;p&gt;Go to our github account. Find &lt;strong&gt;Settings&lt;/strong&gt; - &lt;strong&gt;SSH and GPGP keys&lt;/strong&gt; - &lt;strong&gt;New SSH key.&lt;/strong&gt;&lt;br&gt;
Create a &lt;strong&gt;Title&lt;/strong&gt; and paste our &lt;strong&gt;Key&lt;/strong&gt; there, then hit &lt;strong&gt;Add SSH Key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We can run this command to test if our key is successfully configured.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ssh &lt;span class="nt"&gt;-T&lt;/span&gt; git@github.com
Hi zakiarsyad! You&lt;span class="s1"&gt;'ve successfully authenticated, but GitHub does not provide shell access.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Setting our git username
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# setting our username&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"zakiarsyad"&lt;/span&gt;

&lt;span class="c"&gt;# confirm that we set userneame correctly&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name
zakiarsyad
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Setting our commit email address
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# setting our username&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email &lt;span class="s2"&gt;"zakiarsyad@mail.com"&lt;/span&gt;

&lt;span class="c"&gt;# confirm that we set userneame correctly&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email
zakiarsyad@mail.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;git is ready to use in our local machine.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>cli</category>
    </item>
    <item>
      <title>linux : bash script conditions</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Sat, 20 Jun 2020 18:06:29 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/bash-script-conditions-1ano</link>
      <guid>https://dev.to/zakiarsyad/bash-script-conditions-1ano</guid>
      <description>&lt;p&gt;Basic usage of if statement in bash scripting&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; CONDITION &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;FIRST_COMMANDS
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; CONDITION &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;SECOND_COMMANDS
&lt;span class="k"&gt;else
    &lt;/span&gt;THRID_COMMANDS
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Always use space between the brackets in the condition.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Always terminate the line with &lt;code&gt;;&lt;/code&gt; before adding a new keyword&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if [ CONDITION ]; then&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;code&gt;!&lt;/code&gt; to invert the condition&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if [ ! CONDITION ]; then&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Combine conditions using &lt;code&gt;-a&lt;/code&gt; for AND, and &lt;code&gt;-o&lt;/code&gt; for OR&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;There are three syntaxes for define the condition&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Single-bracket
&lt;/h1&gt;

&lt;p&gt;Support 3 types of conditions&lt;/p&gt;

&lt;h2&gt;
  
  
  File-based condition
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[ -a file ]&lt;/code&gt; or &lt;code&gt;[ -e file ]&lt;/code&gt; : if the file is exists&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ -d directory ]&lt;/code&gt; : if the directory is exists and it's a directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ -r file ]&lt;/code&gt; : if the file is exists and is readable to the script&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ -w file ]&lt;/code&gt; : if the file is exists and is writeable to the script&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ -x file ]&lt;/code&gt; : if the file is exists and is executable to the script&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -s file ]&lt;/code&gt; : if the file is exists and has a size of more than 0 bytes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ file1 -ef file2]&lt;/code&gt; : if the files refer to the same device/inode number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ file1 -nt file2]&lt;/code&gt; : if the file1 was changed more recently than file2, or if file1 exists and file2 doesn't&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ file1 -nt file2]&lt;/code&gt; : if the file1 was changed longer ago than file2, or if file1  exists and exists&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -N file ]&lt;/code&gt; : if the file is exists and was modified after the last read&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -g file ]&lt;/code&gt; : if the file is exists and is a set-group-ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -u file ]&lt;/code&gt; : if the file is exists and is a set-user-ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -G file ]&lt;/code&gt; : if the file is exists and is owned by the effective group ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -O file ]&lt;/code&gt; : if the file is exists and is owned by the user executing the script&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -b file ]&lt;/code&gt; : if the file is exists and is a block special&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -c file ]&lt;/code&gt;  : if the file is exists and is a character special&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -f file ]&lt;/code&gt; : if the file is exists and is a regular file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -h file ]&lt;/code&gt; or &lt;code&gt;[ -L file ]&lt;/code&gt; : if the file is exists and is a symbolic link&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -k file ]&lt;/code&gt; : if the file is exists and has its sticky bit set&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -p file ]&lt;/code&gt; : if the file is exists and is a named pipe&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -S file ]&lt;/code&gt; : if the file is exists and is a socket&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[ -t file ]&lt;/code&gt; : if the file descriptor is exists and refers to an open terminal&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  String-based condition
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[ STRING1 == STRING2 ]&lt;/code&gt; : if equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ STRING1 != STRING2 ]&lt;/code&gt; : if not equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ -n STRING ]&lt;/code&gt; : if has length of more than zero&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ -z STRING ]&lt;/code&gt; : if an empty string&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ STRING =~ PATTERN ]&lt;/code&gt; : if match the regex pattern&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Arithmetic condition
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[ NUM1 -eq NUM2 ]&lt;/code&gt; : if equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ NUM1 -ne NUM2 ]&lt;/code&gt; : if not equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ NUM1 -gt NUM2 ]&lt;/code&gt; : if greater than&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ NUM1 -ge NUM2 ]&lt;/code&gt; : if greater than equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ NUM1 -lt NUM2 ]&lt;/code&gt; : if less than&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[ NUM1 -le NUM2 ]&lt;/code&gt; : if less than equal&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  2. Double-bracket
&lt;/h1&gt;

&lt;p&gt;This is the enhanced version of single-bracket. All features in single-bracket syntax are compatible here. We can start using this syntax. &lt;/p&gt;

&lt;p&gt;The differences :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Can use regex&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[[ STRING =~ PATTERN ]]&lt;/code&gt; : if match the regex pattern&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can use &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt;  instead of &lt;code&gt;-a&lt;/code&gt; and &lt;code&gt;-o&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  3. Double-parenthesis
&lt;/h1&gt;

&lt;p&gt;This is another syntax for arithmetic condition&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;(( NUM1 == NUM2 ))&lt;/code&gt; : if equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(( NUM1 != NUM2 ))&lt;/code&gt; : if not equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(( NUM1 &amp;gt; NUM2 ))&lt;/code&gt; : if grater than&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(( NUM1 &amp;gt;= NUM2 ))&lt;/code&gt; : if grater than equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(( NUM1 &amp;lt; NUM2 ))&lt;/code&gt; : if less than&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(( NUM1 &amp;lt;= NUM2 ))&lt;/code&gt; : if less than equal&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;We also can quickly test a condition like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# using &amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$foo&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"bar"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo true&lt;/span&gt;

&lt;span class="c"&gt;# using ||&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$foo&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"bar"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;echo true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>bash</category>
      <category>scripting</category>
    </item>
    <item>
      <title>linux : bash script</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Sat, 20 Jun 2020 16:16:14 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/linux-part-11-bash-script-3l5p</link>
      <guid>https://dev.to/zakiarsyad/linux-part-11-bash-script-3l5p</guid>
      <description>&lt;p&gt;We can run the bash script directly in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ echo "This is a bash script."
This is a bash script.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also can store the script in a file, so that we can run it every time we want without typing the script in terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# !/bin/bash&lt;/span&gt;
echo "This is a bash script." 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to update the file permission if we want to run the bash file. We can run this command, and specify the file permission&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ chmod 700 FILE
$ ./FILE
This is a bash script.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can run linux command in bash file and run the bash script in the cli.&lt;/p&gt;




&lt;p&gt;The bash file will very useful if we want to use some variable or put logics in the script.&lt;/p&gt;




&lt;h2&gt;
  
  
  VARIABLE
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Positional Parameter Variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# !/bin/bash&lt;/span&gt;
echo "This is a $1 $2." 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can give a value for &lt;code&gt;$1&lt;/code&gt; and &lt;code&gt;$2&lt;/code&gt; after the run command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ ./FILE bash script
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;User Defined Variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# !/bin/bash&lt;/span&gt;
&lt;span class="gh"&gt;# define a string value, print as is&lt;/span&gt;
print1='script'

&lt;span class="gh"&gt;# define a string value, we can add variable inside the double quotes&lt;/span&gt;
print2="bash $print1"

&lt;span class="gh"&gt;# define a number&lt;/span&gt;
print3=3

&lt;span class="gh"&gt;# define a command&lt;/span&gt;
print4=&lt;span class="sb"&gt;`clear`&lt;/span&gt;

echo $script
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Environment Variable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Usually we use &lt;code&gt;.env&lt;/code&gt; file to store the environment variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;PORT=80
ENV=development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;operation for variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# using let&lt;/span&gt;
let sum=$number1+$number2

&lt;span class="gh"&gt;# using expr&lt;/span&gt;
sum=&lt;span class="sb"&gt;`expr $number1 + $number2`&lt;/span&gt;
length=&lt;span class="sb"&gt;`expr length $string`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;declaring variable type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# declare an intrger&lt;/span&gt;
declare -i number
number=100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  IF STATEMENT
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; CONDITION &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;TRUE_COMMANDS
&lt;span class="k"&gt;else
    &lt;/span&gt;FALSE_COMMANDS
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  WHILE LOOPING
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; CONDITION &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;COMMANDS
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  FOR LOOPING
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;VARIABLE &lt;span class="k"&gt;in &lt;/span&gt;LIST
&lt;span class="k"&gt;do
    &lt;/span&gt;COMMANDS
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>bash</category>
      <category>cli</category>
      <category>linux</category>
    </item>
    <item>
      <title>linux : package and service management</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Sat, 20 Jun 2020 16:03:29 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/linux-part-10-package-and-service-management-17b8</link>
      <guid>https://dev.to/zakiarsyad/linux-part-10-package-and-service-management-17b8</guid>
      <description>&lt;h1&gt;
  
  
  Package management
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;First, we need to update our repository
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ apt-get update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install a package
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ apt-get install APPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check if a package is already installed
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ dpkg -l | grep APPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Remove a package
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ apt-get remove APPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Search packages by a keyword
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ apt-cache search “KEYWORD”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Service management
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Check if a service is running
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ systemctl status APPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Start a service
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ systemctl start APPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Stop a service
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ systemctl stop APPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Restart a service
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ systemctl restart APPNAME 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check autostart enable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ systemctl is-enabled APPNAME 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enable autostart
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ systemctl enable APPNAME 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Disable autostart
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ systemctl disable APPNAME 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>cli</category>
    </item>
    <item>
      <title>linux : user management and permission</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Thu, 11 Jun 2020 08:01:23 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/user-management-and-permission-p0e</link>
      <guid>https://dev.to/zakiarsyad/user-management-and-permission-p0e</guid>
      <description>&lt;p&gt;This is one of the best part of linux, we can grant access for all services, directories, files, and even commands that can be executed for a specific user or group.&lt;/p&gt;




&lt;h1&gt;
  
  
  User management
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Check who am i
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ whoami
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check the user id
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ id USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check the group of user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ groups USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check who is currently logged in
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ w
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check the last logged in
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ last
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Change user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ su
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add a new user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ useradd USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Set password for a user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ passwd PASSWORD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Change user name
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ usermod -l USERNAME NEW_USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add a user to a group
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ usermod -a -G GROUPNAME USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Change user primary group
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ usermod -g GROUPNAME USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Remove user from a group
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gpasswd -d USERNAME GROUPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Delete a user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ userdel -r USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Lock a user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ passwd -l USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Unlock a user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ passwd -u USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Group management
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Add a new group
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ groupadd GROUPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Change group name
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ groupmod -n GROUPNAME NEW_GROUPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Delete a user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ groupdel GROUPNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Permission
&lt;/h1&gt;

&lt;p&gt;After create a user or group, we can grant access for specific user or group.&lt;/p&gt;

&lt;p&gt;Permission format :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rwxrwxrwx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First 3 characters are the user permission, next 3 characters are the group permission, and the last 3 are other permission.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;r&lt;/code&gt; is for &lt;code&gt;read&lt;/code&gt; with value &lt;code&gt;4&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;w&lt;/code&gt; is for &lt;code&gt;write&lt;/code&gt; with value &lt;code&gt;2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; is for &lt;code&gt;execute&lt;/code&gt; with value &lt;code&gt;1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-&lt;/code&gt; is for &lt;code&gt;no permission&lt;/code&gt; with value &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can also use the value of the characters to define the permission. Simply sum the values of the permissions for each role, and use only 3 numbers to define the permission.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# rwxrwxrwx
777

# rwxr-x-rx
755

# rwx------
700
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;We can see the files or directories permission by run &lt;code&gt;ls -l&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -la
drwxrwxrwx 1 root root  96 Jun 11 07:58 directory
-rwxr-xr-x 1 zaki zaki  96 Jun 11 07:58 file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first column is the permission, the third column is the user, the fourth column is the group name.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>linux : rsync vs scp</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Thu, 11 Jun 2020 03:13:05 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/rsync-vs-scp-1jfp</link>
      <guid>https://dev.to/zakiarsyad/rsync-vs-scp-1jfp</guid>
      <description>&lt;p&gt;&lt;strong&gt;rsync&lt;/strong&gt; is a command for move and synchronizing files. This command help us to manage files or directories effectively when backing up data on a regular basis. &lt;strong&gt;rsync&lt;/strong&gt; compares any differences and only transfer those differences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;scp&lt;/strong&gt; is used for copy files and directories in secure way. Basically, It is a plain linear copy. &lt;strong&gt;scp&lt;/strong&gt; reads the source file and writes it to the destination.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;rsync&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Basic usage :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ rsync OPTION SOURCE DESTINATION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to check if we have &lt;code&gt;rsync&lt;/code&gt;, because some machines might not have this command.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Not passing the &lt;code&gt;OPTION&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will sync between two directories, but only files in the main directory, not include files in the subdirectories.&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Sync all files in original directory to duplicate directory&lt;/span&gt;
$ rsync SOURCE/&lt;span class="err"&gt;*&lt;/span&gt; DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-r&lt;/code&gt; or &lt;code&gt;-recursive&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Sync all files in all the main directory and subdirectories&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Sync all files in original directory and its subdirectories&lt;/span&gt;
$ rsync -r SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-a&lt;/code&gt; or &lt;code&gt;-archive&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This option allow us to copy almost everything, including file permissions, user &amp;amp; group ownership and timestamps.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-v&lt;/code&gt; or &lt;code&gt;-verbose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It gives us a summary about the data transferred.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-h&lt;/code&gt; or &lt;code&gt;--human-readable format&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We will get the result in  human readable format.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-z&lt;/code&gt; or &lt;code&gt;-compress&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Compress file data during the transfer&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-e&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To specify the type of protocol we use. We can choose using &lt;code&gt;ssh&lt;/code&gt; or &lt;code&gt;rsh&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Sync using ssh protocol&lt;/span&gt;
$ rsync -avhze ssh SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--progress&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To show the progress while transferring the data&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Show the progress during transfer&lt;/span&gt;
$ rsync -avhze ssh --progress SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To updated more recently on the local filesystem. Files that don't exist are copied. Files that already exist, but have a newer timestamp are also copied.&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Update only if there is a newer version&lt;/span&gt;
$ rsync -avhze ssh --progress --update SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--remove-source-files&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To remove files that successfully transferred.&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Sync using ssh protocol&lt;/span&gt;
$ rsync -avhze ssh --remove-source-files SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--delete&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Delete files that have been deleted in the original directory&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Update duplicate directory if there are files deleted in original directory&lt;/span&gt;
$ rsync -avhze ssh --delete SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--include&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This option will include files that we specify in the parameter&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Include files that matched with include paramaeter&lt;/span&gt;
$ rsync -avhze ssh --include 'KEYWORD' SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--exclude&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This option will exclude files that we specify in the parameter&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Exclude files that matched with exclude paramaeter&lt;/span&gt;
$ rsync -avhze ssh --exclude 'KEYWORD' SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--chown&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Change file permission in the destination directory&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Copied files permisson are changed form user to group&lt;/span&gt;
$ rsync -avhe ssh --chown=USER:GROUP SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--dry-run&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This option perform a trial run and will not make any changes, but gives us the same result as a real run. If the results are as expected, then we can remove the &lt;code&gt;--dry-run&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Perfom dry run&lt;/span&gt;
$ rsync --dry-run -avhze ssh --delete SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--max-size&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Set the maximum files to transfer. This option will only transfer files that are equal or smaller than the max size.&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Set max size 200k&lt;/span&gt;
$ rsync -avhze ssh --max-size='200k' SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--bwlimit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can set the bandwidth limit when we sync data from a machine to another machine.&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Set bandwidth rate 5000KBytes per second&lt;/span&gt;
$ rsync -avhze ssh --bwlimit=5000 SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  &lt;code&gt;scp&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Basic usage :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ scp OPTION SOURCE DESTINATION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Copy a single file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Copy a single file&lt;/span&gt;
$ scp SOURCE_FILE.txt DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Copy multiple files
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Copy a multiple file&lt;/span&gt;
$ scp FILE1.txt FILE2.txt FILE3.txt DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Copy .pem file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Copy aws key to vm &lt;/span&gt;
$ scp -i file.pem file.pem DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-r&lt;/code&gt; to copy a directory recursively
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Copy all files in a directory&lt;/span&gt;
$ scp -r SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-P&lt;/code&gt; to specify the port&lt;/p&gt;

&lt;p&gt;By default, &lt;code&gt;scp&lt;/code&gt; will use port 22, but we can use another port for security reason&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Use port 2249&lt;/span&gt;
$ scp -P 2249 SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-v&lt;/code&gt; for verbose&lt;/p&gt;

&lt;p&gt;To show detailed information of the scp process&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Use port 2249&lt;/span&gt;
$ scp -v SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-l&lt;/code&gt; limit the bandwidth usage
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Set the bandwidth limit&lt;/span&gt;
$ scp -l 400 SOURCE/ DESTINATION/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-q&lt;/code&gt; for quite mode&lt;/p&gt;

&lt;p&gt;Run the command in quite mode, and only display critical errors&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;-p&lt;/code&gt; for preserves modification times, access times, and modes from the original file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;-u&lt;/code&gt; to delete source files after the transfer is successful&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Both of the commands are similar, lets choose what we use based on our case&lt;/p&gt;

</description>
      <category>linux</category>
      <category>cli</category>
      <category>terminal</category>
    </item>
    <item>
      <title>linux : find</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Wed, 10 Jun 2020 02:26:44 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/finding-files-35di</link>
      <guid>https://dev.to/zakiarsyad/finding-files-35di</guid>
      <description>&lt;p&gt;We can search files or directories in linux using &lt;code&gt;find&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Basic usage :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;find DIRECTORY OPTION WHAT_TO_FIND
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  DIRECTORY :
&lt;/h2&gt;

&lt;p&gt;We can specify where we want to run the find command. &lt;/p&gt;

&lt;p&gt;By default, if we don't specify the directory it will call the current directory &lt;code&gt;./&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find FILE.txt in home directory&lt;/span&gt;
$ find /home -name "FILE.txt"

&lt;span class="gh"&gt;# find all .txt files in the current directory&lt;/span&gt;
$ find -name "&lt;span class="err"&gt;*&lt;/span&gt;.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  OPTIONS :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-type f&lt;/code&gt; : find files
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find matched files&lt;/span&gt;
$ find -type f -name "FILE.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;by default find is finding files. we can also use &lt;code&gt;-type f&lt;/code&gt; for file type&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-type d&lt;/code&gt; : find a directories
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find matched directories&lt;/span&gt;
$ find -type d -name "DIRECTORY"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-iname&lt;/code&gt; : find with case insensitive
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find a FILE.txt or file.txt&lt;/span&gt;
$ find -iname "FILE.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-print&lt;/code&gt; : display the path name&lt;/p&gt;

&lt;p&gt;We can use &lt;code&gt;-print&lt;/code&gt; option or not with the sam result.&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find files&lt;/span&gt;
$ find -name "FILE.txt" -print

&lt;span class="gh"&gt;# find directories&lt;/span&gt;
$ find -type d -name "DIRECTORY"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-size&lt;/code&gt; : find by size
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find files smaller than 10MB&lt;/span&gt;
$ find -size -10M

&lt;span class="gh"&gt;# find files larger than 10MB&lt;/span&gt;
$ find -size +10M

&lt;span class="gh"&gt;# find files exactly 3 10MB&lt;/span&gt;
$ find -size 10M

&lt;span class="gh"&gt;# find files between 10MB and 1GB&lt;/span&gt;
$ find -size +10M -size -1G
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-empty&lt;/code&gt; or &lt;code&gt;-size 0&lt;/code&gt; : find empty files or directories
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find an empty files&lt;/span&gt;
$ find -type f -empty

&lt;span class="gh"&gt;# find an empty directories&lt;/span&gt;
$ find -type d -size 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-exec CMD&lt;/code&gt; :  execute a command after
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# execute grep after find is done&lt;/span&gt;
$  find -name "FILE.txt" -exec grep "KEYWORD" {} &lt;span class="se"&gt;\;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-delete&lt;/code&gt; or &lt;code&gt;-exec rm {} \;&lt;/code&gt; : delete matched files or directories
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# delete an mathed files&lt;/span&gt;
$ find -name "&lt;span class="err"&gt;*&lt;/span&gt;.bak" -delete

&lt;span class="gh"&gt;# delete an empty directories&lt;/span&gt;
$ find -type d -size 0 -exec rmdir {} &lt;span class="se"&gt;\;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;not&lt;/code&gt; or &lt;code&gt;!&lt;/code&gt; : exclude the matched files or directories
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find all except the matched files&lt;/span&gt;
$ find -not -name "FILE.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-mtime&lt;/code&gt; : find by modified time&lt;/p&gt;

&lt;p&gt;we also can use &lt;code&gt;-mmin&lt;/code&gt; if we want to specify the time interval to minutes&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find files modified within the last 3 days&lt;/span&gt;
$ find -name "FILE.txt" -mtime -3

&lt;span class="gh"&gt;# find files modified more than 3 days&lt;/span&gt;
$ find -name "FILE.txt" -mtime +3

&lt;span class="gh"&gt;# find files modified exactly 3 days&lt;/span&gt;
$ find -name "FILE.txt" -mtime 3

&lt;span class="gh"&gt;# find files modified between 3 and 10 days&lt;/span&gt;
$ find -name "FILE.txt" -mtime +3 -mtime -10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-atime&lt;/code&gt; : find by accessed time&lt;/p&gt;

&lt;p&gt;we also can use &lt;code&gt;-amin&lt;/code&gt; if we want to specify the time interval to minutes&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find files accessed within the last 3 days&lt;/span&gt;
$ find -name "FILE.txt" -atime -3

&lt;span class="gh"&gt;# find files accessed more than 3 days&lt;/span&gt;
$ find -name "FILE.txt" -atime +3

&lt;span class="gh"&gt;# find files accessed exactly 3 days&lt;/span&gt;
$ find -name "FILE.txt" -atime 3

&lt;span class="gh"&gt;# find files accessed between 3 and 10 days&lt;/span&gt;
$ find -name "FILE.txt" -atime +3 -atime -10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-ctime&lt;/code&gt; : find by changed time&lt;/p&gt;

&lt;p&gt;we also can use &lt;code&gt;-cmin&lt;/code&gt; if we want to specify the time interval to minutes&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find files changed within the last 3 days&lt;/span&gt;
$ find -name "FILE.txt" -atime -3

&lt;span class="gh"&gt;# find files changed more than 3 days&lt;/span&gt;
$ find -name "FILE.txt" -atime +3

&lt;span class="gh"&gt;# find files changed exactly 3 days&lt;/span&gt;
$ find -name "FILE.txt" -atime 3

&lt;span class="gh"&gt;# find files changed between 3 and 10 days&lt;/span&gt;
$ find -name "FILE.txt" -atime +3 -atime -10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-perm&lt;/code&gt; : find by permission
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find files with permission 777&lt;/span&gt;
$ find -perm 777
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-user&lt;/code&gt; : find by user access
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find matched files with user root&lt;/span&gt;
$ find -user root -name "FILE.txt" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-group&lt;/code&gt; : find by group access
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# find matched files with group developer&lt;/span&gt;
$ find -group developer -name "FILE.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;find hidden files
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;$ find -name ".&lt;span class="err"&gt;*&lt;/span&gt;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>cli</category>
      <category>terminal</category>
    </item>
    <item>
      <title>linux : archiving &amp; compression</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Sat, 30 May 2020 17:12:09 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/file-archiving-compression-568h</link>
      <guid>https://dev.to/zakiarsyad/file-archiving-compression-568h</guid>
      <description>&lt;p&gt;&lt;strong&gt;Archiving&lt;/strong&gt; is the process of combining multiple files and directories (same or different sizes) into one file. &lt;strong&gt;Compression&lt;/strong&gt; is the process of reducing the size of a file or directory.&lt;/p&gt;

&lt;p&gt;Common type of compression:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Gzip&lt;/code&gt; : with extension &lt;code&gt;.tar.gz&lt;/code&gt;. It has fastest compression time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Bzip&lt;/code&gt; : with extension &lt;code&gt;.tar.bz2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Xz&lt;/code&gt; : with extension &lt;code&gt;.tar.xz&lt;/code&gt;. It has smallest size compression.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Common programs for archiving files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tar&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;zip&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gzip&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bzip2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;xz&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;We will talk about how we use &lt;code&gt;tar&lt;/code&gt; command. It has a lot of option that we can use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-c&lt;/code&gt; or &lt;code&gt;--create&lt;/code&gt; : create a new file archive&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-f&lt;/code&gt; or &lt;code&gt;--file&lt;/code&gt; : filename&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# create an archive from multiple files
tar -cf ARCHIVE.tar FILE1.txt FILE2.txt FILE3.txt

# create an archive from a directory
tar -cf ARCHIVE.tar DIRECTORY

# using long command
tar --create --file ARCHIVE.tar DIRECTORY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-X&lt;/code&gt; or &lt;code&gt;--exclude&lt;/code&gt; : exclude a file&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# exclude a file when creating an archive
tar -cf ARCHIVE.tar DIRECTORY --exclude=FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-x&lt;/code&gt; or &lt;code&gt;--extract&lt;/code&gt; : extract an archive&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# extract an archive file
tar -xf ARCHIVE.tar

# using long command
tar --extract --file ARCHIVE.tar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-z&lt;/code&gt; : zip or unzip using &lt;code&gt;gzip&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;create a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# create an archive with gzip compression
tar -czf ARCHIVE.tar.gz DIRECTORY

# using gzip
gzip ARCHIVE.tar.gz DIRECTORY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;extract a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# extract an archive with gzip compression
tar -xzf ARCHIVE.tar.gz

# using gunzip --decompress
gunzip -d ARCHIVE.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-j&lt;/code&gt; : zip or unzip using &lt;code&gt;bzip2&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;create a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# create an archive with bzip compression
tar -cjf ARCHIVE.tar.bz2 DIRECTORY

# using bzip2
bzip2 ARCHIVE.tar.bz2 DIRECTORY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;extract a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# extract an archive with bzip compression
tar -xjf ARCHIVE.tar.bz2

# using bunzip2 --decompress
bunzip2 -d ARCHIVE.tar.bz2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-J&lt;/code&gt; : zip or unzip using &lt;code&gt;xz&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;create a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# create an archive with xz compression
tar -cJf ARCHIVE.tar.xz DIRECTORY

# using xz
xz ARCHIVE.tar.xz DIRECTORY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;extract a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# extract an archive with xz compression
tar -xJf ARCHIVE.tar.xz

# using unxz --decompress
unxz -d ARCHIVE.tar.xz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;zip&lt;/code&gt; and &lt;code&gt;unzip&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;create a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# create using zip
zip ARCHIVE.zip DIRECTORY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;extract a compressed archive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# extract using unzip
unzip ARCHIVE.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-t&lt;/code&gt; or &lt;code&gt;--list&lt;/code&gt; : list the contents of an archive without extracting it&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# display contents of an archive
tar -tf ARCHIVE.tar

# display contents using gzip
gzip -l ARCHIVE.tar.gz

# display contents using unzip
unzip -l ARCHIVE.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-r&lt;/code&gt; or &lt;code&gt;--append&lt;/code&gt; : append files to the end of an archive&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# append files to an archive
tar -rf ARCHIVE.tar FILE.txt

# using --append
tar --append -file ARCHIVE.tar FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-u&lt;/code&gt; or &lt;code&gt;--update&lt;/code&gt; : Append files which are newer than the corresponding copy in the archive&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# append files to an archive
tar -uf ARCHIVE.tar FILE.txt

# using --append
tar --update -file ARCHIVE.tar FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;delete&lt;/code&gt; : delete files inside an archive&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# delete from the archive
tar --delete --file ARCHIVE.tar FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-C&lt;/code&gt; or &lt;code&gt;--directory&lt;/code&gt; : change the directory&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# change location of unarchived files
tar -xf ARCHIVE.tar -C DIRECTORY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;-v&lt;/code&gt; or &lt;code&gt;--verbose&lt;/code&gt; : see the detailed output&lt;/strong&gt;&lt;br&gt;
We can combine this options with all others&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;--wildcards&lt;/code&gt; : matching on the filenames within an archive&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# extract a particular type of file
tar -xf ARCHIVE.tar --wildcards "*.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>commandline</category>
      <category>devops</category>
    </item>
    <item>
      <title>linux : regex</title>
      <dc:creator>Zaki Arrozi Arsyad</dc:creator>
      <pubDate>Wed, 27 May 2020 16:30:31 +0000</pubDate>
      <link>https://dev.to/zakiarsyad/regular-expression-for-linux-command-line-man</link>
      <guid>https://dev.to/zakiarsyad/regular-expression-for-linux-command-line-man</guid>
      <description>&lt;p&gt;Regex or regular expression is a text pattern. Basically we use regex for helping us search, update, or manage text. We can combine regex with &lt;code&gt;grep&lt;/code&gt;, &lt;code&gt;sed&lt;/code&gt;, or &lt;code&gt;awk&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Basic usage :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grep -E REGEX_PATTERN FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll talk about how we can create a regex pattern. Thing to note, regex is case sensitive. I will use &lt;code&gt;grep&lt;/code&gt; for simple examples. It will display text with matched pattern.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. Basic matcing
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; is search for anything, or replace &lt;code&gt;.&lt;/code&gt; with any character
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with anything
grep -E . FILE.txt

# matched with 'linux' or 'lanux' or etc
grep -E l.nux FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\d&lt;/code&gt; is for digit in 0 - 9
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with all digits
grep -E '\d' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\D&lt;/code&gt; is for non-digit
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with all non digit
grep -E '\D' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\w&lt;/code&gt; is for word ( &lt;code&gt;letter&lt;/code&gt;, &lt;code&gt;digit&lt;/code&gt;, and &lt;code&gt;_&lt;/code&gt; )
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with all word
grep -E '\w' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&lt;/code&gt; is for space
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with space
grep -E ' ' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&lt;/code&gt; is for space
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with space
grep -E ' ' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\t&lt;/code&gt; is for tab
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with tab
grep -E '\t' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\r&lt;/code&gt; is for return
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with return
grep -E '\r' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\n&lt;/code&gt; is for new line
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with new line
grep -E '\n' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\s&lt;/code&gt; is for whitespace
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with whitespace. Include space, tab, return, and new line
grep -E '\s' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\S&lt;/code&gt; is for non whitespace
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with non whitespace
grep -E '\S' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  2. Classes
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;[ ]&lt;/code&gt; -&amp;gt; matched any character inside the square bracket.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[linux]&lt;/code&gt; matched anything inside the square bracket
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with any characters inside the square bracket
grep -E '[linux]' FILE.txt

# matched with linux and xinux
grep -E '[lx]inux' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[^linux]&lt;/code&gt; matched any characters except characters inside the square bracket
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with any characters except l, i, n, u, and x
grep -E '[^linux]' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[a-z]&lt;/code&gt; matched anything in the range of characters
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with all lowercase
grep -E '[a-z]' FILE.txt

# matched with all uppercase
grep -E '[A-Z]' FILE.txt

# matched with all digit
grep -E '[0-9]' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  3. Boundaries
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;\b&lt;/code&gt; is for boundaries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;\B&lt;/code&gt; is for non boundaries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;^&lt;/code&gt; is for the beginning of the line&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with anything started with l
grep -E '^l' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;$&lt;/code&gt; is for the end of the line
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with anything ended with x
grep -E '^x' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  4. Disjunction
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;|&lt;/code&gt; is for or
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with linux and unix
grep -E 'linux|unix' FILE\.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  5. Quantifier
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;*&lt;/code&gt; is for zero or more repetition
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with lnux, linux, liinux, etc
grep -E 'li*nux' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt; is for one or more repetition
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with linux, liinux, etc, but doesn't matched with lnux
grep -E 'li+nux' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;?&lt;/code&gt; is for zero or one instances
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with lnux and linux
grep -E 'li?nux' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{n}&lt;/code&gt; is for exactly n instances
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with linuxlinuxlinux
grep -E '(linux){3}' FILE.txt

# matched with linuxxx
grep -E 'linux{3}' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{n,}&lt;/code&gt; is for at least n instances
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with linuxxx with 3 or more x
grep -E 'linux{3,}' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{m,n}&lt;/code&gt; is for between m and n instances
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with linuxx with 2 until 4 x
grep -E 'linux{2,4}' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, quantifier are &lt;code&gt;greedy&lt;/code&gt;. example for word &lt;code&gt;linuxlinuxlinux&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;greedy
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with all stacko
print stackoverflow | grep -E 's.*o'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;lazy
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with all stackoverflo
print stackoverflow | grep -E 's.*?o'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  6. Special characters
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{ } [ ] ( ) ^ $ . | * + ? \ -&lt;/code&gt; inside the square bracket must be escaped with &lt;code&gt;\&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with period
grep -E '[\.]' FILE.txt

# matched with backslash
grep -E '[\\]' FILE.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  7. Given two criteria
&lt;/h1&gt;

&lt;p&gt;we can combine 2 or more pattern&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matched with text beginning with a digit and have linux word
grep -E '^[1-9]' FILE.txt | grep -E 'linux'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>regex</category>
      <category>devops</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
