<?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: Kurumi</title>
    <description>The latest articles on DEV Community by Kurumi (@walnut07).</description>
    <link>https://dev.to/walnut07</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%2F907420%2F11a110d8-2ef2-47b6-9db7-f323341c3f22.jpeg</url>
      <title>DEV Community: Kurumi</title>
      <link>https://dev.to/walnut07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/walnut07"/>
    <language>en</language>
    <item>
      <title>Terminal Commands that Every Developers Should Know</title>
      <dc:creator>Kurumi</dc:creator>
      <pubDate>Wed, 19 Apr 2023 12:12:19 +0000</pubDate>
      <link>https://dev.to/walnut07/terminal-commands-that-every-developers-should-know-181e</link>
      <guid>https://dev.to/walnut07/terminal-commands-that-every-developers-should-know-181e</guid>
      <description>&lt;p&gt;Today, I'm going to introduce some useful commands that every developer should know.&lt;br&gt;
I will update this article as I learn more commands, so please bookmark it and check it back later!&lt;/p&gt;

&lt;p&gt;Table of Contents:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;grep&lt;/li&gt;
&lt;li&gt;sed&lt;/li&gt;
&lt;li&gt;awk&lt;/li&gt;
&lt;li&gt;find&lt;/li&gt;
&lt;li&gt;rm&lt;/li&gt;
&lt;li&gt;lsof -i&lt;/li&gt;
&lt;li&gt;kill&lt;/li&gt;
&lt;li&gt;ps&lt;/li&gt;
&lt;li&gt;history&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  grep
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;grep&lt;/code&gt; is a command that &lt;strong&gt;searches for a pattern in a file&lt;/strong&gt; and prints the lines that contain that pattern.&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;grep&lt;/span&gt; &lt;span class="s2"&gt;"pattern"&lt;/span&gt; file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command searches for the string "walnut07", which is my username, &lt;br&gt;
in the README.md file under my current directory, and prints the lines that contain the string "walnut07".&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;grep&lt;/span&gt; &lt;span class="s2"&gt;"walnut07"&lt;/span&gt; ./README.md

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;# Kurumi's Blog walnut07.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Strongly recommend using &lt;code&gt;git grep&lt;/code&gt;&lt;/strong&gt; instead of &lt;code&gt;grep&lt;/code&gt; if you are in a git repository. 

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git grep&lt;/code&gt; is a command that searches for a pattern in the &lt;strong&gt;git repository&lt;/strong&gt; that the current directory is in.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;-i&lt;/code&gt; option to ignore case. E.g.: &lt;code&gt;git grep -i "pattern"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;-n&lt;/code&gt; option to print the line number. E.g.: &lt;code&gt;git grep -n "pattern"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  git &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"walnut07"&lt;/span&gt; ./README.md
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; README.md:1:# Kurumi&lt;span class="s1"&gt;'s Blog walnut07.com
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;-v&lt;/code&gt; option to print the lines that do not contain the pattern. &lt;code&gt;git grep -v "pattern"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  git &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"walnut07"&lt;/span&gt; ./README.md
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; README.md:# Kurumi&lt;span class="s1"&gt;'s Blog walnut07.com
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  sed
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;sed&lt;/code&gt; is a command that &lt;strong&gt;filters and transforms text&lt;/strong&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="nb"&gt;sed&lt;/span&gt; &lt;span class="s2"&gt;"command"&lt;/span&gt; file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command replaces the string "walnut07" with "foobar07" in the README.md file under my current directory, and outputs the result.&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;sed&lt;/span&gt; &lt;span class="s2"&gt;"s/walnut07/foobar07/g"&lt;/span&gt; ./README.md
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;# Kurumi's Blog foobar07.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;s&lt;/code&gt; command is used to replace the string. The &lt;code&gt;g&lt;/code&gt; option is used to replace all occurrences of the string.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Note that &lt;code&gt;sed&lt;/code&gt; &lt;strong&gt;does not edit the file in place&lt;/strong&gt;. 

