Introduction to Linux Shells (Bash)

Table of Contents

Introduction to Linux Shells (Bash)

Understand the different Linux shells, with a focus on Bash, and learn how to customize shell environments.

Shells Overview

The following command displays the list of available shells on the system. Each line represents a shell executable.

cat /etc/shells

Current Shell

Displays the path to the current shell. The default shell for the user is typically set in the /etc/passwd file.

echo $SHELL

Switching Between Shells

Entering the name of a shell (e.g., bash, zsh) in the terminal switches to that shell. It is useful for exploring and using different shell environments.

bash # Switch to Bash

zsh # Switch to Zsh

Bash Basics

A simple command in Bash to print “Hello, World!” to the terminal. Bash supports various built-in commands for various tasks.

echo "Hello, World!"

Customizing the Bash Prompt

Customize the Bash prompt to display the user, host, and current directory. The PS1 variable controls the prompt’s appearance.

PS1="\u@\h:\w\$ "

Bash Configuration Files

The following commands represent user-specific Bash configuration file and system-wide Bash configuration file.

~/.bashrc

/etc/bash.bashrc

Environment Variables

The following commands export an environment variable. Environment variables are accessible to child processes and control the behavior of programs.

export MY_VARIABLE="Hello"

echo $MY_VARIABLE

Aliases

The following command creates an alias (ll) for the ls -la command. Aliases simplify and customize command usage.

alias ll="ls -la"

Start your Career with Learn DeOps Free.

Shell Scripts

The following commands opens a script file using nano, makes the script executable with chmod, and executes the script with ./myscript.sh.

nano myscript.sh

chmod +x myscript.sh

./myscript.sh

Bash Completion

The following command installs Bash completion for improved command-line efficiency. Allows for tab completion of commands, filenames, and more.

sudo apt install bash-completion

Exiting the Shell

The following command exits the current shell. It is useful when working with different shells or ending a terminal session.

exit

By diving into system logs and employing various commands and techniques, users can gain valuable insights into system activities, troubleshoot issues effectively, and maintain a proactive approach to system monitoring and management.

We are providing Best DevOps Courses

what you need to know

in your inbox every morning