Skip to content

Linux Shell Scripting

Linux Shell Scripting

Shebang

#!/bin/bash

Running a script

bash filename.sh

or 

chmod +x filename.sh

Delimeter in shell scripting

command 1; command2;

Printing in the terminal.

echo "hello world"
printf "hello world"

Assigning a value to a variable

var=value

Printing value to the terminal

echo ${var}

Setting an environment variable

export APP_PORT=9222

Identifying the current shell

echo $SHELL

Displaying processes.

ps

Displaying processes ( all columns )

ps -f

Displaying top memory consuming processes.

top

Finding the location of the command :

which command_name

Finding file type :

file file_name

Finding the meaning of the command :

whatis ls

Printing the hostname of the current system.

hostname
uname -a

Printing cpu info : ;

cat /proc/cpuinfo

Printing ram details :

cat /proc/meminfo