Os 0189
Os 0189
4th SEMESTER
Department of Artificial Intelligence & Data Science
CERTIFICATE
INDEX
2. CD
• Description: The cd command is used to change the current directory
in both Linux and other Unix-like systems.
• Syntax: cd [directory]
3. LS
• Description: we use ls command to list files and directories. This
command will print all the file and directories in the current directory.
• Syntax: ls [directory]
4. CD ..
• Description: This command is used to move to the parent directory of
current directory, or the directory one level up from the current directory.
“..” represents parent directory.
• Syntax: cd ..
5. CAT
• Description: The cat command is a utility command in Linux. One of
its most common usages is to print the content of a file onto the standard
output stream. Other than that, the cat command also allows us to write
some texts into a file.
• Syntax: cat [file-name]
6. HEAD
• Description: The head command, as the name implies, print the top N
number of data of the given input. By default, it prints the first 10 lines
of the specified files. If more than one file name is provided then data
from each file is preceded by its file name.
• Syntax: head [option] [file]
7. TAIL
• Description: Tail is a command which prints the last few numbers of
lines (10 lines by default) of a certain file, then terminates. By default,
“tail” prints the last 10 lines of a file, then exits. as you can see, this
prints the last 10 lines of /var/log/messages.
• Syntax: tail [option] [file]
8. MKDIR
• Description: The mkdir command in Linux/Unix allows users to create
or make new directories. mkdir stands for “make directory.” With mkdir
, you can also set permissions, create multiple directories (folders) at
once, and much more.
• Syntax: mkdir [directory name]
9. MV
• Description: The mv command termed as “Move”, which is a
command-line utility to move files or directories from source to target.
It supports the moving of a single file, multiple files, and directories.
• Syntax: mv [option] source destination
10. CP
• Description: cp command copies files (or, optionally, directories). The
copy is completely independent of the original. You can either copy one
file to another, or copy arbitrarily many files to a destination directory.
In the first format, when two file names are given, cp command copies
SOURCE file to DEST file.
• Syntax: cp [option] source destination
11. RMDIR
• Description: mdir command is used remove empty directories from the
filesystem in Linux. The rmdir command removes each and every
directory specified in the command line only if these directories are
empty. So if the specified directory has some directories or files in it
then this cannot be removed by rmdir command.
Student Name: ALAMURU TOSHITH REDDY
Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
12. GEDIT
• Description: The gedit command is used to create and open a file
• Syntax: gedit filename.txt
13. MAN
• Description: man command in Linux is used to display the user manual
of any command that we can run on the terminal. It provides a detailed
view of the command which includes NAME, SYNOPSIS,
DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES,
ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS
• Syntax: man command
14. ECHO
15. CLEAR
16. WHOAMI
• Description: whoami prints the effective user ID. This command
prints the username associated with the current effective user ID
• Syntax: whoami [option]
17. WC
• Description: wc (word count) command, can return the number of
lines, words, and characters in a file.
• Syntax: wc [option]… [file]…
Example:
✓ Print the byte counts of file myfile.txt
wc -c myfile.txt
✓ Print the line counts of file myfile.tx
wc -l myfile.txt
✓ Print the word counts of file myfile.txt
wc -w myfile.txt
18. GREP
• Description: grep command uses a search term to look through a file
• Syntax: grep [option]… Pattern [file]
19. FREE
• Description: To display the RAM details in Linux machine need to
write following command.
• Syntax: free
Types Of Shells:
1. Bournee shell: This is default shell for version 7 unix. The character $ is the
default prompt for the bourne shell.
2. C shell: This is a unix shell and a command processor that is run in a text window
. The character % is the default prompt for the C shell. File commands can also be
read easily by the C shell , which is known as a script.
Shell scripting is writing a series of command for the shell to execute. It can combine
lengthy and repetitive sequences of commands into a single and simple script, which can be
stored and executed anytime. This reduces the effort required by the end user. Let us understand
the steps in creating a Shell Script
1. Create a file using a vi editor(or any other editor). Name script file with extension .sh
2. Start the script with #! /bin/sh
3. Write some code.
4. Save the script file as filename.sh
5. For executing the script type bash filename.sh
"#!" is an operator called shebang which directs the script to the interpreter location. So, if we
use"#! /bin/sh" the script gets directed to the bourne-shell. Let's create a small script -
#!/bin/sh
ls
Let's see the steps to create it –
Command 'ls' is executed when we execute the scrip sample.sh file.
#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"
As you see, the program picked the value of the variable 'name' as Joy and 'remark' as
excellent.
This is a simple script. You can develop advanced scripts which contain conditional
statements, loops, and functions. Shell scripting will make your life easy and Linux
administration a breeze.
Summary:
• Kernel is the nucleus of the operating systems, and it communicates between
hardware and software
• Shell is a program which interprets user commands through CLI like Terminal
• The Bourne shell and the C shell are the most used shells in Linux
• Shell scripting is writing a series of command for the shell to execute
• Shell variables store the value of a string or a number for the shell to read
• Shell scripting can help you create complex programs containing conditional
statements, loops, and functions .
1. Gedit:
Syntax : gedit prac1.txt
Description: Gedit, the deafault GUI editor if you use Gnome ,also runs under KDE and
other desktops . Most gNewsense and linux installations use gnome by default. To start
Gedit open a terminal and type.
2. Bash:
Syntax : bash prac11.sh
Description : it is used to read the data in existing file in the linux .
PRACTICAL –3
Aim: Write a Shell script to print given numbers sum of all digits.
Sample Code:
#!/bin/bash echo "Enter the first number:"
read num1 echo "Enter the second number:"
read num2 sum=$((num1 + num2))
echo "The sum of $num1 and $num2 is: $sum"
Output:
PRACTICAL – 4
Sample Code:
#!/bin/bash
# Function to validate date format
validate_date() {
date -d "$1" 2>/dev/null
if [ $? -eq 0 ]; then
return 0 # Valid date
else
return 1 # Invalid date
fi
}
# Read date from user input
read -p "Enter a date in the format dd-mm-yyyy: "
date_input
# Validate the date format
if validate_date "$date_input"; then
echo "Valid date: $date_input"
else
echo "Invalid date format. Please enter a date in the
format dd-mm-yyyy."
fi
Output:
PRACTICAL – 5
Aim: Write a shell script to print whether the number is palindrome or not?
Sample Code:
#!/bin/bash
# Function to check if a string is a palindrome
is_palindrome() {
local original_string="$1"
$1 represents the first argument passed to a script or function.
local reversed_string=$(rev <<< "$original_string")
if [[ "$original_string" == "$reversed_string" ]]; then
return 0 # Palindrome
else
return 1 # Not a palindrome
fi
}
# Read input from user
read -p "Enter a string: " string
# Check if the string is a palindrome
if is_palindrome "$string"; then
echo "'$string' is a palindrome."
else
echo "'$string' is not a palindrome."
fi
Output:
PRACTICAL – 6
Sample Code:
#!/bin/bash
# Get the current hour
current_hour=$(date +%H)
(current_hour=$(date +%H):
# Determine the greeting
if [ "$current_hour" -lt "12" ]; then
(if [ "$current_hour" -lt "12" ]; then
echo "Good Morning!"
elif [ "$current_hour" -ge "12" ] && [
"$current_hour" -lt "18" ]; then
(elif [ "$current_hour" -ge "12" ] && [
"$current_hour" -lt "18" ]; then: This line checks
If
Output:
PRACTICAL – 7.1
Sample Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
fork();
fork();
fork();
printf("hello\n");
return 0;
}
Output:
PRACTICAL – 7.2
Sample Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
// make two process which run same
// program after this instruction
pid_t p = fork();
if(p<0){
perror("fork fail");
exit(1);
}
printf("Hello world!, process_id(pid) = %d \n",getpid());
return 0;
}
Output:
PRACTICAL – 8
Sample Code:
#include <stdio.h>
int main() {
int a = 11, b = 2, c = 9;
// Finding max using compound expressions
if (a >= b && a >= c)
printf("%d is the largest number.", a);
else if (b >= a && b >= c)
printf("%d is the largest number.", b);
else
printf("%d is the largest number.", c);
return 0;
}
Output: