Tutorial 0
Tutorial 0
Tutorial 0
1. All students are expected to have access to a working Ubuntu (22.04 LTS) set up by the first tutorial
session.
2. Students may follow instructions here or here to dual boot their systems. It is also fine to use a virtual
installation or a standalone Ubuntu installation. Please remember to back up all your important data before
trying this.
(or)
Download the VMware workstation for Windows from:
https://www.vmware.com/in/products/workstation-pro/workstation-pro-evaluation.html.
Once VMware is installed in your windows machine, follow the steps mentioned in below URL to
download Ubuntu and creating virtual machine:
https://ubuntu.tutorials24x7.com/blog/how-to-install-ubuntu-20-04-lts-on-windows-using-vmware-
workstation-player
6. Assume that you are in home directory. Type the following commands and observe the results.
$ls
$ls –l
$ls –a
$ls ..
$ls .
$ls ~
$ls ../.
$ls ./..
$ls –lt
$ls –ls
$ls –lh
$ls –al
7. Construct the following directory structure (using both absolute and relative path):
Assume that your present working directory is /home/sim1/BITS/Pilani/ Create a file student_id.doc under
WASE directory using relative path
Assume that your present working directory is /home/sim1/BITS/Pilani/ Execute following command:
$mkdir ./../newdir
Find out where newdir folder is created.
8. Assume that your present working directory is /home/sim1/BITS/ . User wishes to update the contents
of file info.txt under WIBangalore using relative path. He tries to use the following:
$ cat > /WIBangalore/info.txt
$ cat > ~/WIBangalore/info.txt
$ cat >> ~/WIBangalore/info.txt
Identify the correct command.
BITS Pilani - Hyderabad Campus
Operating Systems (CS F372)
Tutorial 0
The objective of this tutorial is to learn some Linux OS concepts and commands.
1. Run the command ps with various options and explain the output (important fields)
$ ps ( to read manual page for any command, run man <command>
$ ps –e
You will see that each process has a unique id (called pid). Use pipe ( | ) to send
output to ‘more’ to view output one screen at a time. What are Unix pipes?
$ ps –ef
$ pstree (to see process tree. Look at the tree and find the bash process. Go up
the tree by using grep to look at parents recursively. You can see that init process is at
the root of this tree.)
$ ps –ef | grep [parent pid]..
2. Run a program and use kill pid to terminate it. E.g. open vi in the background ( tell
them about background processes), and terminate it by its pid.
$ sleep 100& (command to sleep for 100 seconds)
[1] 12175 shows pid
$ kill 12175 (use kill -9 <pid> if this doesn’t work)
3. Create hard link to a file. What is a hard link? Need for hard links?
Assume a file 1.c is present with some text content; run the following commands
$ ln 1.c 2.c
$ ls –li
After running the above command, you will see two files with same size and inode
number (what is inode?)
Now, delete 2.c, and again run “ls –li”
Repeat the above process but now delete the original file instead of the new one.
Nothing changes except the file name. Directories have at least 2 links. Why?
4. Create symbolic link to a file. What is a symbolic link aka soft link aka sym link?
$ ln –s 1.c 2.c
$ ls –li
The output is different this time, 2.c is shown as a symbolic link to 1.c (look at the
first letter in the permission field, and also look at the end of the output line
corresponding to 2.c). The inode is also different. Attempting to read content of 2.c
will result in content of 1.c being read instead. The symbolic link file just contains the
name of the file it is pointing to; you can see this by running:
$ readlink 2.c
it will show 1.c as its content
Copying the symbolic link to another file copies the content of the original file the
symbolic link is pointing to.
$ cp 2.c 3.c
$ ls –li to see the inodes
Now delete the symbolic link.
$ rm 2.c
$ ls –li
Now delete all .c files (use rm <filename>)
Repeat the above process of creating symbolic link, but now delete the original file
instead of the symbolic link.
$ ln –s 1.c 2.c
$ ls –li
$ rm 1.c
The symbolic link remains but the file it points to has become invalid. Try copying
2.c to another file….will result in an error.
$ cp 2.c 3.c
cp: cannot stat ‘2.c’: No such file or directory
Why are symbolic links needed?
8. Deleting Files : rm
The rm (remove) command deletes one or more files. A file once deleted can’t be
recovered.
$ rm
$ rm chap01 chap02
$ rm *
Sometimes need to delete all files in a directory as part of a cleanup operation. The *
when used by itself, represented all files and can use rm with it.
9. top : The top command allows users to monitor processes and system resource usage
on Linux
$ top
10. Grep command is a powerful tool that searches for matching a regular expression
against text in a file, multiple files or a stream of input. It searches for the pattern of text
that you specify on the command line and prints output for you.
$ grep options pattern filename(s)
Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.
Options Description
-v : Displaying Non printing Characters
-n : Numbering Lines
Options Description
-l : Counts number of lines
-w : Counts words
-c : Counts characters
Tutorial 0
The objective of this tutorial is to learn the concepts related to booting an OS.
GRUB is the boot loader that Linux systems use to boot the operating system of your choice.
By default, in a single boot system the GRUB menu won’t be displayed. So press Shift immediately after
POST to make GRUB menu visible. You can see the list of OS installed in your system and can select
one of them
$ sudo vi /etc/default/grub
<<snip>>
GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
<<end snip>>
$ sudo update-grub
Now, during next booting any changes made in /etc/default/grub will be effective.
Make changes to GRUB_TIMEOUT; setting it to 0 would timeout immediately or you can increase the
time to say 60. In this case, the menu will be displayed for 60 seconds.
2. BIOS
You can change options in ROM-BIOS which will affect the whole system.
Find out the interrupt key. It will likely be one of F8, F12, or Del. To find out the interrupt key,
restart your system. When the system powers, press the interrupt key to enter the BIOS menu.
Select “Enter Setup”. You will get screen like below. You can view various system related stuff or
make changes to the system parameters here.
You can make changes to the boot order of various devices from Primary Boot Sequence.
Homework: Install Damn Small Linux in a thumb drive, and boot the OS from
it. See instructions on how to do at:
http://www.pendrivelinux.com/all-in-one-usb-dsl/
f
il
eco
mmand
LinuxCheatSheet
l
s –d i
rectorylisti
ng
l
s -
al –f ormattedli
stin
gw it
hh i
ddenfil
e s
cddir- c h
ang edirect
orytodir
cd–c hanget oho me
pwd–s howc u r
rentdir
ectory
mkd irdir–c reat
ea di
rector
yd i
r
rmfile–d el
e t
ef i
le
rm- rd i
r–d elet
ed i
rector
yd i
r
rm- ffi
le–f o rceremovefile
rm- rfdir–f o r
cer emovedirect
orydir*
cpfile1file2–c o p
yf i
le1tofil
e2
cp-rd ir1d ir2–c opyd i
r1todir2;cr
eatedir2ifi
t
doesn'
te xi
st
mvfile1f ile
2–r enameo rmovefil
e1t ofil
e2
i
f f
il
e 2is anex i
sti
ngd i
rect
ory,mo v
es f
ile1int
o
di
rectoryfile2
l
n- sfilelink–c r
eatesymbolicli
nklinktofile
t
o uchfile–c reateor u
pdatefi
le
cat>f i
le–p l
aces st
andar
dinputint
of i
le
moref ile–o utputtheconten
tsof f
ile
headfile–o u t
put t
hefirs
t10l i
nesof f
ile
t
ailfile–o u
tput t
helast10linesoffi
le
t
ail-f f
ile–o u t
putthecontent
s offi
leasit
gr
ow s,star
tingw it
hthelast10lines
Pro
ces
s Manage
ment
ps–displ
ayyou rcu
rrent
lyacti
veproces
ses
t
op–d ispl
ayallrun
ningprocesse
s
ki
llpid–k i
llprocessi
dp i
d
ki
lla
llproc–k illa
llprocess
es n
ame dpr
oc*
bg–list
sstoppedorbackgroundjobs
;res
umea
s
toppedjobinthebackgr
o u
nd
f
g–b ri
ngsthemo strece
ntjobtoforegr
ound
f
gn–b r
ingsjobntotheforeground
Fi
lePer
mis
sio
n s
chmodo cta
l fi
le–c h
angethepermiss
ionsoffi
le
t
oo ct
al,
w hi
c hcanbefoundsepa
rate
lyforuse
r,
gr
oup,andw orl
dbya d
ding:
●4–r ead(r)
●2–w r
ite(w)
●1–e xecute(x)
Exampl
es:
chmod7 77–r ead,
w r
ite
,execut
efor a
ll
chmod7 55–r wxforow ne
r,rxf
or gr
oupandw or
ld
Formoreo pt
ions,s
eema nchmod.
SSH
s
shu s
er@h ost–conne
c tt
oh os
tasuser
s
sh-pp ortus
er@h os
t –connectt
oho s
tonport
p
o r
tasuser
s
sh-copy-
iduser@host–a ddyourke
ytoh os
tfor
u
sertoenabl
ea ke
yedor pa
sswordl
esslogi
n
Sear
chi
ng
greppat
ternfi
les–s ea
rchforpat
ter
ninfil
es
grep-rpat
terndir–s ea
rchrec
ursi
velyfor
p
atter
nindir
c
o mma nd|gre
pp att
ern–s e
archforpat
ter
nint
he
out
putofcomma n
d
l
ocatefi
le–findalli
nst
ancesoffi
le
I
nst
all
ati
on
I
n s
tal
lfromsGoe
un
rr
a
cel
:command
.
/confi
g ure
ma ke
makeinstal
l
dpkg-i pkg.
d e
b–i ns
tal
l apackag
e(De bi
an)
rpm- Uvhp kg.rpm –installapac
kage(RPM)
Short
cuts
Ctrl+C–h altst
hec urre
n tcomma nd
Ctrl+Z–s topsthecurrentcomma nd,r
esumew i
th
fgintheforegr
oun dorbgi nthebackgr
ound
Ctrl+D–l ogo utofcurrentsess
ion,si
milart
oexit
Ctrl+W –e ra
ses onew ordinthecurr
entli
ne
Ctrl+U–e rasesthew holeli
ne
Ctrl+R–t ypetob ri
ngu pa r
ecentcomma nd
!
! -re
pe a
tsthelas
t comma nd
v
imc
heats
hee
t