0% found this document useful (0 votes)
96 views

System Commands PDF

A hypervisor is software that allows multiple operating systems to run simultaneously by sharing the host machine's resources. It provides commands to navigate the filesystem hierarchy, view and manage running processes, and get information about the operating system, memory, and hardware. Shell variables store intermediate values and enable communication between processes. Process control commands allow managing jobs running in the foreground and background.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

System Commands PDF

A hypervisor is software that allows multiple operating systems to run simultaneously by sharing the host machine's resources. It provides commands to navigate the filesystem hierarchy, view and manage running processes, and get information about the operating system, memory, and hardware. Shell variables store intermediate values and enable communication between processes. Process control commands allow managing jobs running in the foreground and background.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

WEEK 1

A hypervisor is a software that creates and runs virtual machines. It can run multiple
operating systems simultaneously by sharing the resources of the host machine.

pwd - present working directory


ls - list the names of all the files/folders in the current directory
ps - processes that are running
uname - current os
clear or ctrl l - to clear the screen
exit or ctrl d - to exit the terminal
ls -a - list hidden/all files
ls -l - list files in long format
ls -la - list all files in long format

Filesystem hierarchy standard (FHS 3.0)


- To identify the right location of a library file required for some compilation
- Provides the ability to traverse through the filesystem hierarchy
cd -(without any argument) takes us to the home directory
boot directory - Linux kernel is located in this directory
In the long format:-
l means symbolic link of th folder
d means directory
c means character file
b means block files (usually 1kb)

cd .. - parent directory
cd - - previous directory
cd ~ - home directory ( same as cd )
date -R - date and time in rfc 5322 standard ( used in email communications)
man date - manual/ help page of date command
press q - to exit the help page
cal - to get the calendar
ncal - calendar in different orientation
free - memory available
free -h - memory available in human readable format
groups - groups that current user belongs to
mkdir - to make a directory
To give or remove permissions(read, write or execute) for group, user or others:-
chmod (u or g or o)(+ or - )(r or w or x ) folder name
OR
chmod 700 folder name [here 700 represents rwx- - - - - -]
touch file1 - touch command is used to change the timestamp of last
modified information about that particular file or folder. If the file doesn’t exist then it
creates an EMPTY file.
cp file1 file2 - to make a copy of file1 with a name file2
mv file2 .. - to move file2 to its parent directory (.. represents parent
directory)

mv file2 file2a - to Rename the file2 to file2a


mv file1 “file one” - to rename the file separated by space
rm file1 - to remove file1
alias rm=“rm -i” - to set prompt for removal of a file
rm -r dir1 - to remove directory

Hard links = no. of files having same inode number OR no. of different entries in the
filesystem
“-” files have only one hard link

less filename - to read a text file page by page


file filename - to get the type of file

WEEK 2
Multiple use of / is the same as using it one time.
/ is called root directory. Root directory is its own parent.

ls -ld - listing permissions in long format without actually going inside


the directory

ls command can take command in any sequence.


cat filename - just like less command but cat command dumps the file
content onto the screen and we do not need to exit using q. (not recommended for
very long files as we can’t exit till all the content of the file is shown)
more filename - similar to less command
head filename - to get first few lines of file(default 10)
head -n 5 filename - to print first 5 lines
tail filename - similar to head but shows last lines
wc filename - prints no. of lines, words, bytes the file takes
wc -l filename - to just print no. of lines
which commandname - to locate the command
whatis commandname - to get brief description of command
apropos keyword - show all the commands which have the keyword in the
description or in the manual page.
man -k keyword - same as apropos keyword
apropos is a symbolic link to whatis command but the output is different
info
help - displays keywords reserved for the shell being run
type command - gives type of command(shell builtin or an alias)
type and help are shell builtin (offered by shell not OS)
alias ll= ‘ls -l’ - to set an alias
unalias ll - to remove the alias
alias - to list all the aliases

rmdir dir name - to remove empty directory


ln - to make hard link between files
ln -s sourcefile destinationfile- to make symbolic link
stat filename - to show file size in bytes, no. of blocks and block size
ls -s filename - to show file size in kb (if block size is 4096 and file size is
greater than 4096 but less than 8192, size shown will be 8kb i.e. if file size is less than
block size, it would take up the whole block)
du filename - to show file size ( same as ls -s filename)

