0% found this document useful (0 votes)
8 views100 pages

Experiment - 1: What Is A Computer?

The document provides an overview of computers, including their definition, history, and components such as motherboards, RAM modules, daughter cards, and storage devices. It also covers various interfacing ports and Linux commands for basic operations. The information is structured as an educational experiment from the Federal Institute of Science & Technology (FISAT).

Uploaded by

aromalvasanth333
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)
8 views100 pages

Experiment - 1: What Is A Computer?

The document provides an overview of computers, including their definition, history, and components such as motherboards, RAM modules, daughter cards, and storage devices. It also covers various interfacing ports and Linux commands for basic operations. The information is structured as an educational experiment from the Federal Institute of Science & Technology (FISAT).

Uploaded by

aromalvasanth333
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

FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT – 1

What is a computer?

A computer is an electronic device that manipulates information, or data. It has the ability to
store, retrieve, and process data.

History of computers

In the early 1820s, it was designed by Charles Babbage who is known as "Father of Modern
Computer". It was a mechanical computer which could perform simple calculations. It was a
steam driven calculating machine designed to solve tables of numbers like logarithm tables
Modern computers can perform generic sets of operations known as programs. These
programs enable computers to perform a wide range of tasks. A computer system is a
"complete" computer that includes the hardware, operating system (main software), and
peripheral equipment needed and used for "full" operation. This term may also refer to a
group of computers that are linked and function together, such as a computer network or
computer cluster.
A broad range of industrial and consumer products use computers as control systems. Simple
special-purpose devices like microwave ovens and remote controls are included, as are
factory devices like industrial robots and computer-aided design, as well as general-purpose
devices like personal computers and mobile devices like smartphones. Computers power the
Internet, which links billions of other computers and users.
Early computers were meant to be used only for calculations. Simple manual instruments like
the abacus have aided people in doing calculations since ancient times. Early in the Industrial
Revolution, some mechanical devices were built to automate long tedious tasks, such as
guiding patterns for looms. More sophisticated electrical machines did specialized analog
calculations in the early 20th century. The first digital electronic calculating machines were
developed during World War [Link] semiconductor transistors in the late 1940s were
followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit
(IC) chip technologies in the late 1950s, leading to the microprocessor and the
microcomputer revolution in the 1970s. The speed, power and versatility of computers have
been increasing dramatically ever since then, with transistor counts increasing at a rapid pace
(as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early
21st centuries.

DEPARTMENT OF COMPUTER APPLICATIONS 1


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Components of Computer

1. Mother Board

A motherboard (also called mainboard, main circuit board, mb, mboard, backplane board,
base board, system board, logic board (only in Apple PCs) or mobo) is the main printed
circuit board (PCB) in general-purpose computers and other expandable systems. It holds and
allows communication between many of the crucial electronic components of a system, such
as the central processing unit (CPU) and memory, and provides connectors for other
peripherals. Unlike a backplane, a motherboard usually contains significant sub-systems,
such as the central processor, the chipset's input/output and memory controllers, interface
connectors, and other components integrated for general use.
The motherboard is mounted inside the case and is securely attached via small screws
through pre-drilled holes. Motherboard contains ports to connect all of the internal
components. It provides a single socket for CPU, whereas for memory, normally one or more
slots are available. Motherboards provide ports to attach the floppy drive, hard drive, and
optical drives via ribbon cables. Motherboard carries fans and a special port designed for
power supply.
There is a peripheral card slot in front of the motherboard using which video cards, sound
cards, and other expansion cards can be connected to the motherboard.
On the left side, motherboards carry a number of ports to connect the monitor, printer, mouse,
keyboard, speaker, and network cables. Motherboards also provide USB ports, which allow
compatible devices to be connected in plug-in/plug-out fashion. For example, pen drive,
digital cameras, etc.

DEPARTMENT OF COMPUTER APPLICATIONS 2


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

2. Ram Modules

In computing, a memory module or RAM (random-access memory) stick is a printed circuit


board on which memory integrated circuits are mounted. Memory modules permit easy
installation and replacement in electronic systems, especially computers such as personal
computers, workstations, and servers. The first memory modules were proprietary designs
that were specific to a model of computer from a specific manufacturer.

DEPARTMENT OF COMPUTER APPLICATIONS 3


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

3. Daughter cards

A daughterboard is type of circuit board that plugs in or is attached to the motherboard or


similar expansion card to extend its features and services. A daughterboard complements the
existing functionality of a motherboard or an expansion card. A daughterboard is also known
as daughter card, piggyback board, riser card or mezzanine board. A daughterboard is
connected directly to the motherboard. Unlike expansion cards, which connect with the
motherboard using bus and other serial interfaces, daughterboards are usually directly
embedded through soldering. Like a motherboard, a daughterboard has sockets, pins, plugs
and connectors to be attached to other boards. Typically, daughterboards are released as a
post-launch update to a motherboard or expansion card. For example, a MIDI daughterboard
is used to add on the functionality of the sound card.

Functionalities of daughter board:

• It is known as the piggyback board, riser card, daughtercard etcetera.


• A daughter board is smaller than a motherboard and may have some slots like the
motherboard.
• A daughter board is a printed circuit board which is connected to the motherboard or
expansion card.
• Unlike expansion card, daughter boards are directly connected to the motherboard by
soldering.
• Daughter boards do not provide new functions to the circuit like an expansion but they
extend the circuitry of the circuit in which they are plugged into.
• Daughter boards are released by the vendors as an update of motherboard or expansion
card.

List of daughter cards

• Video Card: This is also referred to as the graphics adapter, display adapter or video
adapter.
• Sound Card: To handle sound, to insert a microphone or connect a speaker this sound card
is used.
• Network Interface Card: This is also referred as NIC. The computer can be connected to a

DEPARTMENT OF COMPUTER APPLICATIONS 4


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

network only with the use of this network interface card.


• Ethernet Card: Ethernet card is used to connect computers to computers. A cable is used to
connect the Ethernet cards in each computer to make a network

DEPARTMENT OF COMPUTER APPLICATIONS 5


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

4. Bus slots

An expansion slot refers to any of the slots on a motherboard that can hold an expansion card
to expand the computer's functionality, like a video card, network card, or sound [Link]
expansion card is plugged directly into the expansion port so that the motherboard has direct
access to the hardware. However, since all computers have a limited number of expansion
slots, it's important to open your computer and check what's available before you buy
[Link] older systems require the use of a riser board to add additional expansion cards;
however, modern computers not only usually have enough expansion slot options, but they
also have features integrated directly into the motherboard, eliminating the need for so many
expansion cards. There are three different types of expansion slots: PCI Express, PCI, and
AGP.

PCI (Peripheral Component Interconnect) Slot: The PCI slot is the most common form of
internal expansion for a [Link] PCs have a mixture of PCI and PCI Express slots.

PCI express (PCIe) Slots: The best type of expansion slot to have in your PC is the PCI
Express. The PCI Express type of expansion slot communicates with the motherboard, and
therefore with the microprocessor, both quickly and efficiently.

AGP (Accelerated Graphics Port) Slot: This type of expansion slot was specifically
designed to deal with graphics adapters. In fact, AGP stands for Accelerated Graphics Port.
Older PCs may sport this expansion slot, but the best video cards use PCI Express.

DEPARTMENT OF COMPUTER APPLICATIONS 6


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

5. SMPS

A switched-mode power supply (SMPS) is an electronic circuit that converts power using
switching devices that are turned on and off at high frequencies, and storage components
such as inductors or capacitors to supply power when the switching device is in its non
conduction state.
Switching power supplies have high efficiency and are widely used in a variety of electronic
equipment, including computers and other sensitive equipment requiring stable and efficient
power supply.
A switched-mode power supply is also known as a switch-mode power supply or switching
mode power supply.
Switched-mode power supplies are classified according to the type of input and output
voltages. The four major categories are:

•AC to DC

•DC to DC

•DC to AC

•AC to AC

DEPARTMENT OF COMPUTER APPLICATIONS 7


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

6. INTERNAL STORAGE DEVICES

Some storage devices are classed as 'internal' which means they are inside the computer case.
Most computers have some form of internal storage. The most common type of internal
storage is the hard disk. At the most basic level, internal storage is needed to hold the
operating system so that the computer is able to access the input and output devices. It will
also be used to store the applications software that you use and more than likely, the original
copies of your data files. Internal storage allows the data and applications to be loaded very
rapidly into memory, ready for use. The data can be accessed much faster than data which is
stored on an external storage device. This is because internal storage devices are connected
directly to the motherboard and its data bus whereas external devices are connected through a
hardware interface such as USB, which means they are considerably slower to access.
Internal storage also means that if the computer is moved around, it will still retain its most
commonly used data. The main disadvantage of internal storage is that when the hard disk
fails (and it will), all the data and applications may be lost. This can be avoided to some
extent by using more than one hard disk within the machine. Each hard disk has a copy of all
the data, so if one fails the other can carry on. This is called a RAID array. An alternative is
to use external drives for backup.

DEPARTMENT OF COMPUTER APPLICATIONS 8


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

7. Interfacing Ports

A Computer Port is an interface or a point of connection between the computer and its
peripheral devices. Some of the common peripherals are mouse, keyboard, monitor or display
unit, printer, speaker, flash drive etc. The main function of a computer port is to act as a point
of attachment, where the cable from the peripheral can be plugged in and allows data to flow
from and to the device.

Types of ports: -

Serial Port: used for external modems and older computer mouse.
Parallel Port: used for scanners and printers.
PS/2 Port: used for old computer keyboard and mouse.
Universal Serial Bus (or USB) Port: It can connect all kinds of external USB devices such
as external hard disk, printer, scanner, mouse, keyboard, etc.
VGA Port: connects monitor to a computer's video card. It has 15 holes. Similar to the serial
port connector. However, serial port connector has pins, VGA port has holes.
Power Connector: connects to the computer's power cable that plugs into a power bar or
wall socket.
Modem Port: connects a PC's modem to the telephone network.
Ethernet Port: connects to a network and high speed Internet. Connects the network cable to
a computer.
Game Port: connect a joystick to a PC. Now replaced by USB Digital Video Interface
DVI port: connects Flat panel LCD monitor to the computer's high-end video graphic cards.
Sockets: sockets connect the microphone and speakers to the sound card of the computer.

DEPARTMENT OF COMPUTER APPLICATIONS 9


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

DEPARTMENT OF COMPUTER APPLICATIONS 10


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT - 2

LINUX COMMANDS

[Link] : man command in Linux is used to display the user manual of any command
that we can run on the terminal.
Syntax : $man [OPTION]... [COMMAND NAME]..
• If no option is provided it displays whole manual of the command. •
$man ls

[Link] : List directory contents Syntax: ls [options] [paths]

● Options:

○ s -a: list all files including hidden files.

○ ls -t: sort the list by time of modification, with the newest at the top.

○ ls -r: reverse the sorting order.

○ ls -l: list the files in long format i.e. with an index number, owner name, group

name, size, and permissions.

DEPARTMENT OF COMPUTER APPLICATIONS 11


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Eg : ls –l

[Link] : display a line of text

Syntax : Echo [option] [string]

● Options:

○ \b: removes all spaces between the text

○ \n : this option creates new line from where it is used

○ \t : this option is used to create horizontal tab spaces.

DEPARTMENT OF COMPUTER APPLICATIONS 12


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

4 .read : The read command in the Linux system is used to read from a file

descriptor. Example:

5. more : more commands are used to view the text files in the command prompt,
displaying one screen at a time in case the file is large

● Syntax:

more [-options] [-num] [+/pattern] [+linenum] [file_name]

▪ [-options]: any option that you want to use in order to


change the way the file is displayed. Choose any one
from the followings: (-d, -l, -f, -p, -c, -s, -u)

▪ [-num]: type the number of lines that you want to display


per screen.

▪ [+/pattern]: replace the pattern with any string that you


want to find in the text file.

▪ [+linenum]: use the line number from where you want to


start displaying the text content.

● Options:

▪ -d : Use this command in order to help the user to


navigate.

▪ -f : This option does not wrap the long lines and displays
them as such

● Example:

more [Link];

DEPARTMENT OF COMPUTER APPLICATIONS 13


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

6. Less : Less command is a Linux utility that can be used to read the contents of a text file
one page(one screen) at a time. It has faster access because if file is large it doesn’t
access the complete file, but accesses it page by page.
● Syntax:
less filename
● Options:
○-E : causes less to automatically exit the first time it reaches end of file.
○ -f : forces non-regular file to open.
○ -F : causes less to exit if entire file can be displayed on first screen
○ -g : highlight the string which was found by last search command
● Example:
less [Link]

7. cat : concatenate files and print on the standard output.


Syntax: cat <fileName>
● To create a file or overwrite content of the file: cat > filename
● To open a file: cat filename
● To append content to a file: cat>>filename
● To concatenate files: cat file1 file2

DEPARTMENT OF COMPUTER APPLICATIONS 14


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

8. cd : Linux cd command is used to change the current working directory ( i.e.,


in which the current user is working). The "cd" stands for 'change directory.'
● Syntax:
$ cd [directory]
cd ~ change to home directory

cd .. change to previous working directory

cd directoryname : move from one directory to its next directory.

DEPARTMENT OF COMPUTER APPLICATIONS 15


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

9. mkdir - make directories


Syntax: mkdir [options...] [directories ...]
● Options:
○ –version: It displays the version number, some information regarding
the license and exits.
○ –help: It displays the help related information and exits.
○ -p: A flag which enables the command to create parent directories as
necessary. If the directories exist, no error is specified.

10. pwd : print name of current working directory. It prints the path of the working
directory, starting from the root.

● Syntax:

○ pwd -L: Prints the symbolic path.

○ pwd -P: Prints the actual path.

11. find: The find command helps us to find a particular file within a directory. It is
used to find the list of files for the various conditions like permission, user ownership,
modification, date/time, size, and more.

Syntax: $ find [where to start searching from] [expression determines what to find] [-
options] [what to find]

DEPARTMENT OF COMPUTER APPLICATIONS 16


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

12. mv: mv stands for move. mv is used to move one or more files or directories from
one place to another in a file system like UNIX. It has two distinct functions:
(i) It renames a file or folder.
(ii) It moves a group of files to a different directory.
Syntax:
mv [Option] source destination
Example:
mv [Option] source destination

13. cp: cp stands for copy. This command is used to copy files or group of files or
directory. It creates an exact image of a file on a disk with different file name.
cp command require at least two filenames in its arguments.
Syntax:
cp [OPTION] Source Destination
● Example:

DEPARTMENT OF COMPUTER APPLICATIONS 17


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

14. rm: rm stands for remove here. rm command is used to remove objects such as
files, directories.
Syntax: rm[OPTION]... FILE...

15. tar : The Linux ‘tar’ stands for tape archive, is used to create Archive and extract the
archive files. tar command in Linux is one of the important command which
provides archiving functionality in Linux. We can use Linux tar command to
create compressed or uncompressed Archive files and also maintain and modify
them.
Syntax:
tar [options] [archive-file] [file or directory to be archived]

● Options:
○ -c : Creates Archive
○ -x : Extract the archive
○ -f : creates archive with given filename
○ -t : displays or lists files in archived file

16. wc : wc stands for word count. As the name implies, it is mainly used for counting
purpose. It is used to find out number of lines, word count, byte and characters
count in the files specified in the file arguments

DEPARTMENT OF COMPUTER APPLICATIONS 18


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

17. cut : The cut command in UNIX is a command for cutting out the sections
from each line of files and writing the result to standard output
Syntax:
cut OPTION... [FILE]...
● Options:
○ -b(byte): To extract the specific bytes, you need to follow -b option
with the list of byte numbers separated by comma.
○ -c (column): To cut by character use the -c option.
○ -f (field): -c option is useful for fixed-length lines.

18. paste: It is used to join files horizontally (parallel merging) by outputting lines
consisting of lines from each file specified, separated by tab as delimiter, to the
standard output
Syntax:paste [OPTION]... [FILES]...
● Options:
○ -d (delimiter): Paste command uses the tab delimiter by default for
merging the files.
○ -s (serial): We can merge the files in sequentially manner using the -s
option.

DEPARTMENT OF COMPUTER APPLICATIONS 19


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

19. head: 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.
Syntax: head [OPTION]... [FILE]...
● Options:
○ -n num: Prints the first ‘num’ lines instead of first 10 lines
○ -c num: Prints the first ‘num’ bytes from the file specified.
○ -q: It is used if more than 1 file is given.
○ -v: By using this option, data from the specified file is always preceded
by its file name.

20. tail: The tail command, as the name implies, print the last N number of data of the
given input. By default it prints the last 10 lines of the specified files.
Syntax: tail [OPTION]... [FILE]...
Options:
● -n num: Prints the last ‘num’ lines instead of last 10 lines.
● -c num: Prints the last ‘num’ bytes from the file specified.
● -q: It is used if more than 1 file is given.
● -v: By using this option, data from the specified file is always preceded by
its file name.

DEPARTMENT OF COMPUTER APPLICATIONS 20


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

21. grep: The grep filter searches a file for a particular pattern of characters, and displays
all lines that contain that pattern.
Syntax: grep [options] pattern [files]
● -i : Ignores, case for matching
● -l : Displays list of a filenames only.
● -n : Display the matched lines and their line numbers.
● -c : This prints only a count of the lines that match a pattern
● -w : Match whole word
● -o : Print only the matched parts of a matching line,
● with each such part on a separate output line.

22. expr: The expr command in Unix evaluates a given expression and displays its
corresponding output. It is used for:
○ Basic operations like addition, subtraction, multiplication, division, and
modulus on integers.
○ Evaluating regular expressions, string operations like substring, length of
strings etc.
Options:
○ –version : It is used to show the version information.

23. chmod: In Unix-like operating systems, the chmod command is used to change the
access mode of a [Link] name is an abbreviation of change mode.
Syntax: chmod [reference][operator][mode] file...
The references are used to distinguish the users to whom the permissions apply i.e.
they are list of letters that specifies whom to give permissions. The references are
represented by one or more of the following letters:

DEPARTMENT OF COMPUTER APPLICATIONS 21


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

24. Chown: Different users in the operating system have ownership and permission to
ensure that the files are secure and put restrictions on who can modify the
contents of the files. In Linux, there are different users who use the system:

● Root User: It is a superuser who has access to all the directories and
files in our system and it can perform any operation. An important
thing to note is that only the root user can perform changing of
permissions or ownerships of the files that are not owned by them.

● Regular User: These users have limited access to files and directories
and can only modify the file that they own.
Each user has some properties associated with them, such as a user ID and a home
directory. We can add users to a group to make the process of managing users easier.
A group can have zero or more users. A specified user can be associated with a
“default group”. It can also be a member of other groups on the system as well.
Ownership and Permissions: To protect and secure files and directories in Linux we
use permissions to control what a user can do with a file or directory. Linux uses three
types of permissions:
● Read: This permission allows the user to read files in directories, it
lets the user read directories and subdirectories stored in it.
● Write: This permission allows a user to modify and delete a file. Also,
it allows a user to modify its contents (create, delete, and rename files
in it) for the directories. Unless the execution permission is given to
directories changes do affect them.
● Execute: This permission on a file allows it to get executed. For
example, if we have a file named [Link] so unless we don’t give it
execute permission it won’t run.

Types of file permissions:


● User: This type of file permission affects the owner of the file.
● Group: This type of file permission affects the group which owns the file.
Instead of the group permissions, the user permissions will apply if the owner
user is in this group.
● Other: These types of file permission affect all other users on the system.

DEPARTMENT OF COMPUTER APPLICATIONS 22


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

25. Redirection and piping: Pipes and redirection are two different kinds of mechanisms
used in Linux. Sometimes, we need the output of a command to be passed as input of
another command and do some operation. There we use the pipe operator. The operator
is “|”. It’s found on top of the “Enter” key. Sometimes, we redirect or pass all the output
of a command to a file for storing purposes. Also, we take a file’s content as input for a
command. This is called redirection and operators are used like “>”, “>>” and “<”.

● Redirection:

● Piping

DEPARTMENT OF COMPUTER APPLICATIONS 23


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

26. useradd: useradd is a command in Linux that is used to add user accounts to your
system. It is just a symbolic link to adduser command in Linux and the difference
between both of them is that useradd is a native binary compiled with system
whereas adduser is a Perl script which uses useradd binary in the background. It
make changes to the following files:

/etc/passwd /etc/shadow

/etc/group /etc/gshadow

useradd [options] name_of_the_user

27. usermod: usermod command or modify user is a command in Linux that is used to
change the properties of a user in Linux through the command line. After creating a user
we have to sometimes change their attributes like password or login directory etc. so in
order to do that we use the Usermod command. The information of a user is stored in
the following files:
/etc/passwd
/etc/group
/etc/shadow
/etc/[Link]
/etc/gshadow
/etc/[Link]

28. userdel:userdel command in Linux system is used to delete a user account and related
files. This command basically modifies the system account files, deleting all the
entries which refer to the username LOGIN. It is a low-level utility for removing
the users.
Syntax : userdel [options] LOGIN

29. Passwd:passwd command in Linux is used to change the user account passwords. The
root user reserves the privilege to change the password for any user on the
system, while a normal user can only change the account password for his or her
own account.
Syntax: passwd [options] [username]

DEPARTMENT OF COMPUTER APPLICATIONS 24


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

30. df: The df command (short for disk free), is used to display information related to file
systems about total space and available space.
Syntax : df [OPTION]... [FILE]...

● Example:

31. top: top command is used to show the Linux processes. It provides a dynamic real-time
view of the running system. Usually, this command shows the summary information of
the system and the list of processes or threads which are currently managed by the Linux
Kernel. As soon as you will run this command it will open an interactive command
mode where the top half portion will contain the statistics of processes and resource
usage. And Lower half contains a list of the currently running processes.

● Example:

DEPARTMENT OF COMPUTER APPLICATIONS 25


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

[Link]: Linux provides us a utility called ps for viewing information related with the

processes on a system which stands as abbreviation for “Process Status”. ps command is

used to list the currently running processes and their PIDs along with some other

information depends on different options. It reads the process information from the

virtual files in /proc file-system. /proc contains virtual files, this is the reason it’s referred

as a virtual file system.

Syntax: ps [options]

Example:

DEPARTMENT OF COMPUTER APPLICATIONS 26


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT - 3

FILE SYSTEM COMPONENTS

It makes sense to explore the Linux filesystem from a terminal window, In fact, that is
the name of the first tool you’ll install to help you on the way: tree. If you are using
Ubuntu or Debian, you can do: sudo apt install tree

Once installed, stay in your terminal window and run tree like this: $ tree /

The / in the instruction above refers to the root directory. The root directory is the one
from which all other directories branch off from. When you run tree and tell it to start
with /, you will see the whole directory tree, all directories and all the subdirectories in
the whole system, with all their files, fly by.

If you have been using your system for some time, this may take a while, because, even
if you haven’t generated many files yourself, a Linux system and its apps are always
logging, caching, and storing temporary files. The number of entries in the file system
can grow quite quickly. Instead, try this: tree -L 1 /

Most Linux distributions will show you the same or a very similar layout to what you can see
in the image above. This means that even if you feel confused now, master this and you will

DEPARTMENT OF COMPUTER APPLICATIONS 27


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

have a handle on most, if not all, Linux installations in the whole wide world.
Now, let’s look at what each directory is used for. While we go through each, you can
peek at their contents using ls.
/bin
/bin is the directory that contains binaries, that is, some of the applications and
programs you can run. You will find the ls program mentioned above in this directory,
as well as other basic tools for making and removing files and directories, moving
them around, and so on. There are more bin directories in other parts of the file system
tree, but we’ll be talking about those in a minute.
/boot
The /boot directory contains files required for starting your system. If you mess up
one of the files in here, you may not be able to run your Linux and it is a pain to repair.
On the other hand, don’t worry too much about destroying your system by accident:
you have to have superuser privileges to do that.
/dev
/dev contains device files. Many of these are generated at boot time or even on the fly.
For example, if you plug in a new webcam or a USB pendrive into your machine, a
new device entry will automatically pop up here.
/etc
/etc is the directory where names start to get confusing. /etc gets its name from the
earliest Unixes and it was literally “et cetera” because it was the dumping ground for
system files administrators were not sure where else to put.
Nowadays, it would be more appropriate to say that etc stands for “Everything to
configure,” as it contains most, if not all system-wide configuration files.
For example, the files that contain the name of your system, the users and their passwords,
the
names of machines on your network and when and where the partitions on your hard
disks should be mounted are all in here. Again, if you are new to Linux, it may be best
if you don’t touch too much in here until you have a better understanding of how
things work.

DEPARTMENT OF COMPUTER APPLICATIONS 28


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

/home
/home is where you will find your users’ personal directories. In my case, under /home
there are two directories: /home/paul, which contains all my stuff; and /home/guest, in
case anybody needs to borrow my computer.
/lib
/lib is where libraries live. Libraries are files containing code that your applications
can use. They contain snippets of code that applications use to draw windows on your
desktop, control peripherals, or send files to your hard disk.
There are more lib directories scattered around the file system, but this one, the one
hanging directly off of / is special in that, among other things, it contains the all
important kernel modules. The kernel modules are drivers that make things like your
video card, sound card, WiFi, printer, and so on, work.
/media
The /media directory is where external storage will be automatically mounted when
you plug it in and try to access it. As opposed to most of the other items on this list,
/media does not hail back to 1970s, mainly because inserting and detecting storage
(pendrives, USB hard disks, SD cards, external SSDs, etc) on the fly, while a computer
is running, is a relatively new thing.
/mnt
The /mnt directory, however, is a bit of remnant from days gone by. This is where you
would manually mount storage devices or partitions. It is not used very often
nowadays.
/opt
The /opt directory is often where software you compile (that is, you build yourself
from source code and do not install from your distribution repositories) sometimes
lands. Applications will end up in the /opt/bin directory and libraries in the /opt/lib directory.

A slight digression: another place where applications and libraries end up in is


/usr/local, When software gets installed here, there will also be /usr/local/bin and
/usr/local/lib directories. What determines which software goes where is how the
developers have configured the files that control the compilation and installation
process.

DEPARTMENT OF COMPUTER APPLICATIONS 29


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

/proc
/proc, like /dev is a virtual directory. It contains information about your computer,
such as information about your CPU and the kernel your Linux system is running. As with
/dev, the files and directories are generated when your computer starts, or on the
fly, as your system is running and things change.
/root
/root is the home directory of the superuser (also known as the “Administrator”) of the
system. It is separate from the rest of the users’ home directories because you
are not meant to touch it. Keep your own stuff in you own directories, people.

/run
/run is another new directory. System processes use it to store temporary data for their
own nefarious reasons.
/sbin
/sbin is similar to /bin, but it contains applications that only the superuser (hence the
initial s) will need. You can use these applications with the sudo command that
temporarily concedes you superuser powers on many distributions. /sbin typically
contains tools that can install stuff, delete stuff and format stuff. As you can imagine,
some of these instructions are lethal if you use them improperly, so handle with care.

/usr

The /usr directory was where users’ home directories were originally kept back in the

early days of UNIX. However, now /home is where users kept their stuff as we saw

above. These days, /usr contains a mish-mash of directories which in turn contain

applications, libraries, documentation, wallpapers, icons and a long list of other stuff

that need to be shared by applications and services.

You will also find bin, sbin and lib directories in /usr. What is the difference with their

root-hanging cousins? Not much nowadays. Originally, the /bin directory (hanging off

of root) would contain very basic commands, like ls, mv and rm; the kind of

DEPARTMENT OF COMPUTER APPLICATIONS 30


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

commands that would come pre-installed in all UNIX/Linux installations, the bare

minimum to run and maintain a system. /usr/bin on the other hand would contain stuff

the users would install and run to use the system as a work station, things like word

processors, web browsers, and other apps.

But many modern Linux distributions just put everything into /usr/bin and have /bin

point to /usr/bin just in case erasing it completely would break something. So, while Debian,

Ubuntu and Mint still keep /bin and /usr/bin (and /sbin and /usr/sbin) separate; others,

like Arch and its derivatives just have one “real” directory for binaries, /usr/bin, and

the rest or *bins are “fake” directories that point to /usr/bin.

/srv

The /srv directory contains data for servers. If you are running a web server from your

Linux box, your HTML files for your sites would go into /srv/http (or /srv/www). If

you were running an FTP server, your files would go into /srv/ftp.

/sys

/sys is another virtual directory like /proc and /dev and also contains information from

devices connected to your computer.

In some cases you can also manipulate those devices. I can, for example, change the

brightness of the screen of my laptop by modifying the value stored in the


/sys/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-

1/intel_backlight/brightness file (on your machine you will probably have a different

file). But to do that you have to become superuser. The reason for that is, as with so

many other virtual directories, messing with the contents and files in /sys can be

dangerous and you can trash your system. DO NOT TOUCH until you are sure you

know what you are doing.

DEPARTMENT OF COMPUTER APPLICATIONS 31


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

/tmp

/tmp contains temporary files, usually placed there by applications that you are

running. The files and directories often (not always) contain data that an application

doesn’t need right now, but may need later on.

You can also use /tmp to store your own temporary files — /tmp is one of the few

directories hanging off / that you can actually interact with without becoming

superuser.

/var

/var was originally given its name because its contents was deemed variable, in that it

changed frequently. Today it is a bit of a misnomer because there are many other

directories that also contain data that changes frequently, especially the virtual

directories we saw [Link] that as it may, /var contains things like logs in the /var/log

subdirectories. Logs are files that register events that happen on the system. If something fails

in the kernel, it will be logged in a file in /var/log; if someone tries to break into your

computer from outside, your firewall will also log the attempt here. It also contains spools for

tasks.

These “tasks” can be the jobs you send to a shared printer when you have to wait

because another user is printing a long document, or mail that is waiting to be

delivered to users on the system .

Your system may have some more directories we haven’t mentioned above. In the

screenshot, for example, there is a /snap directory. That’s because the shot was

captured on an Ubuntu system. Ubuntu has recently incorporated snap packages as a

way of distributing software. The /snap directory contains all the files and the software

DEPARTMENT OF COMPUTER APPLICATIONS 32


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

installed from snaps.

/var/log/syslog contains lot of system related logfiles.

Figure 2: Standard Unix filesystem hierarchy.

DEPARTMENT OF COMPUTER APPLICATIONS 33


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

To explore the filesystem yourself, use the cd

command: cd

will take you to the directory of your choice (cd stands for change

directory. If you get confused,

pwd
cd with no options or parameters, will take you back to your own home directory, where
things are safe and cosy. Finally, cd .. will take you up one level, getting you one level closer
to the / root directory. If you are in /usr/share/wallpapers and run cd .., you will move up to
/usr/share To see what a directory contains, use ls or simply ls to list the contents of the
directory you
are in right now. And, of course, you always have tree to get an overview of what lays within

a directory. Try it on /usr/share — there is a lot of interesting stuff in there.


Although there are minor differences between Linux distributions, the layout for their
filesystems are mercifully similar. So much so that you could say: once you know one,

you know them all. And the best way to know the filesystem is to explore it. So go forth

with tree, ls, and cd into uncharted territory.

You cannot damage your filesystem just by looking at it, so move from one directory to

another and take a look around.

DEPARTMENT OF COMPUTER APPLICATIONS 34


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT – 4
LINUX COMMANDS EXPERIMENTS

Exercise 1
1. Create the above directory tree and enter necessary data into the [Link]
perform the following operations using linux utilities.

developer@ccfl6-pc18:~/MCA46/nsa $ mkdir -p Project34/Payroll Project34/Sales


developer@ccfl6-pc18:~/MCA46/nsa$ cd Project34/Payroll
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ touch [Link]
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ cd ..
developer@ccfl6-pc18:~/MCA46/nsa/Project34$ cd Sales
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales$ mkdir RegionA RegionB
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales$ cd RegionA
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales/RegionA$ touch [Link]
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales/RegionA$ cd ..
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales$ cd RegionB
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales/RegionB$ touch [Link]
[Link] [Link]

a)Copy [Link] to directories RegionA and RegionB.

developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales/RegionB$ cd ../../Payroll
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ cp [Link]
../Sales/RegionA
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ cp [Link]
../Sales/RegionB

DEPARTMENT OF COMPUTER APPLICATIONS 35


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

b) Save the file [Link] to RegionA under the name [Link]

developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ cd ../Sales/RegionB
developer@ccfl6-pc18:~/MCA46/nsa/Project34/ Sales/RegionB$ touch ../RegionA/[Link]
developer@ccfl6-pc18:~/MCA46/nsa/Project34/ Sales/RegionB $ cp [Link] .. / RegionA
/[Link]

c) Combine the contents of [Link] and [Link] into a new file [Link]
under payroll.

developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales/RegionB$ cd ../../Payroll
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ touch [Link]
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ cat > [Link]
Hello
How are you
Welcome to Linux
developer@ccfl6-pc18:~/MCA_B16MCA46/nsa/Project34/Payroll$ cat > [Link]
Linux can perform the following:
Display
Copy
Create
View
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Payroll$ cat [Link] [Link] >
[Link]

d) Get the count of the number of ordinary files in Sales directory.

developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales$ find -type f |wc -l


7

e) Find the list all *.dat files in Project34 directory

developer@ccfl6-pc18:~/MCA46/nsa/Project34$ find -name *.dat


./Payroll/[Link]
./Payroll/[Link]
./Payroll/[Link]
./Sales/RegionB/[Link]
./Sales/RegionB/[Link]
./Sales/RegionB/[Link]
./Sales/RegionB/[Link]
./Sales/RegionA/[Link]
./Sales/RegionA/[Link]

