DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING
OPERATING SYSTEMS LAB
CO201
LAB FILE
SUBMITTED TO SUBMITTED BY
Ms. Gul Kaur Vansh Verma
(2K21/CO/504)
INDEX
S.no Objective Date Sign
AIM: To know about the structure of Linux/Unix environment and learn about its architecture.
THEORY:
The Unix operating system is a set of programs that act as a link between the
computer and the user.
The computer programs that allocate the system resources and coordinate all the
details of the computer's internals is called the operating system or the kernel.
Users communicate with the kernel through a program known as the shell. The shell
is a command line interpreter; it translates commands entered by the user and
converts them into a language that is understood by the kernel.
The main concept that unites all the versions of Unix is the following four basics −
• Kernel − The kernel is the heart of the operating system. It interacts with
the hardware and most of the tasks like memory management, task
scheduling and file management.
• Shell − The shell is the utility that processes your requests. When you
type in a command at your terminal, the shell interprets the command
and calls the program that you want. The shell uses standard syntax for
all commands. C Shell, Bourne Shell and Korn Shell are the most
famous shells which are available with most of the Unix variants.
• Commands and Utilities − There are various commands and utilities
which you can make use of in your day to day
activities. cp, mv, cat and grep, etc. are few examples of commands and
utilities. There are over 250 standard commands plus numerous others
provided through 3rd party software. All the commands come along with
various options.
• Files and Directories − All the data of Unix is organized into files. All
files are then organized into directories. These directories are further
organized into a tree-like structure called the filesystem.
LEARNING:
AIM: Execute all the basic commands of unix/linux operating system in the terminal
THEORY:
The Linux command line is a text interface to your computer. Often referred to as the
shell, terminal, console, prompt or various other names, it can give the appearance of
being complex and confusing to use. Yet the ability to copy and paste commands from a
website, combined with the power and flexibility the command line offers, means that
using it may be essential when trying to follow instructions online, including many on this
very website!
CODE:
1. System Based Commands
uname Displays Linux system information
uname -r Displays kernel release information
uptime Displays how long the system has been running including load average
hostname Shows the system hostname
hostname -i Displays the IP address of the system
last reboot Shows system reboot history
date Displays current system date and time
timedatectl Query and change the System clock
cal Displays the current calendar month and day
w Displays currently logged in users in the system
whoami Displays who you are logged in as
finger username Displays information about the user
2. Hardware Based Commands
dmesg Displays bootup messages
Displays more information about CPU e.g model, model name, cores,
cat /proc/cpuinfo
vendor id
Displays more information about hardware memory e.g. Total and
cat /proc/meminfo
Free memory
lshw Displays information about system's hardware configuration
lsblk Displays block devices related information
Displays free and used memory in the system (-m flag indicates
free -m
memory in MB)
lspci -tv Displays PCI devices in a tree-like diagram
lsusb -tv Displays USB devices in a tree-like diagram
dmidecode Displays hardware information from the BIOS
hdparm -i /dev/xda Displays information about disk data
hdparm -tT
/dev/xda <:code> Conducts a read speed test on device xda
badblocks -s
/dev/xda
Tests for unreadable blocks on disk
3. User Management Commands
id Displays the details of the active user e.g. uid, gid, and groups
last Shows the last logins in the system
who Shows who is logged in to the system
groupadd "admin" Adds the group 'admin'
adduser "Sam" Adds user Sam
userdel "Sam" Deletes user Sam
usermod Used for changing / modifying user information
4. File Commands
Lists files - both regular & hidden files and their
ls -al
permissions as well.
pwd Displays the current directory file path
mkdir 'directory_name' Creates a new directory
rm file_name Removes a file
rm -f filename Forcefully removes a file
rm -r directory_name Removes a directory recursively
rm -rf directory_name Removes a directory forcefully and recursively
cp file1 file2 Copies the contents of file1 to file2
Recursively Copies dir1 to dir2. dir2 is created if it
cp -r dir1 dir2
does not exist
mv file1 file2 Renames file1 to file2
ln -s
/path/to/file_name link_name Creates a symbolic link to file_name
touch file_name Creates a new file
cat > file_name Places standard input into a file
more file_name Outputs the contents of a file
head file_name Displays the first 10 lines of a file
tail file_name Displays the last 10 lines of a file
gpg -c file_name Encrypts a file
gpg file_name.gpg Decrypts a file
wc Prints the number of bytes, words and lines in a file
xargs Executes commands from standard input
5. Process Related Commands
ps Display currently active processes
ps aux | grep 'telnet' Searches for the id of the process 'telnet'
pmap Displays memory map of processes
top Displays all running processes
kill pid Terminates process with a given pid
killall proc Kills / Terminates all processes named proc
pkill process-name Sends a signal to a process with its name
bg Resumes suspended jobs in the background
fg Brings suspended jobs to the foreground
fg n job n to the foreground
lsof Lists files that are open by processes
renice 19 PID makes a process run with very low priority
6. File Permission Commands
chmod octal filename Change file permissions of the file to octal
Set rwx permissions to owner, group and everyone
chmod 777 /data/test.c
(everyone else who has access to the server)
chmod 755 /data/test.c Set rwx to the owner and r_x to group and everyone
chmod 766 /data/test.c Sets rwx for owner, rw for group and everyone
chown owner user-file Change ownership of the file
chown owner-user:owner-group
Change owner and group owner of the file
file_name
chown owner-user:owner-group
Change owner and group owner of the directory
directory
7. Network Commands
ip addr show Displays IP addresses and all the network interfaces
ip address add 192.168.0.1/24 dev
Assigns IP address 192.168.0.1 to interface eth0
eth0
ifconfig Displays IP addresses of all network interfaces
ping command sends an ICMP echo request to establis
ping host
a connection to server / PC
whois domain Retrieves more information about a domain name
dig domain Retrieves DNS information about the domain
dig -x host Performs reverse lookup on a domain
host google.com Performs an IP lookup for the domain name
hostname -i Displays local IP address
wget file_name Downloads a file from an online source
netstat -pnltu Displays all active listening ports
8. Compression/Archives Commands
tar -cf home.tar home<:code> Creates archive file called 'home.tar' from file 'home
tar -xf files.tar Extract archive file 'files.tar'
tar -zcvf home.tar.gz source- Creates gzipped tar archive file from the source
folder folder
gzip file Compression a file with .gz extension
9. Install Packages Commands
rpm -i pkg_name.rpm Install an rpm package
rpm -e pkg_name Removes an rpm package
dnf install pkg_name Install package using dnf utility
10. Install Source (Compilation)
Checks your system for the required software needed to build the program. It wi
./configure build the Makefile containing the instructions required to effectively build the
project
It reads the Makefile to compile the program with the required operations. The
make process may take some time, depending on your system and the size of the
program
make The command installs the binaries in the default/modified paths after the
install compilation
11. Search Commands
grep 'pattern' files Search for a given pattern in files
grep -r pattern dir Search recursively for a pattern in a given directory
locate file Find all instances of the file
find /home/ -name "index" Find file names that begin with 'index' in /home folde
find /home -size +10000k Find files greater than 10000k in the home folder
12. Login Commands
ssh user@host Securely connect to host as user
ssh -p port_number user@host Securely connect to host using a specified port
Securely connect to the system via SSH default port
ssh host
22
telnet host Connect to host via telnet default port 23
13. File Transfer Commands
scp file1.txt
Securely copy file1.txt to server2 in /tmp directory
server2/tmp
rsync -a Synchronize contents in /home/apps directory with
/home/apps /backup/ /backup directory
14. Disk Usage Commands
df -h Displays free space on mounted systems
df -i Displays free inodes on filesystems
fdisk -l Shows disk partitions, sizes, and types
Displays disk usage in the current directory in a human-
du -sh
readable format
findmnt Displays target mount point for all filesystems
mount device-path mount-
point Mount a device
15. Directory Traverse Commands
cd .. Move up one level in the directory tree structure
cd Change directory to $HOME directory
cd /test Change directory to /test directory
AIM: Copy the contents of one file to another file using shell scripting.
THEORY:
CODE:
LEARNING: