Let's Learn Linux: An Intro and Terminal Basics

Let's Learn Linux: An Intro and Terminal Basics

Linux Fundamentals

Backstory

As I was getting involved with technologies and knowing more about what our machines run and how effectively we can complete our tasks using better technologies which in our case is using a better OS that runs Linux

  • Well, how did I know it was better, I wasn't even using it back then, that's where the tech communities help us in guiding our way through the hurdles, contribute to our life and make it better.
  • In my case using my PC with optimal performance saves my time, and makes my day productive.
  • Then came the help, "Hey buddy, in that case, you should try using Linux and see if it helps you in any way to make your day better also learning how it works have its perks." that is how I got started.

SETTING UP THE ENVIRONMENT TO RUN LINUX

Before I started learning about Linux, I started setting up the environment for my PC to get it Linux-based.

  • Install Linux on Windows with WSL2 or Using a Virtual Box

  • Running Linux alongside Windows i.e Dual Boot

    For to use it as a Primary OS, I found Dual Booting much better than the first two methods, considering all the suggestions/advice on Linux, I was in to use Linux at its best and found dual boot is the best way possible.

  • It just took more time and patience, reading the documentation carefully, following the instructions and I was good to go, It was completely worth it since I wanted the best experience of using Linux.

  • But it's not all Pros, the dual booting method has its Cons too, and the process has its Risks.

Choosing the distribution for Linux

  • Here I didn't take much time on selecting a distro a.k.a distribution to run Linux.

  • Here are some widely used distros for the following categories:

Server

Desktop

Embedded

  • Yocto isn't embedded Linux distro, what it does is that it provides the necessary tools, templates, and methods to help us to create a custom Linux-based system for embedded system deployments in connected servers, virtual environments, etc. for any type of /regardless of hardware architecture.
  • OpenEmbedded
  • Android

These are not the only distros just the widely used ones, there are almost one thousand distros as of now maybe even more, you can know more at Distrowatch.

  • I fall into the desktop category so I took the obvious choice i.e Ubuntu, also because I preferred the modern and standard desktop interface.

Do you know the actual extent one can go with Linux, is building their distribution, for a person who is at a master-level of System Administration of Linux and uses a distro like Gentoo is quite the challenge they would look up to. It's possible, we need to put on a lot of work for it and we will.

  • As of now that's all for the setup part.

Then enters the switch par from Windows to Linux for dual-booted systems, it was quite simple I must say and that's it for setting up Linux in your PC.

That's Good, but I want to know more about Linux.

What is Linux and Why use it?

  • Firstly, I've found that what I now use isn't just Linux it's GNU/Linux, yes it is. But why, isn't Linux an OS? Well, It is, as GNU/Linux and it is core which as a kernel is Linux just as it is.

  • So Linux is a free OS Kernel it's a key component for an OS and in here which is GNU The OS, our system which we say Linux-based is GNU/Linux System

  • Even our system agrees with it, to know that open your terminal Ctrl + Alt + t and type the command: uname -a , you should get the output similar to this

Screenshot from 2022-06-11 12-03-44.png

  • Linux is constantly evolving both at the technical, including kernel features, distributions, and interface level.

  • Unlike other OS's which are also not an Open-Source Software and take several months for an update, and it's frustrating if it has bugs. We have battled with slowdowns, crashes, malware, and viruses until the next update is released.

GNU/Linux OS consists of:

