Lab Journal

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Shri Ramdeobaba College of Engineering & Management, Nagpur-13

Department of Computer Application


MCA Sem - I
Session: 2023 – 2024

Course Name: Operating Systems Lab with Linux System Administration


Course Code: MCP540 - 1
Name of the Student: Akshita Vijay Bhange
Roll No: 05
Semester: I
Shift: II
Batch: I

Under the Guidance of


Prof. Yoginee Pethe
Sr. No. Title

1. To study virtualization and creating multiple machines of UBUNTU using Virtual Box.

2. To study and execute:


a. Linux Directory Commands
b. Linux File Commands
c. Linux File Content Commands

3. To study and execute:


a. Linux User Commands
b. Linux Filter Commands
c. Linux Utility Commands
d. Linux Network Commands

4. To study and execute Shell Scripting in Linux.

5. To compile and execute C program in Linux Environment.

6. Write C program that illustrates the creation of child process using fork() system call.
Display pid of child and parent process.

7. Write a C program that illustrates the use of wait() system call.

8. Write a C program that illustrates the creation of orphan process.

9. To study Linux file system.


Practical No.: 01
Aim: To study virtualization and creating multiple machines of UBUNTU using Virtual Box.
Theory:

• Virtualization: A process where more than one virtual machine can be installed in the Linux
operating system. It helps in the collaboration of the hardware and software resources of the
Linux operating Software.

• Types of Virtualizations

a. Hardware Virtualization.
b. Operating system Virtualization.
c. Server Virtualization.
d. Storage Virtualization.

• Different tools available for Virtualization

a. Virtual Box
b. VMware Workstation
c. Hyper – V
Steps:
Steps to install Ubuntu in Virtual Box
Before, we begin with the installation process, we need to download ISO file for Ubuntu. For that, all
the versions of Ubuntu are available on the official site ubuntu.com

After the downloading is over, you can install Ubuntu on VirtualBox with the help of following
instructions:
1. Open VirtualBox and click on the New button.

2. Give a name to your Virtual Machine and select the location for it to install.
3. Assign RAM size to your Virtual Machine.

4. Create a Virtual Hard disk for the machine to store files.


5. Select the type of Hard disk. Using VDI type is recommended.

6. Either of the physical storage type can be selected. Using Dynamically allocated disk is by
default recommended.
7. Select disk size and provide the destination folder to install.

8. After the Disk creation is done, boot the Virtual Machine and begin installing Ubuntu.
9. If the installation disk is not automatically detected. Browse the file location and select the
ISO file for Ubuntu.

10. Proceed with the installation file and wait for further options.
11. Click on the Install Ubuntu option, this might look different for other Ubuntu versions.

12. Select Keyboard layout, if the defaults are compatible, just click on the continue button
and proceed.
13. Select installation type. By default, it is set to Normal installation, which is recommended,
but it can also be changed to Minimal installation if there is no need for all Ubuntu
features.

14. Click on the Install Now button and carry on with the installation. Do not get worried
with the Erase disk option, it will only be effective inside the virtual machine, other system
files outside the VirtualBox remain intact.
15. Click on the continue button, and proceed with writing changes on the disk.

16. Select your location to set the Time Zone.


17. Choose a name for your computer and set a password to secure login info.

18. Wait for the installation process to complete.


19. Once the installation process is over, reboot your Virtual Machine.

20. You’re finished with the installation process. Now you can use Ubuntu along with
Windows, without creating a dual boot.
Practical No.: 02
Aim: To study and execute:
a. Linux Directory Commands
b. Linux File Commands
c. Linux File Content Commands
Steps:
a. Linux Directory Commands

1. pwd command
The pwd command is used to display the location of the current working directory.
Syntax:
pwd
Output:

2. mkdir command
The mkdir command is used to create a new directory under any directory.
Syntax:
mkdir [options] [directory name]
Options:
-p: A flag which enables the command to create parent directories as necessary. If the directories
exist, no error is specified.
Output:
3. rmdir command
The rmdir command is used to delete a directory.
Syntax:
rmdir [directory name]
Output:

4. ls Command
The ls command is used to display a list of the content of a directory.
Syntax:
ls [options]
Options:
-l: A long format that displays detailed information about files and directories.
-r: Reverse order which is used to reverse the default order of listing.
-R: List files and directories recursively, including subdirectories.
-lh: To display file size in easy-to-read format. i.e M for MB, K for KB, G for GB.
-a: Represent all files Include hidden files and directories in the listing.
Output:
5. cd command
The cd command is used to change the current directory.
Syntax:
cd [directory name]
Output:
b. Linux File Commands

i. touch command
The touch command is used to create empty files. We can create multiple empty files by executing it
once.

Syntax:
touch [file name]
Output:

ii. cat command


The cat command is a multi-purpose utility in the Linux system. It can be used to create a file, display
content of the file, copy the content of one file to another file, and more.
Syntax:
cat [file name]
Output:

iii. rm command
The rm command is used to remove a file.
Syntax:
rm [options] [file name]
Options:
-i: Interactive Deletion, it is like in cp, the -i option makes the command ask the user for
confirmation before removing each file, you have to press y for confirm deletion, any other key
leaves the file un-deleted.
-f: Force Deletion, rm prompts for confirmation removal if a file is written protected. The -f
option overrides this minor protection and removes the file forcefully.
-r: Recursive Deletion, with -r(or -R) option rm command performs a tree-walk and will delete
all the files and sub-directories recursively of the parent directory. At each stage it deletes
everything it finds.
Output:

iv. cp command
The cp command is used to copy a file or directory.
Syntax:
cp [file name] [new file name]
Output:
v. mv command
The mv command is used to move a file or a directory form one location to another location.
Syntax:
mv [file/directory name] [file/directory name]
Output:
c. Linux File Content Commands

1. head command
The head command is used to display the content of a file. It displays the first 10 lines of a file.
Syntax:
head [options] [file name]
Options:
-n: Prints the first ‘num’ lines instead of first 10 lines. num is mandatory to be specified in
command otherwise it displays an error.
-c: Prints the first ‘num’ bytes from the file specified. Newline count as a single character, so if
head prints out a newline, it will count it as a byte.
-q: It is used if more than 1 file is given. Because of this command, data from each file is not
precedes by its file name.
-v: By using this option, data from the specified file is always preceded by its file name.
Output:
2. tail command
The tail command is similar to the head command. The difference between both commands is that it
displays the last ten lines of the file content. It is useful for reading the error message.
Syntax:
tail [options] [file name]

Options:
-n: Prints the first ‘num’ lines instead of first 10 lines. num is mandatory to be specified in
command otherwise it displays an error.
-c: Prints the first ‘num’ bytes from the file specified. Newline count as a single character, so if
head prints out a newline, it will count it as a byte.
-q: It is used if more than 1 file is given. Because of this command, data from each file is not
precedes by its file name.
-v: By using this option, data from the specified file is always preceded by its file name.
Output:
3. more command
The more command is quite similar to the cat command, as it is used to display the file content in the
same way that the cat command does. The only difference between both commands is that, in case of
larger files, the more command displays screenful output at a time.
Syntax:
more [file name]
Output:
4. less command
The less command is similar to the more command. It also includes some extra features such as
'adjustment in width and height of the terminal.' Comparatively, the more command cuts the output in
the width of the terminal.
Syntax:
less [file name]

Output:
Practical No.: 03
Aim: To study and execute:
a. Linux User Commands
b. Linux Filter Commands
c. Linux Utility Commands
d. Linux Network Commands
Steps:
a. Linux User Commands

i. useradd command
The useradd command is used to add user on a Linux server.
Syntax:
$ sudo useradd username
Output:

ii. userdel command


The useradd command is used to remove user on a Linux server.
Syntax:
$ sudo userdel username
Output:

iii. passwd command