DEPARTMENT OF COMPUTER APPLICATIONS 36


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

f) Sort [Link] in the descending order of payment amount

developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales/RegionA$ cat >[Link]


60000
45000
50000
35000
^D
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales/RegionA$ sort -n -r [Link] -o
[Link]
60000
50000
45000
35000

g) Display the list of all files in the Sales directory in uppercase.

developer@ccfl6-pc18:~/MCA46/nsa/Project34$ cd Sales
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales$ find -type f | tr '[:lower:]' '[:upper:]'
./REGIONB/[Link]
./REGIONB/[Link]
./REGIONB/[Link]
./REGIONB/[Link]
./REGIONA/[Link]
./REGIONA/[Link]
./REGIONA/[Link]

h) Remove RegionB directory and its contents in one shot.

developer@ccfl6-pc18:~/MCA46/nsa/Project34$ cd Sales
developer@ccfl6-pc18:~/MCA46/nsa/Project34/Sales $ rm -r RegionB

DEPARTMENT OF COMPUTER APPLICATIONS 37


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Exercise 2

[Link] an employee file containing employee name , salary ,designation in


the descending order of salary.

->developer@ccfl6-pc46:~/Aromal$ cat>employee
Arun,12000,Manager
Varun,18000,Sales
Abhay,20000,Driver
Aromal,19000,Assistant