Some common terminologies to know before we enter:

  • Kernel: It is considered the brain of the GNU/Linux operating system. It controls the hardware and makes the hardware interacts with the applications know more at Kernel. org

  • Distribution a.k.a Distro: It's a collection of programs combined with the Linux kernel and package management system to make up a Linux-based operating system. Ex: RHEL, SUSE, Ubuntu, Fedora, etc. They are variants of GNU/Linux OS. Each has a different approach to a Desktop, I just had to pick one which matches my needs.

  • A Linux OS has GNU Shell utilities, Linux kernel, graphical desktop environment, and more

  • Boot Loader: A program that boots the operating system, let's get that even more clear when we power on our PC/laptop, a basic standard check is done a.k.a Power On Self Test(POST) like did you ever see a speedometer of a vehicle, technology is being used in it

  • When you put the key in and turn on the ignition mode what you see is that it flashes the numbers, the meter raises or the needle rotates fully and gets back to its default speed, what happened in there was a system check, this is an example since embedded systems are used in them and what powers them is Linux
  • When we power on the BIOS which is the ROM(read-only memory) chip that consists of all the set instructions that are needed to do the system check before we run the programs
  • After that when the computer starts up the first it read was bootloader and it points to the program which is going to run next
  • It's like when you are bootstrapping yourself the first thing you do is to tug your lace-up, so just awake enough to get the OS started. It is also the earliest process to happen in the Boot Process
  • Command-Line Interface a.k.a CLI: Well, it's one of the first few thoughts that comes into my mind when I hear or say Linux.
  • Now an OS kernel is wrapped with a shell, in order to perform tasks by accessing the kernel we need commands to pass through the shell or more like an orb that needs commands to penetrate through to get control of what's inside and show us the effect of it, so it is the shell that interprets the commands and instructs them to the OS, some shell examples are bash which is widely used, bourne, Korn and z shell
  • Terminal: Now the terminal is where we access the OS kernel to perform tasks, this is the command-line interface that I was talking about, it is the arena to use our weapons well in technical terms it is where we access the system through a shell using commands in this environment. Let's start using them.

Opening the Terminal

  1. Press the Windows key and the search pops up, type "terminal"
  2. OR right-click on the desktop home page and click the open terminal option
  3. OR use ctrl + alt + t

Point to remember: Linux commands are case sensitive

  • A terminal is a text-based environment but since we use this in an OS, we get a GUI a.k.a Graphical User-Interface some of them actually have very few features of GUI are available the terminal we now use.

  • But a Console is the environment, which in our case a console in our Linux-based system is a pure text-based environment with no scope for GUI, you can access it with Ctrl + alt + F1 if we want to open-up/access multiple consoles we can do it with Ctrl + Alt + F1-F8 like 1-8 is number for the console, depending on which you want to open it.

  • If you're going to try it, type the exit command to exit from the console, wait for a few seconds, and you'll be back to your system login page.

  • Let's get back to the terminal

What does this mean?

Screenshot from 2022-07-16 15-39-30.png

  • Here's kiransatyaraj is the username name and after the @ which is jksrtwt is the hostname
  • A Linux-based system can have multiple users for the same host and you can also change the hostname

  • The terminal emulator which I'm using is Terminator, you can install it using the command: sudo apt update && sudo apt install terminator

  • After the semicolon, the ~ characters represent the user's home directory, what lies in that position is the file path, after the $ sign we can start writing the commands

Screenshot from 2022-07-16 17-19-08.png

Basic Commands

  • cd - change directory, ls - list, pwd - present working directory, / - root directory, ~ - home directory
  • As you see in the image the output of pwd is a path /home/kiransatyaraj/ which means that starting from /- root directory inside that we have a home directory inside that we have user directory of name kiransatyaraj
  • ls - list which lists all the directories of the current directory you are in.
  • echo Hello, World! is the bash way to print hello world into the console here echo is the command name, and "Hello, World!" is the argument
  • using just cd gets you back to the user's home directory and you can change the directory that you want to work with using cd <filepath> of the directory like cd Documents/
  • cd - to change back to the previous directory, cd .. to change back to the parent directory,

Screenshot from 2022-07-16 17-54-31.png

  • We use flags to get detailed specifications, ls -a - lists all the files also the hidden files because any file that starts with a dot (.) is hidden
  • Flags are like options for a given command for the specification we like to see, we use -- double hyphens for the word flags and - single hyphen for the character flags

  • We can also group the - character flags and can provide arguments which in this case hello/ is the argument and we are in the parent/user's home directory

Screenshot from 2022-07-16 18-00-36.png

Screenshot from 2022-07-16 18-53-41.png

  • Lets clear the clutter using the clear command, which clears the page for you, and Ctrl + l is used to expand the browser until you can use it from the top

Man page

  • Now how do we get to know the option available for a command, that is possible with the man command, now what is man, let's ask about man using man man

Screenshot from 2022-07-16 21-55-09.png which leads to a page about the manual command