The passwd command is used to create and change the password for a user.
Syntax:
$ passwd [username]
Output:
iv. id command
It is used to print the genuine and effective user ID and group ID.
Syntax:
id [options] [username]
Output:

v. su command
It allows a user to switch to another user account and gain all of its privileges, while sudo command in
linux allows a user to execute a specific command with the privileges of another user.
Syntax:
su [username]
Output:
b. Linux Filter Commands

1. cat command
The cat command is also used as a filter, to filter a file, it is used inside pipes.
Syntax:
cat [filename]
Output:

2. cut command
The cut command is used to select a specific column of a file. The '-d' option is used as a delimiter, and
it can be a space (' '), a slash (/), a hyphen (-), or anything else. And, the '-f' option is used to specify a
column number.
Syntax:
cut -d (delimiter) -f (column Number) [file name]
Output:

3. grep command
The grep is the most powerful and used filter in a Linux system. The 'grep' stands for "global regular
expression print." It is useful for searching the content from a file. Generally, it is used with the pipe.
Syntax:
grep [word search]
Output:

4. sed command
The sed command is also known as stream editor. It is used to edit files using a regular expression. It
does not permanently edit files; instead, the edited content remains only on display. It does not affect
the actual file.
Syntax:
sed ‘s/<oldWord>/<newWord>/’

Output:

5. uniq command
The uniq command is used to form a sorted list in which every word will occur only once.

Syntax:
[file name] | uniq
Output:
6. sort command
The sort command is used to sort files in alphabetical order.
Syntax:
sort [file name]

Output:
c. Linux Utility Commands

1. find command
The find command is used to find a particular file within a directory. It also supports various options to
find a file such as byname, by type, by date, and more.
The following symbols are used after the find command:
(.): For current directory name
(/): For root
Syntax:
find .-name “*.pdf”
Output:

2. date command
The date command is used to display date, time, time zone, and more.
Syntax:
date
Output:

3. sleep
The sleep command is used to hold the terminal by the specified amount of time. By default, it takes
time in seconds.
Syntax:
sleep [time]
Output:

4. cal command
The cal command is used to display the current month's calendar with the current date highlighted.
Syntax:
cal
Output:

5. df command
The df command is used to display the disk space used in the file system. It displays the output as in
the number of used blocks, available blocks, and the mounted directory.
Syntax:
df
Output:
6. clear command
Linux clear command is used to clear the terminal screen.
Syntax:
clear
Output:

7. exit command
The command causes the shell or program to terminate.
Syntax:
exit
Output:
d. Linux Network Commands

1. ip command
Linux ip command is an updated version of the ipconfig command. It is used to assign an IP address,
initialize an interface, disable an interface.
Syntax:
ip a or ip addr
Output:

2. ping command
The ping command is used to check the connectivity between two nodes, that is whether the server is
connected. It is a short form of "Packet Internet Groper."
Syntax:
ping [destination]

Output:

3. host command
The host command is used to display the IP address for a given domain name and vice versa. It performs
the DNS lookups for the DNS Query.
Syntax:
Host [domain name] or [ip address]
Output:

4. ifconfig command
It can be used from the command line either to assign an address to a network interface or to configure
or display the current network interface configuration information.

Syntax:
ifconfig [options] [interface]
Output:
Practical No.: 04
Aim: To study and execute Shell Scripting in Linux.
Theory:
Usually, shells are interactive, which means they accept commands as input from users and
execute them. However, sometimes we want to execute a bunch of commands routinely, so we have to
type in all commands each time in the terminal.

As a shell can also take commands as input from file, we can write these commands in a file
and can execute them in shell to avoid this repetitive work. These files are called Shell Scripts or Shell
Programs. Shell scripts are similar to the batch file in MS-DOS. Each shell script is saved with `.sh` file
extension e.g., myscript.sh.

A shell script has syntax just like any other programming language. If you have any prior
experience with any programming language like Python, C/C++ etc. It would be very easy to get started
with it.