->developer@ccfl6-pc46:~/Aromal$ sort -t ',' -k2 -nr employee


Abhay,20000,Driver
Aromal,19000,Assistant
Varun,18000,Sales
Arun,12000,Manager

[Link] the largest file in the current directory. The final output should contain only the
filenames and the respective file sizes

->developer@ccfl6-pc46:~/Aromal$ find . -type f -exec du -h {} + | sort -rh | head -n 1


4.0K ./[Link]

3. From the output of a long directory listing display only the file permissions. Then
pipe this output to filter out any double lines & count the different permission types in
this directory.

-> developer@ccfl6-pc46:~/Aromal$ ls -l | cut -d ' ' -f 1 | sort | uniq -c


3 drwxr-xr-x
1 lrwxrwxrwx
22 -rw-r--r--
1 -rw--wxrwx
1 total

[Link] Find with –exec option to rename all .htm files to .html

->developer@ccfl6-pc46:~/S2MCA/nsa$ find -type f -name "*.htm" -exec mv {} {}l \;


->developer@ccfl6-pc46:~/S2MCA/nsa$ ls
[Link] cycle1qn1 cycle1qn2 [Link] [Link] [Link]

[Link] tr filter to encrypt using ROT13.(Every character should be replaced with the 13th chr in
the alphabetical order)

developer@ccfl6-pc46:~/S2MCA/nsa$ echo "Hello World" | tr 'A-Za-z' 'N-ZA-Mn-za-m'


Uryyb Jbeyq

[Link] Find command to print the list of all files in the current directory containing the

DEPARTMENT OF COMPUTER APPLICATIONS 38


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Word linux inside them.

developer@ccfl6-pc46:~/S2MCA/nsa$ find . -type f -exec grep -il "linux" {} +


./ab
./file2

[Link] grep filter and wc filter to get the count of ordinary files in the current
directory

developer@ccfl6-pc46:~/S2MCA/nsa$ ls -l | grep "^-" | wc -l

12

DEPARTMENT OF COMPUTER APPLICATIONS 39


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXERCISE – 3

Question 1
Enter the Linux command to create both a parent directory called ' NSA_lab' and it's
child directory called 'work' at the same time. Assume that directory ' NSA_lab' will
branch-off your home directory and that you are in your home directory to start.
Question 2
Enter a Linux command to create the empty file called 'labtest1' in the directory
'NSA_lab' (you are still in your home directory).
Question 3
Assume that your current directory contains the files 'labtest', 'labtest1', 'labtest2',
'labtest2a', 'labtest3', and 'labtest4'.
Issue a command to delete only the files 'labtest1' and 'labtest2'
Question 4
Assume that you are NOT currently in your home directory. Enter a command to copy all
files inyour home directory beginning with the letter 'a' to the current directory.
Question 5
Enter a command to delete all files that have filenames starting with 'labtest', except
'labtest' itself (Delete all files starting with 'labtest' followed by one or more characters).
Question 6
Enter a Linux command to remove a directory called 'assignments' and all of it's contents,
and allow the system to prompt the user to remove each file or directory.
Assume you are in the home directory, which happens to be the parent directory of
'assignments' directory.
Question 7
Here are two inverted-tree diagrams. Issue a command to change the left diagram to the
right diagram. Assume that you are in your home directory and use relative pathnames.
[home] is your home directory:

Question 8
Issue a command to delete all files in your current directory with 2-character names.

DEPARTMENT OF COMPUTER APPLICATIONS 40


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

DEPARTMENT OF COMPUTER APPLICATIONS 41


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT – 5

SHELL SCRIPT
1)Write a shell script to find the sum, the average and the product of the four
integers entered.

ALGORITHM
Step 1:Prompt the user to enter four numbers (a, b, c, and d).
Step2:Read and store the four numbers in variables 'a', 'b', 'c', and 'd'.
Step 3:Calculate the sum of the four numbers: 'Sum = a + b + c + d'.
Step 4:Display the sum: "Sum is: [Sum]".
Step 5:Calculate the average of the four numbers: 'Avg = Sum / 4'.
Step 6:Display the average: "Average is: [Avg]"
Step 7:Calculate the product of the four numbers: 'Prd = a * b * c * d'.
Step 8:Display the product: "Product of the four numbers: [Prd]".

PROGRAM CODE
#!/bin/bash
echo "enter the number:";
read a
echo "Enter the number : ";
read b
echo "Enter the number : ";
read c
echo "Enter the number : ";
read d
Sum=`expr $a + $b + $c + $d `
echo "sum is:" $Sum
Avg=`expr $Sum / 4 `
echo "avg is : " $Avg
Prd=`expr $a \* $b \* $c \* $d `
echo "product of 4 numbers: " $Prd

DEPARTMENT OF COMPUTER APPLICATIONS 42


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

OUTPUT

$ bash [Link]
Enter four integers:
5367
Sum: 21
Average: 5
Product: 630

2)
a) Write a program to check whether a number entered is odd or even.
b) Write a shell script to print given number in reverse order
c) Write a shell script to print sum of all digits of a given number

a)
ALGORITHM

Step 1: Prompt the user to enter a number and store it in the variable 'a'.
Step 2: Check if 'a' is even or odd:
If 'a' is even (i.e., 'a % 2 == 0'), display "[a] is even".
If 'a' is odd (i.e., 'a % 2 != 0'), display "[a] is odd".

PROGRAM CODE

#!/bin/bash
echo "enter the number:";
read a
if [ `expr $a % 2` == 0 ]
then
echo "$a is even"
else
echo "$a is odd"
fi

OUTPUT
$ bash [Link]
Enter a number: 422
422 is Even

DEPARTMENT OF COMPUTER APPLICATIONS 43


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

b)

ALGORITHM

Step1. Prompt the user to enter a number and store it in the variable 'number'.
Step 2. Initialize a variable 'temp' with the value 0. This variable will be used to store the
reverse
of the input number.
Step 3. Enter a while loop that continues as long as 'number' is greater than 0.
Step 4. Within the loop:
- Get the last digit of 'number' by finding the remainder when 'number' is divided by 10.
- Append the last digit to the 'temp' variable by multiplying 'temp' by 10 and then adding the
last digit.
- Remove the last digit from 'number' by dividing it by 10.
Step 5. Once the loop is complete, the 'temp' variable will contain the reversed number.
Step 6. Display the message "Reverse of the given number is [temp]".

PROGRAM CODE

echo "Enter a number"


read number
temp=0
while [ $number -gt 0 ]
do
temp=`expr $temp \* 10`
reverse=`expr $number % 10`
temp=`expr $temp + $reverse`
number=`expr $number / 10`
done
echo "Reverse of the given number is" $temp

OUTPUT

$ bash [Link]
Enter a number: 566
Reversed number is: 665

DEPARTMENT OF COMPUTER APPLICATIONS 44


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

c)

ALGORITHM

Step 1. Prompt the user to enter a number using the `echo` command and store it in the
variable
`num`.
Step 2. Initialize the variable `sum` to 0, which will be used to accumulate the sum of digits.
Step 3. Use a `while` loop with the condition `[ $num -gt 0 ]` to iterate as long as the value of
`num` is greater than 0.
Step 4. Inside the loop:
a. Calculate the last digit of the number by taking the modulus (`mod`) of `num` with 10.
b. Add the last digit (`mod`) to the `sum` variable.
c. Update the value of `num` by removing the last digit using integer division (`num=$((num
/ 10))`).
Step 5. After the `while` loop ends (when `num` becomes zero), print the value of `sum`,
which
represents the sum of the digits of the original number.

PROGRAM CODE

#!/bin/bash
echo "Enter a Number:"
read num
sum=0
while [ $num -gt 0 ]
do
mod=$((num % 10))
sum=$((sum + mod))
num=$((num / 10))
done
echo $sum

OUTPUT
$ bash [Link]
Enter a number:
777
Sum of digits: 21

DEPARTMENT OF COMPUTER APPLICATIONS 45


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

3) Write a shell script that accepts any year from the keyboard and determine
whether the year is a leap year or not.

ALGORITHM

Step [Link] the user to enter a year using the `echo` command and store it in the variable
`year`.
Step 2. Use the expression ``expr $year % 4`` to calculate the remainder when the year is
divided by 4.
Step 3. Use the conditional `if` statement to check if the remainder is equal to 0. If it is, then
the year is divisible by 4, and we proceed to the `then` block.
Step 4. Inside the `then` block, print "`$year is a leap year`" using the `echo` command,
indicating that the entered year is a leap year.
Step 5. If the remainder is not equal to 0 (i.e., the year is not divisible by 4), the `else` block
is
executed.
Step 6. Inside the `else` block, print "`$year is not a leap year`" using the `echo` command,
indicating that the entered year is not a leap year.

PROGRAM CODE

#!/bin/bash
echo "Enter a year:"
read year
if [ `expr $year % 4` == 0 ]
then
echo "$year is a leap year"
else
echo "$year is not a leap year"
fi
OUTPUT
$ bash [Link]
Enter a year:
2023
2023 is not a leap year
$ bash [Link]
Enter a year:
2024
2024 is a leap year

DEPARTMENT OF COMPUTER APPLICATIONS 46


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

4) Write a shell script to find the factorial of a number.

ALGORITHM

Step 1. Prompt the user to enter a number and read the input into the variable `num`.
Step 2. Initialize the variable `fact` to 1.
Step 3. Use a `while` loop with the condition `[ $num -gt 1 ]` to calculate the factorial. The
loop will continue as long as `num` is greater than 1.
Step 4. Inside the loop, multiply the current value of `fact` with `num` and store the result
back
in the `fact` variable.
Step 5. Decrement the value of `num` by 1.
Step 6. After the `while` loop ends (when `num` becomes 1), print the value of `fact`, which
represents the factorial of the original number.

PROGRAM CODE

#!/bin/bash
echo "Enter a number:"
read num
fact=1
while [ $num -gt 1 ]
do
fact=$((fact * num))
num=$((num - 1))
done
echo "Factorial is:"$fact

OUTPUT
$ bash [Link]
Enter a number:
5
Factorial is : 120

DEPARTMENT OF COMPUTER APPLICATIONS 47


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

5) Write a program to print prime numbers from 1 to 100

ALGORITHM

Step 1. Use a `for` loop to iterate through numbers from 2 to 100, stored in the variable
`num`.
Step 2. Initialize the variable `is_prime` to `true`.
Step 3. Use a nested `for` loop with the variable `i` to check for factors of `num` from 2 to
`num/2` (integer division). The loop will continue as long as `i` is less than `num/2`
Step 4. Inside the nested loop:
a. Check if `num` is divisible by `i` using the expression `expr $num % $i -eq 0`.
b. If `num` is divisible by `i`, set `is_prime` to `false`, indicating that it is not a prime number.
c. Break out of the loop since we have already determined that the number is not prime.
Step 5. After the nested loop, check if `is_prime` is still `true`.
a. If `is_prime` is `true`, then `num` is a prime number since it had no factors other than 1
and itself.
b. In this case, print the value of `num` using the `echo` command.
Step 6. The outer `for` loop will continue to the next number until all numbers from 2 to 100
have been checked.

PROGRAM CODE
#!/bin/bash
for num in {2..100}
do
is_prime=true
for ((
i=2;
i<num/
2; i++
)) do
if [ `expr
$num % $i
` -eq 0 ]
then
is_prime=false
break
fi
done
if $is_prime
then
echo $num
fi
done

DEPARTMENT OF COMPUTER APPLICATIONS 48


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

OUTPUT

$ bash [Link]
Prime numbers from 1 to 100:
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

DEPARTMENT OF COMPUTER APPLICATIONS 49


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

6) Write a script for printing Numbers in ascending order

ALGORITHM

Step 1. Display the list of numbers: Use the `echo` command to print the list of numbers
separated by spaces.
Step 2. Print a message: Use the `echo` command to print a message indicating that the
following numbers will be displayed in ascending order.
Step 3. Use a `for` loop to iterate over each number in the list: The numbers in the list are
hardcoded, with `i` taking one value at a time from the list `45 -12 60 12 0`.
Step 4. Inside the loop, print the value of the current number (`i`) to the terminal using the
`echo` command.
Step 5. Use a pipeline (`|`) to send the output of the loop (the list of numbers) to the `sort`
command with the `-n` option: The `sort -n` command performs a numeric sort, ensuring that
the numbers are sorted correctly.
Step 6. The sorted numbers will be displayed on the terminal.

PROGRAM CODE

#!/bin/bash
echo "The number is : 45 -12 60 12 0 "
echo "In ascending order:"
for i in 45 -12 60 12 0;
do
echo "$i";
done |sort -n

OUTPUT
$ bash [Link]
The number is : 45 -12 60 12 0
In ascending order:
-12
0
12
45
60

DEPARTMENT OF COMPUTER APPLICATIONS 50


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

7) Write a shell script which displays a list of files in the current directory to
which we have read, write and execute permissions.

ALGORITHM

Step1. Print the message "files which have read, write, and execution permissions."
Step 2. Start iterating through each item in the current directory using the wildcard `*`.
Step 3. For each item, check if it is a regular file.
Step 4. If it is a regular file, check if it has read, write, and execute permissions.
Step 5. If the file has all three permissions, then print its details using `ls -l`.
Step [Link] the loop until all items in the directory have been processed.
PROGRAM CODE

echo "files which have read ,write,and execution permissions" for file in *
do
if [ -f $file ]
then
if [ -r $file -a -w $file -a -x $file ]
then
ls -l $file
fi
fi
done

OUTPUT
$ bash [Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]

DEPARTMENT OF COMPUTER APPLICATIONS 51


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

8) Write a shell script to find the number of occurrences of a particular digit in a


given number.

ALGORITHM
Step1. Initialize a counter variable `c` to zero.
Step 2. Prompt the user to enter a number and store it in the variable `num`.
Step 3. Prompt the user to enter the digit whose occurrence needs to be found and store it in
the variable `digit`.
Step 4. Enter into a loop that continues until `num` becomes zero.
Step 5. In each iteration of the loop, extract the last digit of `num` using modulo (`%`) and
store it in the variable `rem`.
Step 6. Check if the extracted digit `rem` is equal to the specified `digit`.
Step 7. If the extracted digit matches the specified digit, increment the counter `c`.
Step 8. Divide `num` by 10 to remove the last digit, effectively moving to the next digit for
the next iteration.
Step 9. Continue the loop until all digits of `num` have been processed.
Step 10. After the loop, print the total number of occurrences of the specified digit.

PROGRAM CODE

#!/bin/bash

echo "Enter a number:"

read num

echo "Enter the digit to find:"

read digit

count=0

while [ $num -gt 0 ]

do

i=$(( num % 10 ))

if [ $i -eq $digit ]; then

(( count++ ))

DEPARTMENT OF COMPUTER APPLICATIONS 52


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

fi

num=$(( num / 10 ))

done

echo "$digit appears $count times"

OUTPUT

$ bash [Link]
Enter a number:
644564
Enter the digit to find:
4
4 appears 3 times

DEPARTMENT OF COMPUTER APPLICATIONS 53


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

9) Write shell script to print alternate digits when a 7 digit number is passed as
input. (Eg: Input: 1234567, Ans: 1,3,5,7)

ALGORITHM

Step1. Prompt the user to enter a 7-digit number and store it in the variable `number`.
Step 2. Initialize a variable `n` to 1, which will be used to keep track of the position of the
digit
to extract.
Step 3. Enter into a loop that continues until `n` is greater than 7 (the total number of digits in
the input number).
Step 4. In each iteration of the loop, extract the `n`-th digit from the input number using the
`cut` command and store it in the variable `a`.
Step 5. Print the extracted digit without a newline character (using `echo -n` to avoid
newlines).
Step 6. Increment `n` by 2 to move to the next position for the next iteration.
Step 7. Continue the loop until every second digit has been extracted and printed.
Step 8. Print a newline character to move to the next line after the loop.

PROGRAM CODE

#!/bin/bash
echo "enter 7 digit number"
read number
n=1
echo "ANS:"
while((n<=7))
do
a=`echo $number | cut -c $n`
echo -n " $a"
n=`expr $n + 2`
done
echo "

OUTPUT

$ bash [Link]
Enter a 7 digit number:
6472915
Alternate numbers are :
6795

DEPARTMENT OF COMPUTER APPLICATIONS 54


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

10) Write a shell script that takes a command line argument and displays the details
depending on whether the argument is a directory, a file, or something else.

ALGORITHM

Step 1. Prompt the user to enter a file name and store it in the variable `file`.
Step 2. Check if the entered `file` name corresponds to a regular file using the `-f` test.
Step 3. If the entered `file` is a regular file, print the message "`file` is a file."
Step 4. If the entered `file` is not a regular file, check if it corresponds to a directory using the
`-d` test.
Step 5. If the entered `file` is a directory, print the message "`file` is a directory."
Step 6. If the entered `file` is neither a regular file nor a directory, print the message "`file` is
something else."

PROGRAM CODE

echo "enter file name: "


read file
if [ -f $file ]
then
echo " $file is a file "
elif [ -d $file ]
then
echo " $file is a directory "
else
echo " $file is something else"
fi
OUTPUT
$ bash [Link] test_dir
test_dir is a directory

$ bash [Link] [Link]


[Link] is a file

$ bash [Link] shell


shell is something else

DEPARTMENT OF COMPUTER APPLICATIONS 55


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

11) Write a shell script that accepts a filename, starting line number and ending
line number as arguments and displays all the lines between the given line
numbers.

ALGORITHM

Step1. Prompt the user to enter a file name and store it in the variable `file`.
Step 2. Prompt the user to enter the starting line number and store it in the variable `s`.
Step 3. Prompt the user to enter the ending line number and store it in the variable `e`.
Step 4. Use the `sed` command to print the lines within the range from `s` to `e` (both
inclusive)
from the file specified by `file`.
Step 5. The `-n` option in `sed` tells it not to print the lines by default. The `$s,$e\p` specifies
the range of lines to be printed (`$s` is the starting line number, `$e` is the ending line
number,
and `\p` is used to print the lines within that range).
Step 6. The output displays the lines from the specified file within the specified range.

PROGRAM CODE

echo "Enter file name:"


read file
echo "Enter starting line:"
read s
echo "Enter the ending line:"
read e
echo "the lines are: "
sed -n $s,$e\p $file

DEPARTMENT OF COMPUTER APPLICATIONS 56


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

OUTPUT

$ cat [Link]
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

$ bash [Link] [Link] 3 7


Line 3
Line 4
Line 5
Line 6
Line 7

DEPARTMENT OF COMPUTER APPLICATIONS 57


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

12)Write a shell script that deletes all lines containing a specified word in one or
more files supplied as arguments to it.

ALGORITHM

Step 1: Read the first command-line argument and store it in the variable word.
Step 2: Shift the positional parameters so that $@ now contains only the list of files.
Step 3: For each file in the list:

 a. Check if the file exists using -f.


 b. If the file exists, use the sed -i "/$word/d" command to delete all lines that
contain the word (case-sensitive).
 c. Display a message indicating that the file was updated.
 d. If the file does not exist, display an error message stating that the file was not
found.

PROGRAM CODE

#!/bin/bash

word=$1

shift

for file in "$@"; do

if [ -f "$file" ]; then

sed -i "/$word/d" "$file"

echo "Updated $file"

else

echo "$file not found!"

fi

done

DEPARTMENT OF COMPUTER APPLICATIONS 58


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

OUTPUT

$ cat >[Link]
apple pie
banana pie
cherry pie
apple tart

$ cat >[Link]
apple strudel
blueberry pie
apple crumble

$ bash [Link] apple [Link] [Link]


Updated [Link]
Updated [Link]

$ cat [Link]
banana pie
cherry pie

$ cat [Link]
blueberry pie

DEPARTMENT OF COMPUTER APPLICATIONS 59


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

13) Write a shell script that computes the gross salary of an employee according
to the following:
a. if basic salary is <1500 then HRA 10% of the basic salary and DA =90% of the basic
salary
b. if basic salary is >1500 then HRA 500 and DA =98% of the basic salary (The basic salary
is entered interactively through the keyboard)

ALGORITHM

Step 1. Prompt the user to enter the basic salary and read the input into the variable `bsal`.
Step 2. Check if the `bsal` is less than 1500. If it is, calculate the gross salary using the
formula:
`gsal = bsal + (bsal/100)*10 + (bsal/100)*90`.
Step 3. If `bsal` is greater than or equal to 1500, calculate the gross salary using the formula:
`gsal = (bsal + 500) + (bsal/100)*98`.
Step 4. Display the calculated gross salary to the user.

PROGRAM CODE

echo "enter basic salary"


read bsal
if [ $bsal -lt 1500 ]
then
gsal=$((bsal+((bsal/100)*10)+(bsal/100)*90))
echo "the gross salary:$gsal"
fi
if [ $bsal -ge 1500 ]
then
gsal=$(((bsal+500)+(bsal/100)*98))
echo "the gross salary:$gsal"
fi

OUTPUT
$ bash [Link]
Enter the basic salary: 30000

hra = Rs. 500


da = Rs. 29400
Gross Salary = Rs. 59900

DEPARTMENT OF COMPUTER APPLICATIONS 60


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

14) Write a shell script to prepare a marklist of the students along with their grade.
(Inputs: Name, RegNo, Marks in 5 subjects)

ALGORITHM

Step 1: Prompt the user to enter the student's name and read it into the variable name.

Step 2: Prompt the user to enter the student's register number and store it in regno.

Step 3: Prompt the user to enter marks for 5 subjects and store them in variables m1, m2, m3,
m4, and m5.

Step 4: Calculate the total marks by adding all 5 subject marks and store the result in the
variable total.

Step 5: Calculate the average marks by dividing the total by 5 and store it in average.

Step 6: Determine the grade based on the average marks using conditional checks:

 If average is 90 or above, grade is A+


 If average is 80 to 89, grade is A
 If average is 70 to 79, grade is B
 If average is 60 to 69, grade is C
 If average is 50 to 59, grade is D
 If average is below 50, grade is Fail