/proc and /sys are stored in memory, not on hard disk. These are two file systems
which help us to know more about the hardware.
/proc - processes running are stored in this directory
df -h - partition sizes and other information in human readable
format

$hell Variables:
makes it possible to communicate between 2 processes very efficiently without
needing to read and write the file system. Also, used to store the information as an
intermediate form to process further.
echo - to print string or values of variables on to the screen (
removes the extra spaces from the string, To actually print the spaces put the string in
quotes)
Every shell variable will start with a $

Frequently used shell variables:-


echo $USERNAME - displays the username ( “” can be used but not ‘’)
echo $HOME
echo $HOSTNAME
echo $PWD
echo $PATH - list of directories (scanned from left to right to execute any
command)
eg. echo “user is \$USERNAME and host is $HOSTNAME”
here $USERNAME is not interpreted because of \, In this way interpretation can be
skipped

`` (back quotes) and $() are used to redirect the output of a command to a variable.
eg var1=`ls -l` or var1=$(ls -l)

printenv - to list shell variables


env - same as printenve
set - same as printenv

\ - to escape aliases (used before the commands)


ps - snapshot of the current processes
ps -e - lists all the processes running
ps -f - current process with parent process id
ps -ef

Special shell variables:-


$0 : name of the shell
$$ : process id of the shell
$? : return code of the previously run program
$- : flags set in the bash shell

Process control:
-Use the & at the end of command to run the process in the background
fg - to bring the process to the foreground
coproc - to run a command and use shell altogether(coprocess)
jobs - list all the programs running in the background
top - to look at the processes hogging the memory
kill - we could kill some processes owned by us

Program exit codes:


0: success
1: failure
2: misuse
126: command cannot be executed
127: command not found
130: process killed using ctrl+c
137: process killed using kill -9 <pid>
if exit code > 256 then exitcode%256 is reported so that the exit code value is always
between 0 - 255

Flags set in bash:


h: locate and hash the commands (i.e. to memorize the commands being executed)
B: brace expansion enabled
i: interactive mode
m: job control enabled ( jobs can be taken to bg or fg)
H: ! style history substitution enabled
s: commands are read from standard input
c: commands are read from arguments

# is called pound/hash symbol and ! is called bang.


Exporting a variable means making the value of that variable available to a shell that is
spawned by that current shell i.e converting it to env variable.
Change in the value of a variable in child shell is not reflected in the parent shell (even
if we export it to parent shell)

The above two tests have different meanings of 0 and 1 output. Read carefully.
List of variable names:-

! asks for name of variable and # asks for length of the value of variable
Length of the string value:-

Slice of the string value:-

offset can be negative(right to left in string) as well (but there should be one space
after colon for negative sign)
(eg. 5 means skip 5 characters from front, -5 means take the last 5 characters and use
those only)
REMOVE matching pattern:-

This prints the pattern that is not matching the given pattern.

KEEP matching pattern:-

This prints the pattern that matches the given pattern.

REPLACE matching pattern:-


Array indexes may/maynot be contiguous. Array indices are numeric.

hash indices can be alphanumeric


Linux process management

sleep n - command prompt sleeps for n seconds


coproc sleep n - command prompt sleeps but its still available to use
sleep n & - sleep process goes to bg
kill -9 PID - to kill a process using process id
ctrl + c - to kill a foreground process
jobs - list of active jobs/processes
top - display linux processes in sorted order
ctrl+z - to suspend a job ( to bring the job back use fg)
; - to combine multiple commands
history - history list of all the commands executed
!sr.no. - executes the command with the given sr. no. (the sr. no.
is from the history list)
Brace expansion:-
echo {a..z} - prints small abcd
echo {A..K} - prints big abcd for the given range
echo {a..d}{a..d} - prints combinations (aa ab ac….)
echo * - lists all the files and directories in the current directory
echo D* - list all the files and directories in the current directory
starting with D
bc - bench calculator

WEEK 3

Commands written in parenthesis () will be executed in subshells.


ls -l > file1 command output goes to file1 (file1 is either created or
overwritten)
ls /blah 2> error.txt error msg goes to error.txt file

ls $HOME /blah > file1 2> file1 error msg goes to file1 and then overwritten
by $HOME output
ls $HOME /blah > file1 2>&1 both error and the output will be present in
the file (initial content of the file will be overwritten) (no space between 2>&1)
SOFTWARE MANAGEMENT
Need for a package manager
● Tools for installing, updating, removing, managing software
● Install new/updated software across network
● Package - file look up, both ways
● Database of packages on the system including versions
● Dependency checking
● Signature verification tools
● Tools for building packages
To get checksum strings:
● md5sum file1.txt
● sha1sum file1.txt
● sha256sum file1.txt

