<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bash Tricks on Benjamin Italiaander</title><link>https://tlnd.org/Linux/bash_tricks/</link><description>Recent content in Bash Tricks on Benjamin Italiaander</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 27 Feb 2023 14:12:45 +0100</lastBuildDate><atom:link href="https://tlnd.org/Linux/bash_tricks/index.xml" rel="self" type="application/rss+xml"/><item><title>Date command in bash</title><link>https://tlnd.org/Linux/bash_tricks/date_command/</link><pubDate>Mon, 27 Feb 2023 14:12:45 +0100</pubDate><guid>https://tlnd.org/Linux/bash_tricks/date_command/</guid><description>&lt;h1 id="a-few-small-examples-of-the-date-command"&gt;A few small examples of the date command&lt;/h1&gt;
&lt;p&gt;Show the day of the week as a number (1 = Monday), which is always handy to know:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;date +%u
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Show the quarter of the year:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;date +%q
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In a script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;todayWeekday&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;date +%u&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;todayQuarter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;date +%q&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Today is weekday &lt;/span&gt;&lt;span class="nv"&gt;$todayWeekday&lt;/span&gt;&lt;span class="s2"&gt;, in quarter &lt;/span&gt;&lt;span class="nv"&gt;$todayQuarter&lt;/span&gt;&lt;span class="s2"&gt; of the year.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Count logged-in users</title><link>https://tlnd.org/Linux/bash_tricks/display_number_of_loggedin_users/</link><pubDate>Fri, 01 Jan 2021 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/bash_tricks/display_number_of_loggedin_users/</guid><description>&lt;h1 id="display-the-number-of-logged-in-users-with-the-who-command"&gt;Display the number of logged-in users with the who command&lt;/h1&gt;
&lt;p&gt;Keeping track of the number of users logged into a system can be very useful. This short Bash command shows the exact number of active users:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;who -q &lt;span class="p"&gt;|&lt;/span&gt; grep &lt;span class="s2"&gt;&amp;#34;users=&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; sed &lt;span class="s1"&gt;&amp;#39;s/# users=//g&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For a continuous, real-time update of the user count, run it with &lt;code&gt;watch&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;watch &lt;span class="s2"&gt;&amp;#34;who -q | grep &amp;#39;users=&amp;#39; | sed &amp;#39;s/# users=//g&amp;#39;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Allow a User to Access Serial (TTY) Devices</title><link>https://tlnd.org/Linux/bash_tricks/allow_tty/</link><pubDate>Mon, 14 Nov 2016 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/bash_tricks/allow_tty/</guid><description>&lt;h1 id="allow-a-user-to-access-serial-tty-devices"&gt;Allow a user to access serial (TTY) devices&lt;/h1&gt;
&lt;p&gt;On Ubuntu, create the user and add them to the &lt;code&gt;dialout&lt;/code&gt; group. &lt;code&gt;dialout&lt;/code&gt; normally grants access to serial devices such as &lt;code&gt;/dev/ttyUSB0&lt;/code&gt;, &lt;code&gt;/dev/ttyACM0&lt;/code&gt; and &lt;code&gt;/dev/ttyS0&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Create the user&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo adduser username
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Allow access to serial/TTY devices&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo usermod -aG dialout username
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Check:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;groups username
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You should see something like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;username : username dialout
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The user needs to &lt;strong&gt;log out and back in&lt;/strong&gt; before the new group membership takes effect.&lt;/p&gt;</description></item></channel></rss>