CompTIA Linux+ (XK0-004)
Red Hat Enterprise Linux
Git and Github
Learn Docker and Kubernates
Tips and Tricks

1. Working with the Shell

Let's familiarize ourselves with the shell.

The Shell

Remember:

  • The terminal is a program that takes the command as input and hands it off to the shell.

  • The shell is a program that creates an interface through which we can interact with the system kernel.

Useful terminal shortcuts:

ctrl + u -> clear the line
ctrl + l -> clean it off
ctrl + shift + t -> starts a new terminal
ctrl + shift + n -> opens up a seperate terminal
ctrl + shift + -> increases font size in the terminal
ctrl - -> decreases font size in the terminal

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

There are many shell environments available in Linux. You can check all the available shells in your system by issuing cat /etc/shells. You can install new shells as per your requirements.

[email protected]:~$ cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/bin/zsh
/usr/bin/zsh

If you want to run a particular shell, simply type in the name of the shell, just like so:

And, it will put you in the zsh shell. To pop back out of the shell, just type bash in the terminal.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

There are many times when we want to go back to the traditional terminal apart from the ones we have been provided with the GUI system, usually the Gnome terminal. The tty command prints the name of the terminal you're using in the GUI environment. TTY stands for “teletypewriter.”

/dev/pts/0

The traditional terminals are also called 'sudo' terminals in Linux terms. And, you can start it from the GUI using ctrl + alt + F2 OR ctrl + alt + F3. The key combinations differ from system to system sometimes. That said, this is the place you will be spending as you become a system admin.

Remember, in a traditional terminal, there is no scrollbar. But you can press shift + page up and shift + page down to go up and down.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Elevating Privilege

su - switch user that lets you switch to other accounts if you hold their password. For example, su - bob will ask for bob's password to login in. If you are root, then it doesn't ask for any password.

su - or su -l It now asks for the root's password to log in. Once logged in, you stay as root as long as you do not exist. This is an old method and often not very good to use the system as a root user. So the latest and greatest alternative option is sudo.

The difference is su is shell-oriented. Once you do su you are in a new shell and now you can do whatever you want to do if you have that privilege.

sudo is command-oriented. You don't switch to a new account. You just stay who you are, just your privilege to run the command gets escalated. sudo visudo is the file where you give or remove the permission.

sudo's password gets saved for about 5 minutes but you can change the duration here sudo sudo -v. And, if you want to wipe out the sudo information as cache, sudo -k

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Useful commands:

  • whoami tells you who you have logged in as. Usually, helpful in terminal environements where they are lots of users.

  • who tells you who other users are logged in currently.

  • w command gives you even more information about users' time, user name, and what the users are doing.

output of 'w' command
  • ifconfig gives you the IP address related information.

  • ip addr also gives you almost the same info.

  • uname -a gives you a lot of information - OS, domain name, kernel version, time, and a lot of other info.

  • history command gives you the history of 1000 commands that you have run by default. You can re-run one of those commands using the exclamation sign before the number.

Repeat the history:-)
  • ctrl+r is the way you can search through the history with the specified characters.

  • poweroff or halt or init 0 or shutdown -h now all of these commands do just one thing - they shutdown the system immediately.

  • shutdown -h +time-in-minute "message" is a scheduled shutdown. And, this message is passed to the every user that is currently logged in.

  • reboot or init 6 - restart the system.

  • If you are wondering why this 6 for reboot. Read about runlevel.

    • 0 – is described as Halt. your machine will halt when the runlevel is set to 0.

    • 1 – is single-user Mode which is used for administrative tasks before the non-essential services are started.

    • 2 – is the first multi-user mode runlevel and will start some non-essential services. This may, or may not contain networking depending on your Linux distribution.

    • 3 – is a multi-user mode which headless servers usually run at. All essential and non-essential services such as Apache HTTP Server should be running.

    • 4 – unused

    • 5 – is when GUI desktops are loaded such as Gnome or KDE.

    • 6 – is the reboot runlevel. The operating system will reboot when runlevel 6 is issued.