Linux

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

LINUX

SHELL SCRIPTING
lslisting out files.

ls -ltrall directories and files

touchcreate a file

ls for checking file

vi testto write inside a file (press I for insering & esc :wq! For saving)

vi catto check the file

mkdirfor creating directory

rmfor deleting file

rm -rremove directory

freefor looking into the memory

nproc cpu size

topmanage memory, cpu

SHELL SCRIPTING
touch first-shell-script.sh  to create file

ls  list out files or folders first-shell-script.sh


ls - list directory contents

ls-ltr  it will show when file is created


total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Jan 28 07:30 first-shell-script.sh

#!/  shebang
#!/bin/ksh
Bash/sh/dashdifferent executables of linux
Commonly used is bash

#!/bin/sh & #!/bin/bash  earlier both are same now a days we are using bin/bash

#!/bin/bash

Echo “my name is rahul”  for printing name

:wq! for saving file

:q!  for quit

cat  to print the contents of the file

cat first-shell-script.sh #!/bin/bash  without opening it will display my name is rahul

sh or ./ for executing file


sh first-shell-script.sh  permission denied

chmod ch change mod mode


divided into 3 groups 1. Which user 2. Which group 3. What permission you
have
1-execute, 2-write, 4- read, 7- 1+2+4

chmod 777  permissions for all

sh or ./ for executing file

sh first-shell-script.sh  my name is rahul

history  to check what all commands we have used

pwd  current working directory

mkdir  Create a directory /make directory

Rmdir Remove an empty directory

Cd  change directory
vim or touch #!/bin/bash

#  for writing comments, this is not executable


# create a folder
mkdir rahul
# create two files
touch firstfile secondfile
:wq!
Chmod 777
df displays the available storage space

free check for memory RAM on your system

nproc prints the number of processing units available to the system or to the
current process.

Top  provides a lot of information about the processes that are currently running on
the system. This information can be very helpful for identifying any processes that
are using excessive resources and need to be terminated.

Custom Shell script to detect node health, providing metadata information

vim nodeHealth.sh 
INSERT
#!/bin/bash

#############  used to create comment


# Author:Rahul
# Date 28th Jan’24
# Sunday
# This script outputs the node health
# Version V1

########### 

df -h  for printing disk space

free -g  for printing the memory

nproc  prints the number of processing units available to the current process
:wq!
Chmod 777 nodeHealth.sh

./ nodeHealth.sh it displays the below, but we this we are unable to know exact
details, so we use

vim nodeHealth.sh  edit by adding echo


echo “Print the disk space”

df -h  for printing disk space


echo “Print the memory”

free -g  for printing the memory


echo “Print the CPU”

nproc  prints the number of processing units available to the current process
:wq!
Chmod 777 nodeHealth.sh
vim nodeHealth.sh  if there are huge we need to use below, generally devops engineer
uses below
set -x # debug mode

df -h  for printing disk space

free -g  for printing the memory

nproc  prints the number of processing units available to the current process
:wq!

Command for printing all processers in Virtual Machines

To find this we use the below


ps  processers

ps -ef a powerful tool that allows you to view information about the processes
running on your Linux system

ps -ef |grep “amazon”  command is used to list all running processes on a Linux
system and filter the output by a specific process name. The ps command stands for
"process status" and the ef option tells the command to display information about all
processes in a full format. The grep command is used to search for a specific pattern
in the output of the ps command.

| pipe parameter integrates and sends the output of the first one to the second one
Echo 1
Echo 11
Echo 12
Echo 55
Echo 90
:wq!
Chmod 777 test.sh
./ test.sh
Vim test.sh | grep 1

You might also like