Step 7: Display the marklist with the following details:

PROGRAM CODE

#!/bin/bash
echo "Enter Student Name:"
read name
echo "Enter Register Number:"
read regno
echo "Enter marks for 5 subjects:"
read m1
read m2
read m3
read m4

DEPARTMENT OF COMPUTER APPLICATIONS 61


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

read m5
total=$((m1 + m2 + m3 + m4 + m5))
average=$((total / 5))
if [ $average -ge 90 ]; then
grade="A+"
elif [ $average -ge 80 ]; then
grade="A"
elif [ $average -ge 70 ]; then
grade="B"
elif [ $average -ge 60 ]; then
grade="C"
elif [ $average -ge 50 ]; then
grade="D"
else
grade="Fail"
fi
echo "---------------------------"
echo "Student Marklist"
echo "Name: $name"
echo "Register Number: $regno"
echo "Total Marks: $total"
echo "Average Marks: $average"
echo "Grade: $grade"
echo "---------------------------"
Output
$ bash [Link]
Enter Student Name:
Sreya P
Enter Register Number:
412106
Enter marks for 5 subjects:
87

DEPARTMENT OF COMPUTER APPLICATIONS 62


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

85
91
92
86
---------------------------
Student Marklist
Name: Sreya P
Register Number: 412106
Total Marks: 441
Average Marks: 88
Grade: A

DEPARTMENT OF COMPUTER APPLICATIONS 63


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

15)Write a shell script to update bank account details using case construct.
(Menu options are Deposit and Withdraw).

ALGORITHM

Step 1: Set balance to 10000.

Step 2: Show menu:

1. Deposit
2. Withdrawal
3. Display
4. Exit

Step 3: Repeat the steps below:

 Step 4: Ask the user to enter a choice.


 Step 5: If choice is 1, ask for deposit amount and add it to balance.
 Step 6: If choice is 2, ask for withdrawal amount.
If amount > balance, show "Insufficient Balance".
Else, subtract from balance.
 Step 7: If choice is 3, display current balance.
 Step 8: If choice is 4, show "Thank you!" and exit.
 Step 9: If choice is invalid, show "Invalid Option".

PROGRAM CODE

bal=10000
echo "Bank Operation"
echo "1. Deposit"
echo "2. Withdrawal"
echo "3. Display"
echo "4. Exit"

while true; do
echo -n "Enter your choice: "
read ch
case $ch in
1) echo -n "Enter deposit amount: "
read dep
bal=$((bal + dep))
echo "Balance Updated <3"

DEPARTMENT OF COMPUTER APPLICATIONS 64


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

echo ""
;;
2) echo -n "Enter withdrawal amount: "
read with
if [ $with -gt $bal ]; then
echo "Insufficient Balance!!!"
echo ""
continue
fi
bal=$((bal - with))
echo "Balance Updated <3"
echo ""
;;
3) echo "Balance = $bal"
echo ""
;;
4) echo "Thank you!"
echo ""
exit
;;
*) echo "Invalid Option!"
echo ""
;;
esac
done

DEPARTMENT OF COMPUTER APPLICATIONS 65


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

OUTPUT

$ bash [Link]
Bank Operation
1. Deposit
2. Withdrawal
3. Display
4. Exit
Enter your choice: 3
Balance = 10000

Enter your choice: 1


Enter deposit amount: 500
Balance Updated <3

Enter your choice: 3


Balance = 10500

Enter your choice: 2


Enter withdrawal amount: 600
Balance Updated <3

Enter your choice: 3


Balance = 9900

Enter your choice: 2


Enter withdrawal amount: 10000
Insufficient Balance!!!

Enter your choice: 4


Thank you!

DEPARTMENT OF COMPUTER APPLICATIONS 66


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT-6

INSTALLING LAMPSTACK ON DEBIAN LINUX

Step 1: Update Package Repository Cache


Before you begin:
1. Open the terminal either by using the CTRL+ALT+T keyboard shortcut or by
searching for the word terminal in Ubuntu
2. Make sure to update the package repository cache to ensure it installs the latest
versions of the software. To do so, type in the following command:

sudo apt-get update

Step 2: Install Apache


1. To install Apache, run the following command in the terminal:
sudo apt-get install apache2

DEPARTMENT OF COMPUTER APPLICATIONS 67


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Press y (yes) and hit ENTER to permit the installation.


2. To ensure Apache is running, enter the Localhost of your server in the address bar
and press ENTER.
The test Apache web server page should display as below.

Step 3: Install PHP


1. To install PHP, run the following command:
$ sudo apt-get install php7.4

DEPARTMENT OF COMPUTER APPLICATIONS 68


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Press y and ENTER to allow the installation.


Step 4: Restart Apache
After the php installation you must restart the Apache service.
Enter the command:
$ sudo /etc/init.d/apache2 restart
Step 5: Test PHP Processing on Web Server
1. Create a basic PHP script and save it to the “web root” directory. This is necessary
for Apache to find and serve the file correctly. This directory is located
at /var/www/html/.
To create a file in that directory, type in the following command:
sudo nano /var/www/html/[Link]

This command opens the bank file.


2. Inside the file, type in the valid PHP code:

<?php
Echo “ test php ”;
?>

DEPARTMENT OF COMPUTER APPLICATIONS 69


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

3. Press CTRL + X to save and close the file. Press y and ENTER to confirm.
4. Then check the code are run currectly in [Link] the browser enter the
Ip address (localhost/[Link]).
It show the below image

Step 6: Install Mysql server


1. To install Mysql server, run the following command:
$ sudo apt-get install mysql-server

DEPARTMENT OF COMPUTER APPLICATIONS 70


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

2. Then it’s asking us for a root password . enter the password . Again we get to
repeat it
Step 7: Check the Mysql server
1. To check Mysql server, run the following command
$ mysql -u root -p
• Enter the root password and press enter

DEPARTMENT OF COMPUTER APPLICATIONS 71


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

2 . Create a database testdb and show it


• Enter the command
Create database testdb;
Show databases;
• So mysql is working then exit the mysql prompt just enter exit;

Step 8: Install PHP Myadmin


1. To install PHP Myadmin, run the following command:
$ sudo apt-get install phpMyAdmin

Press y and ENTER to allow the installation


2. Then its ask what type of server, we have Apache2 is set by default that’s what we
want then press ok
3. Then a configuration prompt are open . here we’re going to just choose yes and then it
ask the input password for phpmyadmin
4. Then check it currect . go to the localhost/phpmyadmin. Here we can not found it so
We have to actually edit the file php is located in Apache2 folder.
5. Enter the following command to edit the file
$ sudo nano/etc/php7.4/[Link]
6. Then we need to uncomment an extension=[Link]. find it the file just remove
the Semicolon.
7. Then enter ctl+x to save

DEPARTMENT OF COMPUTER APPLICATIONS 72


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Step 9: Restart Apache


After the php installation you must restart the Apache service.
Enter the command:
$ sudo /etc/init.d/apache2 restart

Step 9.1: Include phpmyadmin in apache configuration


1. Enter the command:
$ sudo nano/etc/apache2/[Link]
2. Type the following command to the nano editor Include
/etc/phpmyadmin/[Link]
3. Then enter ctl+x to save
4. Then again restart the apache

DEPARTMENT OF COMPUTER APPLICATIONS 73


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT-7

Laravel installation On Debian Linux with Apache

Step 1 – Install Apache Web Server

Let’s open up a Terminal and do first thing first update your package list using
Sudo apt update command.
$ sudo apt update
After updating your package list install apache webserver
$ sudo apt install apache2 $ systemctl status apache2

Now, check the status of apache server whether it is running or not

If the Apache server not running then use the following command to start apache
serve and add to boot startup.
$ systemctl start apache2
$ systemctl enable apache2

DEPARTMENT OF COMPUTER APPLICATIONS 74


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Open browser, goto localhost and check if default apache server page is available or
Not

Step 2 – Install and Configure PHP 7.4

To install Laravel 8.x, at least you must have PHP >= 7.3 on your system. And by
default, the official Ubuntu 20.04 repository provides PHP 7.4 packages. Install
PHP 7.4 packages using the apt command below.

DEPARTMENT OF COMPUTER APPLICATIONS 75


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Now go ahead and make tweak changes in PHP ini file and set cgi.fix_pathinfo set to
be 0. If this number is kept as a 1, the php interpreter will do its best to process the file
that is as near to the requested file as possible. This is a possible security risk. If this
number is set to 0, conversely, the interpreter will only process the exact file path—a
much safer alternative.
$ cd /etc/php/7.4/apache2
$ sudo nano [Link]
Press ctrl+w and search for the word “[Link]” the uncomment the line and set it to 0.
.cgi.fix_pathinfo=0

DEPARTMENT OF COMPUTER APPLICATIONS 76


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Press Ctrl + x then y to Save and Exit.


Now Restart The apache service.
$ systemctl restart apache2

Step 3 – Install Composer PHP Packages Management

Install the composer package manager go ahead and download and install
Composer. and move the composer .phar file to usr/local/bin/composer directory.
$ sudo apt install curl
$ curl -sS [Link] | php
$ sudo mv [Link] /usr/local/bin/composer

DEPARTMENT OF COMPUTER APPLICATIONS 77


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Step 4 – Install Laravel 8.x on Ubuntu 20.04

Now install Laravel Framework using composer, just type composer global require
Laravel/installer It will take a while to complete download its dependencies.

