paint-brush
An Introduction to Linux and Terminal Basicsby@kiransatyaraj
455 reads
455 reads

An Introduction to Linux and Terminal Basics

by Kiran Satya RajJuly 17th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Using Linux saves my time, and makes my day productive. Dual Boot is the best way possible to run Linux alongside Windows. There are almost one thousand distros as of now maybe even more, you can know more at Distrowatch(https://www.org/wiki/Linux_distribution) Here are some widely used distros for the following categories: Server Red Hat Enterprise Linux (RHEL) Enterprise Linux. Desktop Ubuntu (https://://://.ubuntu.com) Android (https:www.android.com/intl/en_in)

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - An Introduction to Linux and Terminal Basics
Kiran Satya Raj HackerNoon profile picture


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 them 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.


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 an 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 on 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



  • Linux is constantly evolving both at the technical, including kernel features, distributions, and interface level.
  • Unlike other OS which is also not Open-Source Software and take several months for an update, 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) 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, 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 have very few features of GUI available in 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 the 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?



  • 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 $ the sign we can start writing the commands.


https://twitter.com/jksrtwt/status/1541774775952896002

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 a 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,



  • 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



  • Let’s 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


which leads to a page about the manual command


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.


  • 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 command, we use type <command-name>


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


  • 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 <command-name --help> it works for all the commands no matter what the type is.


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


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


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 In the end, Ctrl + c to stop the execution of the command


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


  • 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


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


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


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


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


  • 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

  • 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