Steps:
1. Create a new file called demo.sh using a text editor such as nano or vi.

2. Add the following code:

3. Exit the code by using Ctrl + X, press Y for yes and run the following command to check
the bash code.
Practical No.: 05
Aim: To compile and execute C program in Linux Environment.

Steps:
Practical No.: 06
Aim: Write C program that illustrates the creation of child process using fork() system call. Display pid
of child and parent process.

Steps:
Practical No.: 07
Aim: Write a C program that illustrates the use of wait() system call.

Algorithm:
1.Start
2.Declaring the variable cpid
3.Checking if(pid==0)
4.It will exit
5.Else
6.cpid=wait(NULL)
7.It will print Parent and Child pid
8.stop

Steps:
Practical No.: 08
Aim: Write a C program that illustrates the creation of orphan process.

Algorithm:
1.Start
2.Initializing the variable pid=fork().
3.Checking if(pid==0)
4.It will print In parent process
5.Else it will print In child process after 30sec
6.Stop

Steps:
Practical No.: 09
Aim: To study Linux file system.

Theory:
Linux File System Structure Linux file system has a hierarchal file structure as it contains a
root directory and its subdirectories. All other directories can be accessed from the root directory. A
partition usually has only one file system, but it may have more than one file system.
A file system is designed in a way so that it can manage and provide space for non-volatile
storage data. All file systems required a namespace that is a naming and organizational methodology.
The namespace defines the naming process, length of the file name, or a subset of characters that can
be used for the file name. It also defines the logical structure of files on a memory segment, such as the
use of directories for organizing the specific files.
Once a namespace is described, a Metadata description must be defined for that particular file.
The data structure needs to support a hierarchical directory structure; this structure is used to describe
the available and used disk space for a particular block. It also has the other details about the files such
as file size, date & time of creation, update, and last modified. Also, it stores advanced information
about the section of the disk, such as partitions and volumes.
The advanced data and the structures that it represents contain the information about the file
system stored on the drive; it is distinct and independent of the file system metadata. Linux file system
contains two-part file system software implementation architecture.

The file system requires an API (Application programming interface) to access the function
calls to interact with file system components like files and directories. API facilitates tasks such as
creating, deleting, and copying the files. It facilitates an algorithm that defines the arrangement of files
on a file system. The first two parts of the given file system together called a Linux virtual file system.
It provides a single set of commands for the kernel and developers to access the file system. This virtual
file system requires the specific system driver to give an interface to the file system.
• Linux File System Features
In Linux, the file system creates a tree structure. All the files are arranged as a tree and its branches.
The topmost directory called the root (/) directory. All other directories in Linux can be accessed from
the root directory.

Some key features of Linux file system are as following:

➢ Specifying paths: Linux does not use the backslash (\) to separate the components; it uses
forward slash (/) as an alternative. For example, as in Windows, the data may be stored in C:\
My Documents\ Work, whereas, in Linux, it would be stored in /home/ My Document/ Work.

➢ Partition, Directories, and Drives: Linux does not use drive letters to organize the drive as
Windows does. In Linux, we cannot tell whether we are addressing a partition, a network
device, or an "ordinary" directory and a Drive.

➢ Case Sensitivity: Linux file system is case sensitive. It distinguishes between lowercase and
uppercase file names. Such as, there is a difference between test.txt and Test.txt in Linux. This
rule is also applied for directories and Linux commands.

➢ File Extensions: In Linux, a file may have the extension '.txt,' but it is not necessary that a file
should have a file extension. While working with Shell, it creates some problems for the
beginners to differentiate between files and directories. If we use the graphical file manager, it
symbolizes the files and folders.

➢ Hidden files: Linux distinguishes between standard files and hidden files, mostly the
configuration files are hidden in Linux OS. Usually, we don't need to access or read the hidden
files. The hidden files in Linux are represented by a dot (.) before the file name (e.g., .ignore).
To access the files, we need to change the view in the file manager or need to use a specific
command in the shell.

You might also like