&lt;ul&gt;
&lt;li&gt;If you want to edit the file in place, use &lt;code&gt;-i&lt;/code&gt; and &lt;code&gt;-e&lt;/code&gt; option. E.g.: &lt;code&gt;sed -i -e "s/walnut07/foobar07/g" ./README.md&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;/number&lt;/code&gt; to specify the Nth occurrence of the string. E.g.: &lt;code&gt;sed -i -e "s/walnut07/foobar07/2" ./README.md&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This command replaces the 2nd occurrence of the string "walnut07" with "foobar07" in the README.md file under my current directory, and edit the file.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;&amp;amp;&lt;/code&gt; to refer to the string that is being replaced. E.g.: &lt;code&gt;sed -i -e "s/walnut07/&amp;amp;07/g" ./README.md&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This command replaces the string "walnut07" with "walnut0707" in the README.md file under my current directory, and edit the file.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h2&gt;
  
  
  awk
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;awk&lt;/code&gt; is a command that &lt;strong&gt;filters and transforms text&lt;/strong&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="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'{action}'&lt;/span&gt; file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command prints the 2nd column of the README.md file under my current directory.&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;awk&lt;/span&gt; &lt;span class="s1"&gt;'{print $2}'&lt;/span&gt; ./README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Kurumi&lt;span class="s1"&gt;'s

tech


