Let's Learn Linux!: Bash Magic! - Issue #5 - GaiaYoga Gardens, Lower Puna, Far East Big Island, Hawai'i - Saturday, March 18, 2023

avatar

Polish_20220714_121452303.jpg

Polish_20220714_121631044.jpg

Polish_20230217_163432316.png

Polish_20220714_121631044.jpg

Warm greetings fellow Linux-and-FOSS lovers! πŸ˜πŸ™πŸ’šβœ¨πŸ€™

To begin this week's Let's Learn Linux! I want give the great news that I ordered my new laptop today! It took me quite some time to find a good suitable laptop that actually met my needs and was what I really wanted. It's not completely ideal, but it's still pretty bloody amazing! I'll describe it when I receive it, somewhere between April 15th and the 18th. I feel so much relief in finally getting it ordered! Finding a laptop that fits me was grueling!

Polish_20220714_121754649.jpg

Now on to this week's topic: Bash Magic! Bash is both a UNIX shell and a command language, or a command interpreter. Along with the GCC compiler it was one of the very first applications to be ported over to Linux from UNIX. Bash stand for Bourne Again Shell, which is a play on words of the shell from with it originated. Bash is the default shell of the vast majority of Linux distributions, though, as with most things in Linux, there are a wide array of other possible shells from which one may choose. The means of interacting with Bash is most often via a graphical terminal application, though if there is no graphical user interface, then we would be working exclusively via a non-graphical command line.

Polish_20220714_121631044.jpg

This is the terminal application Konsole, the default terminal for the KDE Plasma desktop environment. When we interact with Bash, or any other shell, it will usually (though not always) be via some version of terminal application. Like everything else in Linux, there are many terminal applications from which to choose! I love pretty things, so I always choose terminals that have transparency!
Screenshot_20230318_202424.png

Polish_20220714_121631044.jpg

Every single thing that can be done using a graphical user interface (GUI) can be done solely from the command line, along with lots of other cool things that usually can't be done using a GUI.

Polish_20220714_121754649.jpg

When you first open a terminal application to run Bash commands, the command prompt where you will be entering commands will like what you see below.

Polish_20220714_121631044.jpg

This is how it looks for a regular (non-root) user account, in this case mine. The first thing you see is the name of the user account that is logged in, then after the @ symbol, you have the hostname of the computer (this is how the computer will appear on a network). The next thing you'll see is the PWD, or present working directory. With regular accounts, that will be in the user's home directory. This can be changed, of course. You know that the prompt is non-root when you see the $ symbol. 

[tydynrain@Integral-Evolutionary-Nexus-3 ~]$

If you elevate privileges using sudo or sudo su, then the prompt will change to a root prompt. You'll notice the root user in the far left, followed again by the computers hostname, and then the name of the account that has elevated privileges and is operating as root. You'll also notice that the $ symbol has changed to a # symbol, to designate a root prompt. 

[root@Integral-Evolutionary-Nexus-3 tydynrain]#

Polish_20220714_121631044.jpg

To give you an idea of some simple commands that can be run in a terminal using Bash, I'll give a few examples below.

Polish_20220714_121631044.jpg

In Arch Linux to check the repositories for updated software, download, and install it, you run the following command, which invokes pacman (PACkage MANager), the Arch package manager. Every Linux distribution will have its own command for this, though since many distributions share a common source distribution, their update commands will likewise be similar. 

pacman -Syu

To install software... 

pacman -S <package name>

Polish_20220714_121631044.jpg

An entire post (or several!) could be written on all the various commands that can be used with pacman, so I'll stop with these two for the moment. Let's look at a few other examples before moving into some cool things that can be done with commands.

Polish_20220714_121631044.jpg

If you're unsure of the directory in which you're operating, just type the following...

pwd

To chage directories...

cd <directory/where/you/want/to/go>

To go back one directory... 

cd .. 

Polish_20220714_121631044.jpg

Commands can be strung together using &&, so to change directories and the list the contents, you type the following.

Polish_20220714_121631044.jpg

cd <directory/where/you/want/to/go> && ls

Polish_20220714_121631044.jpg

Now I'd like to explain some of the very cool things which can be done with Bash. Each user account will have a Bash configuration file in its individual home directory. There is also another one in the root home directory, /root. These files are called .bashrc. Because commands and strings of commands can often be quite long, aliases can be added to these files, so that you can run often executed commands with simple commands of your choosing. Let's look at a few examples from my own system.

Polish_20220714_121631044.jpg

To elevate to a root prompt... 
alias s='sudo su'

So instead of tying sudo su, all I need to type is s. 

To update my my GRUB boot menu... 
alias ug='grub-mkconfig -o /boot/grub/grub.cfg'

To display the present I/O (input/output) scheduler... 
alias sched='cat /sys/block/sda/queue/scheduler'

To display the present CPU governor... 
alias gov='cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'

To display how long I've been on Hive using the pdd application... 
alias hive='pdd 2021 Sep 23'

To display how old this Arch installation is (date taken from the pacman.log file... 
alias age='pdd 2018 Jan 17'

Polish_20220714_121631044.jpg

The command that you choose must be contiguous, so no spaces, though hyphens can be used. The original command for which you're creating the alias is inside single quotes, because there are usually spaces in the command.

Polish_20220714_121754649.jpg

Bash aliases can also be strung together as well, just like applications, which make things even more interesting.

Polish_20220714_121631044.jpg

alias schedgov='cat /sys/block/sda/queue/scheduler && cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'

The text and ASCII image in the screenshot above comes from this alias....
alias os='clear && neofetch && age && schedgov'

Polish_20220714_121631044.jpg

Bash commands, or strings of commands, can be executed via a script as well. A script is an executable text file, so basically like a simple program. All Bash scripts are designated with #!/bin/bash at the top left of the script. The script must also be made executable to be able to be run. Scripts like can be run manually as needed, added to a cron job to be run periodically, or even run when the computer is booted up or shut down. They are very flexible and useful tools!

Polish_20220714_121754649.jpg

OK, I think that's a good place to end this installment of Let's Learn Linux!, as it gives y'all a good bit on which to chew! I hope that I've explained this in a reasonably clear and understandable way, and that it was interesting, engaging, and maybe even inspiring and exciting! Until next week! 😁 πŸ™ πŸ’š ✨ πŸ€™

Polish_20220714_121754649.jpg

All images were taken with my Motorola G Power Android Phone or are screen shots from my laptop.

Polish_20220714_121551463.jpg

Thank you all so much who have helped me get to where I am today, and allowing me to share more of the beauty and magic from my life and my world with you, and for your continuous appreciation and support! I am truly deeply grateful! πŸ˜πŸ™πŸ’šβœ¨πŸ€™

Polish_20220714_121551463.jpg

If you'd like to find me on other alternative platforms where I have accounts (I spend most of my time here on Hive), click on this signature image below to go to my LinkTree page.

Polish_20220714_123613996.png

If you'd like to send me a BTC Lighting Tip (made possible by the fantastic work of brianoflondon on @v4vapp), just scan the QR image below. πŸ‘‡

tydynrain.png

Sources
Signature image created by @doze, and the dividers made by @thepeakstudio, with all tweaked to their present form by me.

Banner image created by me using Polish, with the Arch Linux logo converted into ASCII art, and Tux the Linux Peguin created by Larry Ewing.

Polish_20220714_121452303.jpg



0
0
0.000
3 comments