Screenshot from 2022-07-16 21-55-30.png you can get additional typing h when you're on the manual page, to quit from it just typing q twice will do the job.

Screenshot from 2022-07-16 22-00-13.png

  • While you are reading the documentation you can scroll through the page using arrow keys but if you want to scroll down as one window Ctrl + f or space will help you and for scrolling up one window at a time Ctrl + b and to get to the very beginning of the page type g and to the very end of the page G, to search for a specific keyword type / while you're on the manual page and type the word or a letter and press enter, the matches in the current will be highlighted

  • To navigate through the page of the keyword you searched for on the manual page press n to get to the next match and N or Shift + n for the previous match

  • Using / the search starts from the beginning of the page, to search from the end of the manual page and you know the drill what to do next

  • Commands are two types, some are executable files, they have a file path in the system and manual and some are builtin commands they do not have a manual like cd, alias, and more

  • To know the type of a command, we use type <command-name>

Screenshot from 2022-07-16 22-39-05.png

  • To get the documentation of such builtin shell commands, we use help <command-name>

Screenshot from 2022-07-16 22-40-40.png

  • help does not work on the executable file commands like try help ls it won't work, help is only for shell builtin commands but we have a hack, use ` it works for all the commands no matter what the type is.

Screenshot from 2022-07-16 22-55-35.png

  • man -k <command-name> or apropos <command-name> to find the command, feature, keyword

Screenshot from 2022-07-16 23-12-55.png

TAB key

  • Use the TAB key for auto-completion of a command, folder, or a directory
  • Type the first few letters of the command you want to execute and press the TAB key, if there's a single match the command will be auto-completed, if not press the key twice to see all the matches for the first few letters of that command

Screenshot from 2022-07-17 09-46-55.png

Terminal Shortcut keys

  • Navigating through all the commands you ran before using the up and down arrow keys and press enter to run them
  • exit or Ctrl + d to exit the bash shell/close the terminal, Ctrl + u to remove the current line, Ctrl + a to move the cursor to the start of the line, and Ctrl + e to the end, Ctrl + c to stop the executing the command

Screenshot from 2022-07-17 10-07-15.png

BASH History

  • cat .bash_history stores the history of all the commands as a directory in the user's home directory, echo $HISTFILESIZE to know how many commands the systems stores in it which is 2000

Screenshot from 2022-07-17 11-56-38.png

  • history to print out the entire history of all the commands you ran, echo $HISTSIZE controls how many commands from your bash history will be stored in the memory

  • history shows the current history of the commands but the user's bash history files are updated when the user is logged out Before logging out

Screenshot from 2022-07-17 12-23-34.png

  • It's updated after logging in, for printing out the user's command history files use cat .bash_history

Screenshot from 2022-07-17 12-26-31.png

  • Commands are numbered when we print out the history using history, so in order to run a certain command of number we use !<number from history's command-line>, take a look at the picture below

Screenshot from 2022-07-17 12-30-27.png

  • To re-run the previous command use !! and to run the last nth command from the history use !-n

Screenshot from 2022-07-17 12-34-56.png

Screenshot from 2022-07-17 12-40-08.png

  • Running the last command that starts with "XYZ" use !XYZ and for printing that command !XYZ:p

Screenshot from 2022-07-17 12-48-35.png

  • To search the commands from the history use Ctrl + r and start typing, if you found the command press enter, or if you want to exit and clear the line press Ctrl + G

Screenshot from 2022-07-17 12-53-05.png

  • To delete a command line from the history use history -d <line_number> and to erase the whole history use history -c

  • To run commands without leaving a trace is to use space before typing a command and check the history if the command you ran is not in the history then you’re good

  • If it does not work then use $HISTCONTROL=ignoreboth it works only for the current session to save the changes using echo “HISTCONTROL=ignoreboth" >> .bashrc

Thank You so much, you made it till the end, and giving your time means a lot to me, I hope you found this blog helpful and we'll meet again with another blog on "Linux File System" starting with root access, why wait till the next blog you can connect with me on Twitter

YOU ARE AWESOME!! HAVE A GREAT DAY BUDDY

Did you find this article valuable?

Support WeMakeDevs by becoming a sponsor. Any amount is appreciated!