Built
Next.js
TypeScript
CI/CD
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;BEGIN&lt;/code&gt; and &lt;code&gt;END&lt;/code&gt; to specify the action that is executed at the beginning and the end of the file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'BEGIN {print "Start"} {print $2} END {print "End"}'&lt;/span&gt; ./README.md
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Start
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Kurumi&lt;span class="s1"&gt;'s
  &amp;gt; tech
  &amp;gt; Built
  &amp;gt; Next.js
  &amp;gt; TypeScript
  &amp;gt; CI/CD
  &amp;gt; End
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  find
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;find&lt;/code&gt; is a command that &lt;strong&gt;finds files in a directory hierarchy&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find directory &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"pattern"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command finds all files that have the string "README.md" in their name under the current directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*README.md*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./blog/README.md
./README.md
./README.md-e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;-type&lt;/code&gt; option to specify the type of the file. E.g.: &lt;code&gt;find . -type f&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;f&lt;/code&gt; is used to specify a regular file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;d&lt;/code&gt; is used to specify a directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;find . -type f -name "*README.md*"&lt;/code&gt; finds all files that have the string "README.md" in their name under the current directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;find . -type d -name "*blog*"&lt;/code&gt; finds all directories that have the string "blog" in their name under the current directory.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h2&gt;
  
  
  rm
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;rm&lt;/code&gt; is a command that &lt;strong&gt;removes files&lt;/strong&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="nb"&gt;rm &lt;/span&gt;file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command removes the README.md file under the current directory.&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;rm&lt;/span&gt; ./README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;-r&lt;/code&gt; option if the file is a directory. E.g.: &lt;code&gt;rm -r ./blog&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  lsof -i
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;lsof -i&lt;/code&gt; is a command that &lt;strong&gt;lists open files&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsof &lt;span class="nt"&gt;-i&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    12345 user    3u  IPv4 0x1234567890abcdef      0t0  TCP &lt;span class="k"&gt;*&lt;/span&gt;:3000 &lt;span class="o"&gt;(&lt;/span&gt;LISTEN&lt;span class="o"&gt;)&lt;/span&gt;
loginwindow  123 user   11u  IPv4 0x1234567890abcdef      0t0  TCP &lt;span class="k"&gt;*&lt;/span&gt;:60000 &lt;span class="o"&gt;(&lt;/span&gt;LISTEN&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Add a port number to the command to specify the port. E.g.: &lt;code&gt;lsof -i :3000&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This command lists open files that are using port 3000.&lt;/li&gt;
&lt;li&gt;Result:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;  COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
  node    12345 user    3u  IPv4 0x1234567890abcdef      0t0  TCP &lt;span class="k"&gt;*&lt;/span&gt;:3000 &lt;span class="o"&gt;(&lt;/span&gt;LISTEN&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;-iTCP&lt;/code&gt; or &lt;code&gt;-iUDP&lt;/code&gt; option to specify the protocol. E.g.: &lt;code&gt;lsof -iTCP&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You can also run &lt;code&gt;-iTCP:PORT_NUMBER&lt;/code&gt; or &lt;code&gt;-iUDP:PORT_NUMBER&lt;/code&gt; option to specify the protocol and the port. E.g.: &lt;code&gt;lsof -iTCP:3000&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h2&gt;
  
  
  kill
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;kill&lt;/code&gt; is a command that &lt;strong&gt;sends a signal to a process&lt;/strong&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="nb"&gt;kill&lt;/span&gt; &lt;span class="nt"&gt;-signal&lt;/span&gt; PID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command sends a signal to terminate the process whose process id is 12345.&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;kill&lt;/span&gt; &lt;span class="nt"&gt;-9&lt;/span&gt; 12345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;-9&lt;/code&gt; option to send a signal to the process. E.g.: &lt;code&gt;kill -9 12345&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-9&lt;/code&gt; is used to send a signal to the process to terminate it.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Remember that we can get a process id by using &lt;code&gt;lsof -i&lt;/code&gt; command? Go get a process id and kill it by using &lt;code&gt;kill -9&lt;/code&gt; command!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  cut
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;cut&lt;/code&gt; is a command that &lt;strong&gt;removes sections from each line of files&lt;/strong&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="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"delimiter"&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"field"&lt;/span&gt; file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command prints the 2nd column of the README.md file under my current directory.&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;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; 2 ./README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ps
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ps&lt;/code&gt; is a command that &lt;strong&gt;reports a snapshot of the current processes&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  PID TTY           TIME CMD
12345 ttys000    0:00.00 &lt;span class="nt"&gt;-bash&lt;/span&gt;
12346 ttys000    0:00.00 ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Why is this command useful?

&lt;ul&gt;
&lt;li&gt;This command is useful when you want to know the process id of a process.&lt;/li&gt;
&lt;li&gt;For example, if you want to kill a process, you can use &lt;code&gt;kill -9&lt;/code&gt; command with the process id.&lt;/li&gt;
&lt;li&gt;Also, you can use &lt;code&gt;lsof -i&lt;/code&gt; command to get the process id of a process that is using a specific port.&lt;/li&gt;
&lt;li&gt;Then, you can kill the process by using &lt;code&gt;kill -9&lt;/code&gt; command with the process id.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;-a&lt;/code&gt; option to show processes for all users. E.g.: &lt;code&gt;ps -a&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;-u&lt;/code&gt; option to show processes for a specific user. E.g.: &lt;code&gt;ps -u user&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  history
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;history&lt;/code&gt; is a command that &lt;strong&gt;lists the history of commands&lt;/strong&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="nb"&gt;history&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;This command lists the history of commands in the terminal you are working with.&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;history&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
This is a history of my terminal commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; 1024  lsof &lt;span class="nt"&gt;-i&lt;/span&gt;:3000
 1025  &lt;span class="nb"&gt;kill&lt;/span&gt; &lt;span class="nt"&gt;-9&lt;/span&gt; 70894
 1026  lsof &lt;span class="nt"&gt;-i&lt;/span&gt;:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>cli</category>
      <category>productivity</category>
      <category>terminal</category>
    </item>
    <item>
      <title>What is $PATH and how to use it?</title>
      <dc:creator>Kurumi</dc:creator>
      <pubDate>Wed, 19 Apr 2023 12:10:42 +0000</pubDate>
      <link>https://dev.to/walnut07/what-is-path-and-how-to-use-it-1n2c</link>
      <guid>https://dev.to/walnut07/what-is-path-and-how-to-use-it-1n2c</guid>
      <description>&lt;p&gt;In this article, we will learn about what PATH is and why we need it. &lt;br&gt;
We'll cover PATH first, and then dive into .zshrc/bash_profile to deepen our understanding.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is PATH?
&lt;/h2&gt;

&lt;p&gt;In short, &lt;strong&gt;PATH is a list of directories that your shell searches for executable files.&lt;/strong&gt; &lt;br&gt;
The variable PATH can look like this: /usr/local/bin:/usr/bin:/bin, which represents a list of directories.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ccY8-O4p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://drive.google.com/uc%3Fid%3D1MJIi-OanQPmrZwEVXO0CMGZ4jxCqLs_9" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ccY8-O4p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://drive.google.com/uc%3Fid%3D1MJIi-OanQPmrZwEVXO0CMGZ4jxCqLs_9" alt="Terminal/Shell searching commands in PATH" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, &lt;strong&gt;if you type &lt;code&gt;ls&lt;/code&gt; in your shell, your shell will search for the executable file &lt;code&gt;ls&lt;/code&gt; in the directories listed in PATH.&lt;/strong&gt;&lt;br&gt;
In other words, an executable file for the command &lt;code&gt;ls&lt;/code&gt; is somewhere in the directories listed in PATH. &lt;/p&gt;

&lt;p&gt;I'll guide you through the process of finding the executable file for &lt;code&gt;ls&lt;/code&gt; in PATH.&lt;br&gt;
First of all, let's use the command &lt;code&gt;which&lt;/code&gt; to find out where the executable file for &lt;code&gt;ls&lt;/code&gt; is located.&lt;br&gt;
&lt;code&gt;which&lt;/code&gt; is a command that prints the location of a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;which &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /bin/ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(1) Now we know that the executable file for &lt;code&gt;ls&lt;/code&gt; is located under &lt;code&gt;/bin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, let's check if PATH has &lt;code&gt;/bin&lt;/code&gt; in it. &lt;code&gt;echo&lt;/code&gt; is a command that prints the value of a variable.&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;echo&lt;/span&gt; &lt;span class="nv"&gt;$PATH&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(2) Now we know that &lt;code&gt;/bin&lt;/code&gt; is in PATH in the third position.&lt;br&gt;
 &lt;em&gt;Note that the directories listed in PATH are separated by &lt;code&gt;:&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As you can see, (1) &lt;strong&gt;the command &lt;code&gt;ls&lt;/code&gt; is implemented by a file located under &lt;code&gt;/bin&lt;/code&gt;&lt;/strong&gt; &lt;br&gt;
and (2) &lt;strong&gt;&lt;code&gt;/bin&lt;/code&gt; is in PATH&lt;/strong&gt;. Since shell searches for executable files in the directories listed in PATH, it can find the executable file for &lt;code&gt;ls&lt;/code&gt; in &lt;code&gt;/bin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now you know about PATH and why we need it. Let's move on to the next topic.&lt;/p&gt;
&lt;h2&gt;
  
  
  .zshrc/bash_profile
&lt;/h2&gt;

&lt;p&gt;First things first, &lt;strong&gt;.zshrc and .bash_profile are files that contain commands that will be executed when you open a new shell.&lt;/strong&gt;&lt;br&gt;
Let's open up .zshrc or .bash_profile and see what's inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano ~/.zshrc
&lt;span class="c"&gt;# or&lt;/span&gt;
nano ~/.bash_profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see something 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="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/bin:/usr/bin:/usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that a variable &lt;code&gt;PATH&lt;/code&gt;, a string that has the three directories &lt;code&gt;/bin&lt;/code&gt;, &lt;code&gt;/usr/bin&lt;/code&gt; and &lt;code&gt;/usr/local/bin&lt;/code&gt;, is exported when you open up a new shell.&lt;br&gt;
If you have other directories that you already added to PATH, they will be listed as well. In my case, I have &lt;code&gt;export PATH=$PATH:$HOME/go/bin&lt;/code&gt; underneath.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export&lt;/code&gt; here is a command that ensures that environment variables to be passed to child processes. &lt;br&gt;
Therefore, any child process of the shell that you just opened will have the PATH variable set to the value of the PATH variable declared in .zshrc or .bash_profile.&lt;/p&gt;

&lt;p&gt;This is why your shell knows what's in the variable PATH whenever you use shell.&lt;/p&gt;
&lt;h3&gt;
  
  
  Fun fact
&lt;/h3&gt;

&lt;p&gt;So, .zshrc and .bash_profile are just files that will be executed when you open a new shell.&lt;br&gt;
You can encourage yourself by displaying a message when you open a new shell like this :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2z4_1HTr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://drive.google.com/uc%3Fid%3D1RSKDUu3tShh1SCsKX-fUXWEbhLwT9TB8" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2z4_1HTr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://drive.google.com/uc%3Fid%3D1RSKDUu3tShh1SCsKX-fUXWEbhLwT9TB8" alt='Terminal displaying "AWESOME PROBLEM SOLVER"' width="697" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How did I do this? I just used the &lt;code&gt;echo&lt;/code&gt; that we learned earlier and added it to my .zshrc!&lt;/p&gt;
&lt;h2&gt;
  
  
  A little more about PATH
&lt;/h2&gt;

&lt;p&gt;So far, we have learned that PATH is a list of directories that your shell searches for executable files.&lt;br&gt;
But what if there are same executable files in different directories? For example, what if there is a file named &lt;code&gt;java&lt;/code&gt; in &lt;code&gt;usr/bin&lt;/code&gt; and &lt;code&gt;usr/local/bin&lt;/code&gt;? &lt;br&gt;
Which file will be executed?&lt;/p&gt;

&lt;p&gt;The answer is that the file in the directory that comes first in PATH will be executed.&lt;br&gt;
Let's say you have PATH 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="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$PATH&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /usr/local/bin:/usr/bin:/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the file in &lt;code&gt;/usr/local/bin&lt;/code&gt; will be executed when you type &lt;code&gt;java&lt;/code&gt; in your shell.&lt;br&gt;
This can be problematic when you have an older java version in the first file but want to use a newer version which is in the second file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, we have learned about the importance of the PATH variable and how it is used to search for executable files in directories listed in the PATH.&lt;br&gt;
Additionally, we have discussed that a shell read the first command in PATH when there are multiple executable files with the same name. &lt;br&gt;
Remember that this can cause problems especially when you want to use an updated version of a command. Overall, understanding the concept of PATH is crucial for anyone working with the command line in a Unix-like environment.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>productivity</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
