0% found this document useful (0 votes)
2 views4 pages

OS Practical Notes

The document provides a comprehensive overview of basic and advanced Linux commands, including their descriptions and examples. It also covers shell scripting fundamentals, such as variables, operators, conditionals, loops, and functions, as well as system calls in C on Linux. The content is structured into sections for easy reference and learning.

Uploaded by

sandipan das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

OS Practical Notes

The document provides a comprehensive overview of basic and advanced Linux commands, including their descriptions and examples. It also covers shell scripting fundamentals, such as variables, operators, conditionals, loops, and functions, as well as system calls in C on Linux. The content is structured into sections for easy reference and learning.

Uploaded by

sandipan das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Basic Linux Commands (2 Classes / 4 Hrs)


Command Description Example Output
pwd Print current directory pwd /home/user
ls List directory contents ls -l Lists files with details
cd Change directory cd /home Moves to /home directory
mkdir Make directory mkdir test Creates test directory
rmdir Remove empty dir rmdir test Removes test directory
rm Remove files/dir rm file.txt Deletes file.txt
touch Create empty file touch file.txt Creates file.txt
man Show manual page man ls Shows help for ls
cp Copy files cp file1 file2 Copies file1 to file2
mv Move or rename mv a.txt b.txt Renames a.txt to b.txt
locate Finds files quickly locate test.txt Lists paths for test.txt
head First 10 lines head file.txt Displays top 10 lines
tail Last 10 lines tail file.txt Displays bottom 10 lines

2. Advanced Linux Commands (3 Classes / 6 Hrs)


Command Description Example
echo Print message echo "Hello"
cat Show file contents cat file.txt
sudo Run as root sudo apt update
df Disk usage df -h
tar Archive files tar -cvf file.tar file/
apt-get Package manager sudo apt-get install vim
chmod Change permissions chmod 755 file.sh
hostname View/set hostname hostname
useradd Add user sudo useradd john
passwd Change password passwd john
groupadd Add group sudo groupadd devs
grep Search pattern grep "hello" file.txt
sed Stream editor sed 's/old/new/' file.txt
uniq Remove duplicates uniq file.txt
wc Word count wc file.txt
od Hex dump od -c file.txt
gzip Compress file gzip file.txt
gunzip Decompress gunzip file.txt.gz
find Search files find / -name file.txt
date Show date date
Command Description Example
cal Show calendar cal
clear Clear terminal clear
top Task manager top
ps Process status ps aux
kill Kill process kill PID

3. Shell Scripting in Linux (7 Classes / 14 Hrs)


�Basics

 Shell: Command-line interpreter (e.g., bash, sh, zsh)


 Shell Script: File containing shell commands (e.g., myscript.sh)

bash
CopyEdit
#!/bin/bash
echo "Hello, Shell Scripting"

�Variables
bash
CopyEdit
name="John"
echo "Hello $name"

 Special Variables:
o $$ – Process ID
o $0 – Script name
o $1...$9 – Positional parameters
o $# – Number of arguments
o $? – Exit status
o $! – PID of last background process

�Arrays
bash
CopyEdit
arr=(one two three)
echo ${arr[1]} # Output: two

�Operators

Operator Type Operators


Assignment =
Equality ==
Not Equal !=
Operator Type Operators
Arithmetic +, -, *, /, %
Comparison -eq, -ne, -gt, -lt, -ge, -le
Logical !, -o, -a

�Conditionals
bash
CopyEdit
if [ $a -gt $b ]
then
echo "A is greater"
else
echo "B is greater"
fi
bash
CopyEdit
case $var in
1) echo "One" ;;
2) echo "Two" ;;
*) echo "Default" ;;
esac

�Loops
bash
CopyEdit
# while loop
i=1
while [ $i -le 5 ]
do
echo $i
i=$((i+1))
done
bash
CopyEdit
# for loop
for i in 1 2 3
do
echo $i
done

�Break & Continue


bash
CopyEdit
for i in {1..5}
do
if [ $i -eq 3 ]; then
break
fi
echo $i
done

�Functions
bash
CopyEdit
function greet() {
echo "Hello, $1"
}
greet "Alice"

4. System Calls in C on Linux (3 Classes / 6 Hrs)


�Example: fork(), getpid(), exec(), exit()
c
CopyEdit
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>

int main() {
pid_t pid = fork();

if (pid == 0) {
printf("Child process, PID = %d\n", getpid());
execlp("/bin/ls", "ls", NULL); // Executes 'ls'
} else {
printf("Parent process, PID = %d\n", getpid());
}
return 0;
}

�mkdir(), rmdir()
c
CopyEdit
#include <sys/stat.h>
#include <unistd.h>

int main() {
mkdir("newdir", 0777);
rmdir("newdir");
return 0;
}

You might also like