1) Package management using apt


Only sudoers can install / upgrade / remove packages - sudo cat /etc/sudoers
Failed attempts are kept in log files - cd /var/log; sudo tail auth.log;

2) Package Management using dpkg


WEEK 4
Pattern Matching
grep command operates line after line

grep -i for case insensitive matching


\b word boundary ( if used at the beginning of the pattern,
then the first word is skipped for matching)
.* (dot star) means any no. of characters
grep -v [[ :alpha:]] for negation of alpha
grep -no to print the line number of the matched
egrep ‘^$’ to print empty lines
egrep -v ‘^$’ to print non-empty lines
egrep -o to print only matching
cut - to extract sections from each line of input
cut OPTION filename
OR
command | cut OPTION

cut -c range - to cut the given range of characters


cut -d “delimiter” -f field 1 or 2 - to cut using delimiter, print the specified field

Command Line Editors:-


Week 5
WEEK 6

hwinfo
lshw -list hardware
cat /proc/cpuinfo - display processors that are available
or cpu details
cat /proc/partitions -partitions info
lsblk -o NAME,SIZE - list the block devices
lspci - list pci devices
free - display free memory, swap memory
hardinfo -gui details
clinfo - tells about libraries supported by graphic card
upower -e - to know about battery devices and their status
iostat
PS1=“set new prompt format”
source .bashrc - to get back the default prompt

make - another way to write bash scripts


tar (tape archive)
sed -e ‘’ filename -to just print the file content
sed -n -e ‘’ filename - to not print the file content
sed -e ‘=’ filename - to print line number and lines
eg
sed -n -e ‘5p’ filename - to print only the 5th line
sed -n -e ‘5!p’ filename - to print all the lines except 5th line

sed -n -e ‘=; 5,8p’ filename -to print line number of all lines and print
lines from 5 to 8

sed -n -e ‘5,8{=;p}’ filename -to print line number and lines from 5 to 8

sed -n -e ‘1~3p’ filename - print 1st line and then print every 3rd line
from first

sed -e ‘5d’ filename -to delete 5th line and print the rest (line is
not actually deleted from the file”

sed -e ‘s/pattern1/pattern2/g’ filename -to search and replace pattern1 with


pattern2 and print (actual file content is not modified) and g represents do the
task for all occurrences of the pattern1 and s represents search and replace

WEEK 7
field separator can be Regex as well in awk
WEEK 8
Version Control
save- a new version of code
make- compile only those parts of code that have changed

“Each programmer has multiple versions of each file they worked on!”
Version Control - trace back to working version of code
versions - #users * #files * #version - requires database to hold

SVN - centrally hosted and managed version control system


GIT-
● distributed version control system
● every user (collaborator) has a copy of everything
● Remote: server with which we sync
● protocol: git
● operation:
○ locally run git server
○ campus git server
○ git-lab
○ github.com

Storage System - if it fails (incorrect, there is 100% surety of failure)


when it fails (correct) (addressed by RAID)
RAID- Redundant array of inexpensive/independent disks
In a RAID, usable space < actual space
PCI card - RAID controller

● Two factor Authentication - one more way


○ customized for each repository/activity
■ “personal access token” : long string, can be revoked as well

Networking Commands and SSH(secure shell):


- RAID 0 - You are using 2 disks as 1. Either Half of one file is stored on 2 disks.
It Doubles the speed of access of a file. Write Speed is 2x(2times) and Read
Speed is 2x for 2 disks. If there are n disks in RAID 0 equivalent storage is the
size of (minimum disk) * n. (minimum 2 disk)
- RAID 1 - Any piece of the file is written to both the disks. Reading is 2x but
writing is n-1. People tend to use RAID 1 for OS alone. (minimum 2 disk)
- RAID 5 - When you have more than 3 disks. Data is written to more than one
disk. If one fails nothing is lost. (minimum 3 disk)
- RAID 6 - Parity over 2 disks. If 2 disks fail you still have all your data.
- Most of the hardware supports hot-swap.
- Useable capacity is less than the actual capacity
- For storage people use RAID 5 or RAID 6.

You might also like