As you had seen above image, all packages have been installed on the
‘~/.config/composer’ directory. Next, we need to add the ‘bin’ directory to the
PATH environment through the ~/.bashrc configuration. So Now Edit the ~/.bashrc
configuration using nano command.
$ nano ~/.bashrc
And add the following line at the end of the file.
..export PATH="$HOME/.config/composer/vendor/bin:$PATH"

DEPARTMENT OF COMPUTER APPLICATIONS 78


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Press Ctrl + x then y to Save and Exit.


Now reload your bashrc configuration using the source command.
$ source ~/.bashrc
Now echo $PATH. It will return your “Bin” directory path for the Composer
package.
$ echo $PATH

The ‘bin’ directory for the composer packages has been added to the $PATH
environment variable. And as a result, you can use the command ‘laravel’ to start
and create a new project. Now go ahead and type Laravel new then your project name
to start a new Laravel project.
$ laravel new myapp1
This will take a while to download all dependencies required by Laravel.

Here you can see the installation of my new project myapp1 finished. You can also
see inside my home directory a new directory has been created with my project name.

DEPARTMENT OF COMPUTER APPLICATIONS 79


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Step 5 – Finally Configure Apache for Laravel and test it


First, add your project directory to www-data group use the following command
$ sudo chgrp -R www-data /home/ebin/myapp1
-R flag is recursive, Recursive means all subdirectory and files under your project
directory become changed to the “www-data” group.
Also, you need to change access permission 775 of the storage directory under your
project. So, go ahead and use the following command.
$ sudo chmod -R 775 /home/ebin/myapp1/storage

$ cd /etc/apache2/sites
available/ $ sudo nano
[Link]
And paste the following line inside the file.
<VirtualHost *:80>
ServerName [Link]
ServerAdmin admin@[Link]
DocumentRoot /home/ebin/myapp1/public
<Directory /home/ebin/myapp1>
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/[Link]
CustomLog ${APACHE_LOG_DIR}/[Link] combined
</VirtualHost>

DEPARTMENT OF COMPUTER APPLICATIONS 80


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

//All Red colored text must be changed as per your//

Now enable mod rewrite for apache2 just type


$ sudo a2enmod rewrite
Now enable your site, just type
$ sudo a2ensite [Link]
Finally, Restart the apache service, type
$ systemctl restart apache2

DEPARTMENT OF COMPUTER APPLICATIONS 81


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

As you are in a local environment you need a local dns resolver for your site. Go
ahead and edit /etc/hosts file, add a dns record for your site then save the file.
$ sudo nano /etc/hosts
...[Link] [Link]

Now get back to the web browser and open a tab then type your project hostname.
And here it is it’s working. Here you can see the Laravel version and PHP version.

DEPARTMENT OF COMPUTER APPLICATIONS 82


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT-8

NETWORKING COMMANDS PING COMMAND

PING COMMAND
PING (Packet Internet Groper) command is used to check the network connectivity between
host and server/host. This command takes as input the IP address or the URL and sends a data
packet to the specified address with the message “PING” and get a response from the
server/host this time is recorded which is called latency. Fast ping low latency means faster
connection. Ping uses ICMP(Internet Control Message Protocol) to send an ICMP echo
message to the specified host if that host is available then it sends ICMP reply message.
Ping is generally measured in millisecond every modern operating system has this ping pre-
installed.
Syntax: ping [OPTIONS] DESTINATION

TRACEROUTE COMMAND
Traceroute command in Linux prints the route that a packet takes to reach the host.
This command is useful when you want to know about the route and about all the hops
that a packet takes. Below image depicts how traceroute command is used to reach the
Google ([Link]) host from the local machine and it also prints detail about all
the hops that it visits in between.
Syntax: traceroute [options] host_Address[pathlength]

DEPARTMENT OF COMPUTER APPLICATIONS 83


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

ROUTE COMMAND
route command in Linux is used when you want to work with the IP/kernel routing
table. It is mainly used to set up static routes to specific hosts or networks via an
interface. It is used for showing or update the IP/kernel routing table.
Syntax: route

NSLOOKUP COMMAND
nslookup (stands for “Name Server Lookup”) is a useful command for getting
information from DNS server. It is a network administration tool for querying the
Domain Name System (DNS) to obtain domain name or IP address mapping or any
other specific DNS record. It is also used to troubleshoot DNS related problems.
Syntax: nslookup [option]

DEPARTMENT OF COMPUTER APPLICATIONS 84


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

IFCONFIG COMMAND
ifconfig(interface configuration) command is used to configure the kernel-resident
network interfaces. It is used at the boot time to set up the interfaces as necessary.
After that, it is usually used when needed during debugging or when you need system
tuning. Also, this command is used to assign the IP address and netmask to an interface
or to enable or disable a given interface.
Syntax:
ifconfig [... OPTIONS] [INTERFACE]

DEPARTMENT OF COMPUTER APPLICATIONS 85


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT- 9

INTRODUCTION TO WIRESHARK

Wireshark is an open-source packet analyzer, which is used for education,


analysis, software development, communication protocol development, and
network troubleshooting. It is used to track the packets so that each one is
filtered to meet our specific needs. It is commonly called as a sniffer, network
protocol analyzer, and network analyzer. It is also used by network security
engineers to examine security problems.
FEATURES OF WIRESHARK
❑Available for UNIX and Windows.

❑Capture live packet data from a network interface.


❑Display packets with very detailed protocol information.

❑Save packet data captured.


❑Filter packet data on our criteria.

❑Colorize packet data on our criteria.


❑Export some or all packet data in a number of capture file formats.

DEPARTMENT OF COMPUTER APPLICATIONS 86


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

DEPARTMENT OF COMPUTER APPLICATIONS 87


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

HOW TO RETRIEVE WEB PAGES USING HTTP AND WIRESHARK TO


CAPTURE THE PACKETS:-

1. Start up your web browser.


2. Start up the Wireshark packet sniffer (but don’t yet begin packet capture).
• Enter “http” (just the letters, not the quotation marks) in the display-filter
specification window, so that only captured HTTP messages will be displayed later
in the packet-listing window.
3. Wait a bit more than one minute (we’ll see why shortly), and then begin
Wireshark packet capture.
4. Enter the following to your browser
TCP OR [Link] == [Link] .
Your browser should display the webpage.
5. Stop Wireshark packet capture.

DEPARTMENT OF COMPUTER APPLICATIONS 88


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

Your Wireshark window should look similar to the window shown in below

DEPARTMENT OF COMPUTER APPLICATIONS 89


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

EXPERIMENT-10

INTRODUCTION TO VIRTUAL BOX

Creating a Virtual Machine

1. Install VirtualBox .

If you don't already have VirtualBox installed on your Windows or Mac computer,
you'll need to install it before proceeding.
Following are the steps required to install VirtualBox(Oracle VM VirtualBox):
You can download the latest version of VirtualBox from the Virtual Box website:
[Link] according to the version of your
operating system Windows, Mac or Linux.
1.1. Click Next

To Install VirtualBox – Setup Wizard

DEPARTMENT OF COMPUTER APPLICATIONS 90


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

1.2. Click Next

To Install VirtualBox – Custom Setup

To Install VirtualBox – Features Selection

DEPARTMENT OF COMPUTER APPLICATIONS 91


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

1.4 Click “Yes

To Install VirtualBox – Network Interfaces Warning

1.5 Click “Install”

Installation of Oracle VM VirtualBox – Ready to Install

DEPARTMENT OF COMPUTER APPLICATIONS 92


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

1.a. Click “Install”

Installation of Oracle VM VirtualBox- Serial Bus Software Installation

1.b. Click “Install”

Installation of Oracle VM VirtualBox – Network Service Installation

DEPARTMENT OF COMPUTER APPLICATIONS 93


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

1.c. Click “Install”

Installation of Oracle VM VirtualBox – Network Adapters Installation

1.d. Click “Finish

DEPARTMENT OF COMPUTER APPLICATIONS 94


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

2. Open VirtualBox. Double-click (or click once on a Mac) the VirtualBox app icon.
3. Click New. It's a blue badge in the upper-left corner of the VirtualBox window.

4. Enter a name for your virtual machine. Type whatever you want to name your
virtual machine (e.g., Ubuntu) into the "Name" text field that's near the top of the
pop-up menu.

DEPARTMENT OF COMPUTER APPLICATIONS 95


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

5) For Operating System Type, select the OS that you want to install.

6. Select the version of the operating system.

DEPARTMENT OF COMPUTER APPLICATIONS 96


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

7. Click Next. It's at the bottom of the menu.

8. Select an amount of RAM to use. Click and drag the slider left or right to decrease
or increase the amount of RAM that VirtualBox will have available for your virtual
machine.
The ideal amount of RAM will automatically be selected when you get to this page.
Make sure not to increase the RAM into the red section of the slider; try to keep the
slider in the green.

DEPARTMENT OF COMPUTER APPLICATIONS 97


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

[Link] Next. It's at the bottom of the menu.

[Link] your virtual machine's virtual hard drive. The virtual hard drive is a
section of your computer's hard drive space which will be used to store your virtual
machine's files and programs:

DEPARTMENT OF COMPUTER APPLICATIONS 98


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

[Link] “VDI” to create a virtual hard disk.

12. Choose “Dynamically allocated”

DEPARTMENT OF COMPUTER APPLICATIONS 99


FEDERAL INSTITUTE OF SCIENCE & TECHNOLOGY (FISAT) ®

13. Allocate at Minimum 8 GB (recommended 10 or more).

Click Create, to create your new virtual machine. The virtual machine is displayed
in the list on the left side of the VirtualBox Manager window, with the name that you
entered initially.
VMs can run multiple operating system environments on a single physical
computer, saving physical space, time and management costs.

DEPARTMENT OF COMPUTER APPLICATIONS 100

You might also like