DEV Community

Prasanth
Prasanth

Posted on

2

The command Line

Reference
1.Book: Linux Administration A Beginner's Guide

*Author * : Wale Soyinka

Bash:-

The login shell is a first program runs when user log into a system. Shell is command language interpreter, shell read and process command execute the user types ,it allow to the user interact with operating system by executing command. Bash(Bourn Again Shell) is improved version of shell , shell used to old linux system, now Bash is used to modern distro .Bash is command line only interface ,it does not have GUi only text-based interaction(CLI),contain built-in commands like cd, echo(print text),bash can lanuch programs and manage running process.
.
Job control:-

when you working in the bash environment, you can start multiple program simultaneously at same prompt . each program consider a job ,by default when run a program, it take over the control terminal, can not type other program until the current program job done. some program require full terminal control to display colored text and fromating for example text editor,now see graphical programs do not need full control the terminal, it just run the background.

example:-

$ firefox ( take over the control terminal)
or
$ firefox & ( run the background keep using terminal)
or
$firefox & gedit & vlc & (multiple program)
$jobs

output show the running

Image description

  • ctr + z pass the current running process
  • ctr + c stop the process (later we will see kill, pkill , killall)

syntax:-

fg job of the firefox number

example:-
$firefox &
$jobs
$ fg 1
fg is bring it to the foreground the job.

bg -background the process

example:-

$sleep 100 (you tell the system
pause 100 second, do nothing)
ctr + z (pause the process sleep)
$bg (resume the last process in the process background)
(bg %jobid = resume particular job in the background, if multiple job running background)
$jobs
$fg (bg jobs bring it to the foreground the job)

Image description

Environment Variables:-

  • Every time you open a new terminal (shell) or run a program (process) in Linux, the system loads environment variables like $HOME, $USER, and $PATH. Each shell session or running process has its own set of settings that control how it behaves. These settings are stored in environment variables, which can be modified to customize the system without changing the original program code.

  • Environment variables in Linux are stored as key-value pairs(VARIABLE=value), either globally or locally. They hold values like file paths, system configurations, and application settings (for example, configuring software behavior). Environment variables can be temporary (session-based) or permanent (saved across reboots).

Practicles:

  1. view all environment varibale $ printenv or $ env

2.set a temporary varibale for current session only

bash:-
$export MY_VAR="Hellow_Linux" (globally set env variable)
$echo $MY_VAR
(varibale set only capital)

3.Remove a temp variable
unset MY_VAR

4.set permeant variable
edit ~/.bashrc or ~/.bash_profile(for bash user only)
$ vim ~/.bashrc
press i for insert mode
Add:-
export MY_VAR="Hellow_Linux"
double tap Esc
then
:wq(save and quite)
then
source ~/.bashrc (apply the changes)

or

echo 'export MY_VAR="Permanent Value"' >> ~/.bashrc
source ~/.bashrc > Apply changes

5.Application configuration

export DB_URL="jdbc:postgresql://localhost:5432/mydatabase"
echo $DB_URL
result:-
jdbc:postgresql://localhost:5432/mydatabase

6.storing Api key securely
set port API_KEY="abcde-123456-fghijk"

7.Setting Language
export LANG="en_US.UTF-8"
echo $LANG
result: en_US.UTF-8

8.simple scripting ,temporarily environment variable:-

Image description

bash:-

mkdir -p ~/scripts

make the directory in scripts(dir name) in side of HOME(~)
-p parent

echo -e '#!/bin/bash\necho "welcome to MY Linux blog"' > ~/scripts/myscript.sh

echo -e = print the text in terminal -e enable escape sequence & \n new line.

!/bin/bash = shebang operator ,tell the system to runt eh script using BASH.
=> > = redirect
~/scripts/myscript.sh = script file location

  1. Commonly used Environment variable:- $PATH = specifies directories executable file $HOME = user home directory $SHELL = default shell $USER = current logged in user $LANG = Language setting $PWD = current working directory $HOSTNAME = Machine hostname

example: $echo $HOME

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Please show some love ❤️ or share a kind word in the comments if you found this useful!

Got it!