0% found this document useful (0 votes)
17 views35 pages

CS505 LINUX

practical file
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)
17 views35 pages

CS505 LINUX

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

A PRACTICAL FILE ON

Linux (CS 505)


S

Submitted to
RAJIV GANDHI PROUDYOGIKI VISHWAVIDYALAYA, BHOPAL
(M.P)
In Partial Fulfilment of the Requirement for the Award of Degree of
BACHELOR OF TECHNOLOGY
With Specialization In

COMPUTER SCIENCE AND ENGINEERING

Submitted by:
Jayesh Shrivastava (0929CS223D08)
3nd year — 5'h semester

Submitted to:
Prof. Ajay Shivhare
Professor, Department of Computer Science & Engineering and AI & DS

SRIIT, Banmore

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING AND ARTIFICIAL


INTELLIGENCE & DATA SCIENCE ENGINEERING

SHRIRAM INSTITUTE OF INFORMATION AND TECHNOLOGY


BANMORE — 476444 (M.P.)
INDEX

S/ Objective Page No. Date Sign


N
1 To Study basic & User status Unix/Linux Commands
2 Study & use of commands for performing arithmetic
operations with Unix/Linux
3 Create a file called wlcc.txt with some lines and display
how many lines, words and
characters are present in that file
4 Append ten more simple lines to the wlcc.txt file created
above and split the appended file into 3 parts. What will
be the names of these split files? Display the contents of
each of these files. How many lines will be there on the
last file?
5 Given two files each of which contains names of
students. Create a program to display only those names
that are found on both the
files
6 Create a program to find out the inode number of any
desired file
7 Study & use of the Command for changing file permissions
8 Write a pipeline of commands, which displays on the
monitor as well as saves the information about the
number of users using the system at present on a file
called usere.ux
9 Execute shell commands through vi edito
10 Installation, Configuration & Customizations of
Unix/Linux.
11 Write a shell script that accepts any number of
arguments and prints them in the reverse order.
12 Write a shell script to find the smallest of three numbers
that are read from the keyboard.
13 Write a shell script that reports the logging in of a
specified user within one minute after he/she logs in.
The script automatically terminates if the specified user
does not login during a specified period of time
14 Installation of SAMBA, APACHE, TOMCAT.
15 Implementation of DNS, LDAP services,
16 Study & installation of Firewall & Proxy server
Q1. To Study basic & User status Unix/Linux Commands.
Ans-Unix commands are a set of commands that are used to interact with the Unix operating
system. Unix is a powerful, multi-user, multi-tasking operating system that was developed in
the 1960s by Bell Labs. Unix commands are entered at the command prompt in a terminal
window, and they allow users to perform a wide variety of tasks, such as managing files and
directories, running processes, managing user accounts, and configuring network settings.
Unix is now one of the most commonly used Operating systems used for various purposes
such as Personal use, Servers, Smartphones, and many more. It was developed in the 1970’s
at AT& T Labs by two famous personalities Dennis M. Ritchie and Ken Thompson.

You’ll be surprised to know that the most popular programming language C came into
existence to write the Unix Operating System.
Linux is Unix-Like operating system.
The most important part of the Linux is Linux Kernel which was first released in the early
90s by Linus Torvalds.There are several Linux distros available (most are open-source and
free to download and use) such as Ubuntu, Debian, Fedora, Kali, Mint, Gentoo, Arch and
much more.
Now coming to the Basic and most usable commands of Linux/Unix part. (Please note that all
the linux/unix commands are run in the terminal of a linux system.Terminal is like command
prompt as that of in Windows OS)
Linux/Unix commands are case-sensitive i.e Hello is different from hello.
Basic unix commands:

1. who : The ‘$ who’ command displays all the users who have logged into the system
currently. As shown above, on my system I am the only user currently logged in.The thing
tty2 is terminal line the user is using and the next line gives the current date and time

$ who
Output: harssh tty2 2017-07-18 09:32 (:0)
2. pwd : The ‘$pwd’ command stands for ‘print working directory’ and as the name says,it
displays the directory in which we are currently (directory is same as folder for Windows OS
users).
In the output, we are harssh directory(folder for Windows OS that are moving to
Linux),which is present inside the home directory.

$ pwd
Output: /home/harssh
3. mkdir : The ‘$ mkdir’ stands for ‘make directory’ and it creates a new directory.We have
used ‘$ cd’ (which is discussed below) to get into the newly created directory and again on
giving ‘$ pwd’ command,we are displayed with the new ‘newfolder’ directory.

$ mkdir newfolder
$ cd newfolder
$ pwd
Output: /home/harssh/newfolder
4. rmdir : The ‘$ rmdir’ command deletes any directory we want to delete and you can
remember it by its names ‘rmdir’ which stands for ‘remove directory’.

$ rmdir newfolder
5. cd : The ‘$ cd’ command stands for ‘change directory’ and it changes your current
directory to the ‘newfolder’ directory.You can understand this a double-clicking a folder and
then you do some stuff in that folder.

$ cd newfolder (assuming that there is a directory named 'newfolder' on your system)


6. ls : The ‘ls’ command simply displays the contents of a directory.

$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos
7. touch : The ‘$ touch’ command creates a file(not directory) and you can simple add an
extension such as .txt after it to make it a Text File.

$ touch example
$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos
example
Note: It is important to note that according to the Unix File structure, Unix treats all the stuff
it has as a ‘file’, even the directories(folders) are also treated as a file.You will get to know
more about this as you will further use Linux/Unix based OS

8. cp : This ‘$ cp ‘ command stands for ‘copy’ and it simply copy/paste the file wherever you
want to.In the above example, we are copying a file ‘file.txt’ from the directory harssh to a
new directory new.

$ cp /home/harssh/file.txt /home/harssh/new/
9. mv : The ‘$ mv’ command stands for ‘move’ and it simply move a file from a directory to
another directory.In the above example a file named ‘file.txt’ is being moved into a new
directory ‘new’

$ mv /home/harssh/file.txt /home/harssh/new
10. rm : The ‘$ rm ‘ command for remove and the ‘-r’ simply recursively deletes file. Try ‘$
rm filename.txt’ at your terminal

$ rm file.txt
11. chmod : The ‘$ chmod’ command stands for change mode command.As there are many
modes in Unix that can be used to manipulate files in the Unix environment.Basically there
are 3 modes that we can use with the ‘chmod’ command
1. +w (stands for write and it changes file permissions to write)
2. +r (stands for read and it changes file permissions to read)
3. +x (generally it is used to make a file executable)

$ chmod +w file.txt
$ chmod +r file.txt
$ chmod +x file.txt
12. cal : The ‘$ cal’ means calendar and it simply display calendar on to your screen.

$ cal
Output : July 2017
Su Mo Tu We Th Fr Sa
1
2345678
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
13. file : The ‘$ file’ command displays the type of file.As I mentioned earlier Linux treats
everything as a file so on executing the command file on a directory(Downloads) it displays
directory as the output

$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos
$ file Downloads
Output: Downloads: directory
14. sort : As the name suggests the ‘$ sort’ sorts the contents of the file according to the
ASCII rules.

$ sort file
15. grep : grep is an acronym for ‘globally search a regular expression and print it’.The ‘$
grep’ command searches the specified input fully(globally) for a match with the supplied
pattern and displays it.
In the example, this would search for the word ‘picture’ in the file newsfile and if found,the
lines containing it would be displayed on the screen.

$ grep picture newsfile


16. man : The ‘$ man’ command stands for ‘manual’ and it can display the in-built manual
for most of the commands that we ever need.In the above example, we can read about the ‘$
pwd’ command.

$ man pwd
17. lpr : The ‘$ lpr’ command send a file to the printer for printing.

$ lpr new.txt
18. passwd : The ‘$ passwd’ command simply changes the password of the user.In above
case ‘harssh’ is the user.

$ passwd
Output: Changing password for harssh.
(current) UNIX password:
19. clear : The ‘$ clear’ command is used to clean up the terminal so that you can type with
more accuracy

$ clear
20. history : The ‘$ history’ command is used to get list of previous commands may be
obtained by executing the following command. you can also use parameters like !n to re-
execute the nth command, !! to executes the most recent command, and !cp this will execute
the most recent command that starts with cp.

$ history
At last, I want to say that these are the most basic and essential commands that are used in the
Linux operating system. You will need them even if you get to advance the Unix. If you want
to master them just keep on practicing them.

Also, it is not possible to cover all the Unix commands because they are so many in number.
You can find more, just google it and you will find most of them. Also if you want to master
Unix operating system, Learn Unix Shell Scripting/Bash Scripting. Trust me there are many
awesome tutorials on the internet for them.

Compile your C/C++ program in the Unix terminal

First reach the directory where your .c or .cpp file is present (assume its name is new.c or
new.cpp). Please note that in order to compile C you will need GCC compiler and in order to
compile C++ you will need g++. I will tell you below how to install them.

For C:

$ gcc new.c -o new


$ ./new
For C++:

$ g++ new.cpp -o new


$ ./new
In this way you can compile you programs of C and C++. You can even compile many more
that i will cover in my coming articles.

Getting gcc, g++

For deb based Linux such as Ubuntu,Debian,Kali etc:

$ sudo apt-get install gcc


$ sudo apt-get install g++
For rpm based Linux such as Fedora,Oracle Linux etc:

$ dnf install gcc


$ dnf install g++
OR
$ yum install gcc
$ yum install g++
If you like GeeksforGeeks and would like to contribute, you can also write an article using
write.geeksforgeeks.org or mail your article to [email protected]. See your
article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information
about the topic discussed above.

Uses of Unix Commands :


File and directory management: Unix commands like ls, cd, cp, mv, rm, mkdir, and rmdir are
used for managing files and directories. These commands allow users to create, delete, copy,
move, and rename files and directories.
Process management: Unix commands like ps and kill are used for managing running
processes. Users can use these commands to list all running processes, view process details,
and terminate a process if necessary.
User management: Unix commands like passwd, useradd, userdel, and groupadd are used for
managing user accounts and groups. These commands allow system administrators to add or
delete user accounts, change user passwords, and manage group memberships.
Text manipulation: Unix commands like cat, grep, sed, and awk are used for manipulating
text files. These commands allow users to view, search, replace, and format text files.
Networking: Unix commands like ping, ifconfig, netstat, and traceroute are used for
configuring and troubleshooting network connections. These commands allow users to test
network connectivity, view network interface details, and diagnose network problems.
System configuration: Unix commands like chmod, chown, and sysctl are used for
configuring system settings. These commands allow users to change file permissions, file
ownership, and system parameters.
Programming: Unix commands like gcc, make, and gdb are used for compiling and
debugging programs. These commands are essential for developers who write programs in C
or C++.
Issues in Unix Commands :

Command syntax errors: Unix commands are sensitive to syntax errors, which can lead to
unexpected behavior or errors. Users must be careful to use the correct command syntax and
to include all required parameters.
Permissions issues: Unix commands are subject to file permissions, which can restrict access
to certain files or directories. Users may need to use the chmod or chown commands to
change file permissions or file ownership to access certain files.
Security risks: Some Unix commands can be used to compromise system security, such as
allowing unauthorized access to files or executing malicious code. Users must be careful to
use Unix commands only for authorized tasks and to avoid running unknown scripts or
commands.
Lack of user interface: Unix commands are typically executed from the command line, which
can be intimidating for users who are used to graphical user interfaces. Users may need to
spend time learning the syntax and usage of Unix commands to be effective.
Limited documentation: While Unix commands are well-documented, some commands may
not have complete or clear documentation. Users may need to rely on online resources or
community forums to find answers to specific issues.
Q2. Study & use of commands for performing arithmetic operations with
Unix/Linux.

Ans-
Bash script supports 11 arithmetic operators. All the operators with their uses is given
below:

Operator Name Use Example

result=
+ Addition It adds two operands
a+b

It subtract second operand from first result= a-


– Subtraction
one b

result=
* Multiplication Multiply two operands
a*b

16/3
Return the quotient after diving first
/ Division
operand from second operands result = 5

16/ 3
Return remainder after dividing first
% Modulo
operand from second operand result = 1

x= 13

Increment value of first operand with x+=3


+= Increment by constant
given constant value result =
16

x= 13

Decrement value of first operand x -= 3


-= Decrement by constant
with given constant value result =
10

x= 10

Multiply the given operand with the x*=3


*= Multiply by constant
constant value result =
30
Operator Name Use Example

x = 31

Divide the operand with given x/=3


/= Divide by constant
constant value and return the quotient result =
10

x= 31
Divide the operand with given
Remainder by dividing x%=3
%= constant value and return the
with constant
remainder result = 1

3**2
The result is second operand raised
** Exponentiation
to the power of first operand. result = 9

Let’s see the examples for the uses of arithmetic operators:

Addition

Code:
Sum=$((10+3))
echo "Sum = $Sum"
Output:

Subtraction
Code:
Difference=$((10-3))
echo "Difference = $Difference"
Output:

Multiplication

Code:
Product=$((10*3))
echo "Product = $Product"
Output:

Division
Code:
Division=$((10/3))
echo "Division = $Division"
Output:

Modulo

Code:
Modulo=$((10%3))
echo "Modulo = $Modulo"
Output:

Exponentiation
Code:
Exponent=$((10**2))
echo "Exponent = $Exponent"
Output:

Example to show use of all the operators in a single code


Code:
x=10
y=20
echo "x=10, y=5"
echo "Addition of x and y"
echo $(( $x + $y ))
echo "Subtraction of x and y"
echo $(( $x - $y ))
echo "Multiplication of x and y"
echo $(( $x * $y ))
echo "Division of x by y"
echo $(( $x / $y ))
echo "Exponentiation of x,y"
echo $(( $x ** $y ))
echo "Modular Division of x,y"
echo $(( $x % $y ))
echo "Incrementing x by 10, then x= "
(( x += 10 ))
echo $x
echo "Decrementing x by 15, then x= "
(( x -= 15 ))
echo $x
echo "Multiply of x by 2, then x="
(( x *= 2 ))
echo $x
echo "Dividing x by 5, x= "
(( x /= 5 ))
echo $x
echo "Remainder of Dividing x by 5, x="
(( x %= 5 ))
echo $x
Output:

Different ways to compute Arithmetic Operations in Bash


There are some of the different ways to perform Arithmetic Operations.

1. Double Parenthesis

This could be used for arithmetic expansion. Let’s see an example to see the use of double
parenthesis.
Code:
#!/bin/bash

first=10
second=3

echo $(( first + second )) # addition


echo $(( $first + $second )) # this is also valid

echo $(( first - second )) # subtraction


echo $(( $first - $second )) # this is also valid

Output:
13
13
7
7
2. Using let command
let command is used to perform arithmetic operations.
Example
code:
#!/bin/bash

x=10
y=3

let "z = $(( x * y ))" # multiplication


echo $z
let z=$((x*y))
echo $z

let "z = $(( x / y ))" # division


echo $z
let z=$((x/y))
echo $z
Output:
30
30
3
3

3. expr command with backticks

Arithmetic expansion could be done using backticks and expr.


Code:
a=10
b=3

# there must be spaces before/after the operator

sum=`expr $a + $b`
echo $sum

sub=`expr $a - $b`
echo $sub

mul=`expr $a \* $b`
echo $mul

div=`expr $a / $b`
echo $div
Output:
13
7
30
3
Q3. Create a file called wlcc.txt with some lines and display how many
lines, words and characters are present in that file.

Output
Q4. Append ten more simple lines to the wlcc.txt file created above and
split the appended file into 3 parts. What will be the names of these split
files? Display the contents of each of these files. How many lines will be
there on the last file?
1. Open a terminal.
2. Navigate to the directory where wlcc.txt is located.
3. Use a text editor like nano or vim to append ten more lines to wlcc.txt.
For example, using nano:
nano wlcc.txt
4. Add ten more lines, save, and exit the text editor.
Next, to split the file into three parts, you can use the split command. For example:
split -l 10 wlcc.txt
This command will split wlcc.txt into files with 10 lines each. The names of the split files
will be something like xaa, xab, and xac.
To display the contents of each file, you can use the cat command. For example:
cat xaa
cat xab
cat xac
The number of lines in the last file (xac) will depend on the total number of lines in wlcc.txt
and the number of lines you added. If the original wlcc.txt had, for example, 30 lines, and
you added 10 more, then xac will have 10 lines.
If you're using a different operating system or environment, the specific commands and steps
may be slightly different, but the general approach should be similar. Let me know if you
need help with a different environment.
Q5. Given two files each of which contains names of students. Create a
program to display only those names that are found on both the files
Certainly! You can accomplish this using common command-line tools like sort, uniq, and
comm. Here's a step-by-step guide:
1. Sort and Uniquify the Files: Open a terminal and navigate to the directory
containing your files.
sort file1.txt | uniq > sorted_file1.txt
sort file2.txt | uniq > sorted_file2.txt
This will sort and remove duplicates from each file, creating sorted_file1.txt and
sorted_file2.txt.
1. Find Common Names: Use the comm command to find common names between the
two files.
comm -12 sorted_file1.txt sorted_file2.txt
This will display the names that are found in both files.
If you want to save the common names to a file, you can use redirection:
comm -12 sorted_file1.txt sorted_file2.txt > common_names.txt
Now, you should have a file called common_names.txt containing the names that are
found in both file1.txt and file2.txt.
Remember to replace file1.txt and file2.txt with the actual file names, if they are
different in your case.
Q6. Given two files each of which contains names of students. Create a
program to display only those names that are found on both the files
You can use the ls command along with the -i option to display the inode number of a file in
Linux. If you want to do this programmatically, you can use the subprocess module in
Python to run the command. Here's an example program:
import subprocess
def get_inode(file_path):
try:
result = subprocess.run(['ls', '-i', file_path], capture_output=True, text=True)
output = result.stdout.strip().split()
inode = output[0]
return inode
except FileNotFoundError:
return None
file_path = input("Enter the path of the file: ")

inode = get_inode(file_path)

if inode is not None:


print(f"The inode number of '{file_path}' is {inode}.")
else:
print(f"File '{file_path}' not found.")
Here's how the program works:
1. The get_inode function takes a file path as input. It runs the command ls -i on the
given file and captures the output.
2. It then extracts the inode number from the output and returns it.
3. If the file is not found, it returns None.
4. The user is prompted to enter the path of the file.
5. The program then calls the get_inode function with the provided file path and prints
the result.
Keep in mind that this program assumes you have the necessary permissions to access the file
and retrieve its inode number.
Q7. Study & use of the Command for changing file permissions.
The chmod command in Linux/Unix is used to change the permissions (read, write, execute)
of files and directories. Here's a basic overview of how it works:
Syntax:
chmod [options] permissions file(s)
Common Options:
• -r: Recursively change permissions for directories and their contents.

• -v: Verbose mode, which displays a message for each file processed.
• -c: Report only when a change is made.
Permissions:
• u: User (owner)

• g: Group
• o: Others (everyone else)
• a: All (equivalent to ugo)
• +: Adds the specified permissions.
• -: Removes the specified permissions.
• =: Sets the permissions explicitly.
Examples:
1. Grant read and write permissions to the owner of a file:
bashCopy code
chmod u+rw file.txt
2. Remove write permission from the group:
bashCopy code
chmod g-w file.txt
3. Allow everyone to execute a script:
bashCopy code
chmod +x script.sh
4. Grant full permissions to the owner, read and execute to the group, and only read to
others:
bashCopy code
chmod u+rwx,g+rx,o+r file.txt
5. Recursively grant read and execute permissions to all files and directories in a folder:
bashCopy code
chmod -R u+rx folder/
6. Set specific permissions using numeric mode (octal representation):
• 4: Read permission
• 2: Write permission
• 1: Execute permission
For example, to grant read, write, and execute to the owner, and read-only to others:
bashCopy code
chmod 755 file.txt
Caution:
Be careful when modifying permissions, especially with the chmod -R command, as it can
potentially alter a large number of files and directories. Improper use of this command can
lead to security issues or unintended consequences.
Always ensure you have the necessary permissions before attempting to change the
permissions of a file or directory.
Remember that changing file permissions may require administrative privileges or
appropriate ownership of the file or directory.
Examples:
1. Grant read and write permissions to the owner of a file:

chmod u+rw file.txt


Remove write permission from the group:
chmod g-w file.txt
Allow everyone to execute a script:
chmod +x script.sh
4. Grant full permissions to the owner, read and execute to the group, and only read to
others:
chmod u+rwx,g+rx,o+r file.txt
Recursively grant read and execute permissions to all files and directories in a folder:
chmod -R u+rx folder/
6. Set specific permissions using numeric mode (octal representation):
• 4: Read permission
• 2: Write permission
• 1: Execute permission
For example, to grant read, write, and execute to the owner, and read-only to others:
chmod 755 file.txt
Caution:
Be careful when modifying permissions, especially with the chmod -R command, as it can
potentially alter a large number of files and directories. Improper use of this command can
lead to security issues or unintended consequences.
Always ensure you have the necessary permissions before attempting to change the
permissions of a file or directory.
Remember that changing file permissions may require administrative privileges or
appropriate ownership of the file or directory.
Q8.Write a pipeline of commands, which displays on the monitor as well as
saves the information about the number of users using the system at
present on a file called usere.ux.
You can achieve this using a combination of who and tee commands in a pipeline. The who
command displays information about currently logged-in users, and tee is used to both
display the output on the terminal and save it to a file. Here's the pipeline of commands:
who | wc -l | tee usere.ux
Explanation:
1. who: This command displays information about currently logged-in users.
2. wc -l: This command counts the number of lines in its input. Since the who command
outputs one line per logged-in user, this will give you the total number of users.
3. tee usere.ux: tee is used to read from standard input and write to standard output and
files simultaneously. In this case, it will display the number of users on the terminal
and save it to a file called usere.ux.
So, when you run this command, it will display the number of users on the terminal and also
save it to the file usere.ux.
Q9. Execute shell commands through vi editor
In Vim (Vi improved), you can execute shell commands by using the :! followed by the
command you want to run. Here's how you can do it:
1. Open the file in Vim:
vi filename
2. Press Esc to ensure you are in normal mode.
3. Type :! followed by the command you want to execute. For example, if you want to
list the files in the current directory, you would type:
:!ls
4. Press Enter to execute the command.
5. To return to the Vim editor, press any key (e.g., Enter).
Keep in mind that while in the command mode, you can run any shell command by using :!
followed by the command. However, be cautious when running commands as they will be
executed in your current shell environment.
Remember to save your work in Vim before running any shell commands, as the output of
the command will replace the content of the file if you don't save your changes first.
Q10. Installation, Configuration & Customizations of Unix/Linux.
Installation, configuration, and customizations of Unix/Linux systems involve several steps.
Below is an overview of the process:
1. Installation:
a. Selecting a Distribution:
• Choose a Unix/Linux distribution based on your requirements. Popular choices
include Ubuntu, Fedora, CentOS, Debian, and others.
b. Hardware Requirements:
• Ensure your hardware meets the minimum requirements specified by the chosen
distribution.
c. Booting from Installation Media:
• Boot your computer from the installation media (DVD, USB, etc.) containing the
chosen Unix/Linux distribution.
d. Follow Installation Wizard:
• Follow the on-screen instructions to perform the installation. This typically includes
selecting language, time zone, keyboard layout, disk partitioning, and setting the root
password.
e. Package Selection:
• Choose which packages or software components you want to install. You can select
predefined setups (e.g., "Desktop Environment" or "Server") or customize the
selection.
f. Completing the Installation:
• Once the installation process completes, remove the installation media and reboot the
system.
2. Post-Installation Configuration:
a. User Accounts:
• Create additional user accounts with appropriate privileges. Avoid using the root
account for regular tasks.
b. System Updates:
• Update the system to ensure you have the latest security patches and software updates.

c. Network Configuration:
• Set up network interfaces, configure IP addresses, and set DNS servers.

d. Firewall and Security:


• Configure the system firewall and security settings to protect against unauthorized
access.
e. Filesystem and Disk Management:
• Manage partitions, mount additional drives, and set up file systems (e.g., ext4, XFS).

3. Customizations:
a. Desktop Environment (Optional):
• If using a graphical interface, customize the desktop environment, themes, and
appearance settings to your preference.
b. Shell Customization:
• Personalize the shell prompt, configure environment variables, and set aliases for
frequently used commands.
c. Package Management:
• Use package managers (e.g., apt, yum, pacman) to install, update, and remove
software packages.
d. Software Installation:
• Install additional software and packages based on your requirements.

e. User Profiles:
• Customize user profiles, including setting preferences for shell, environment
variables, and application configurations.
f. Services and daemons:
• Configure and customize system services and daemons (e.g., web server, database
server) based on your needs.
g. System Monitoring and Logging:
• Set up monitoring tools and configure logging to keep track of system health and
activity.
4. Backups and Disaster Recovery:
• Implement a backup strategy to safeguard important data and create a plan for disaster
recovery.
5. Additional Security Measures:
• Implement additional security measures such as setting up intrusion detection
systems, enabling two-factor authentication, and regular security audits.
Keep in mind that specific steps and commands may vary depending on the Unix/Linux
distribution you are using. Always refer to the official documentation and community
resources for detailed instructions and best practices.
Q11. Write a shell script that accepts any number of arguments and prints
them in the reverse order
You can create a shell script to achieve this. Here's an example script that accepts any number
of arguments and prints them in reverse order:
#!/bin/bash

# Check if there are any arguments


if [ $# -eq 0 ]; then
echo "No arguments provided."
exit 1
fi

# Use a loop to iterate through the arguments in reverse order


for (( i=$#; i>0; i-- )); do
echo "${!i}"
done
Save the script with a .sh extension (e.g., reverse_args.sh). Make it executable using the
command:
chmod +x reverse_args.sh
You can then run the script with any number of arguments:
./reverse_args.sh arg1 arg2 arg3 ...
For example:
./reverse_args.sh apple banana cherry
This will print:
cherry
banana
apple
Explanation:
1. The script starts with a shebang #!/bin/bash to specify that it should be executed
using the Bash shell.
2. It checks if there are any arguments provided. If not, it prints a message and exits.
3. It then uses a loop to iterate through the arguments in reverse order. The loop variable
i starts from the total number of arguments ($#) and decrements down to 1.
4. ${!i} is used to access the value of the argument at position i.
Remember to replace reverse_args.sh with the actual filename if you choose a different
name for your script.
Q12. Write a shell script to find the smallest of three numbers that are read
from the keyboard.
You can create a shell script to find the smallest of three numbers. Here's an example script:
#!/bin/bash

# Read three numbers from the user


echo "Enter three numbers:"
read num1
read num2
read num3

# Check which number is the smallest


if [ $num1 -lt $num2 ] && [ $num1 -lt $num3 ]; then
smallest=$num1
elif [ $num2 -lt $num1 ] && [ $num2 -lt $num3 ]; then
smallest=$num2
else
smallest=$num3
fi

echo "The smallest number is: $smallest"


Save the script with a .sh extension (e.g., find_smallest.sh) and make it executable using the
command:
bash
chmod +x find_smallest.sh
You can then run the script:
bash
./find_smallest.sh
The script will prompt you to enter three numbers, and it will then determine and print the
smallest number.
For example:
Enter three numbers:
10
5
8
The smallest number is: 5
Explanation:
1. The script starts with a shebang #!/bin/bash to specify that it should be executed
using the Bash shell.
2. It prompts the user to enter three numbers and reads them into the variables num1,
num2, and num3.
3. It uses a series of conditional statements (if-elif-else) to compare the numbers and
find the smallest one.
4. The smallest number is stored in the variable smallest.
5. Finally, it prints the smallest number.
Q13. Write a shell script that reports the logging in of a specified user
within one minute after he/she logs in. The script automatically terminates
if the specified user does not login during a specified period of time
To achieve this, you can use a combination of grep, awk, sleep, and a loop to continuously
check for the specified user's login. Here's an example shell script:
#!/bin/bash

# Define the username and time limit (in seconds)


username="your_username"
time_limit=60

# Start an infinite loop to continuously check for user login


while true; do
# Use the `who` command to get information about currently logged-in users
login_info=$(who | grep "$username")

# Check if the specified user has logged in


if [ -n "$login_info" ]; then
echo "User '$username' logged in!"
exit 0
fi

# Sleep for a specified period (e.g., 5 seconds) before checking again


sleep 5

# Increment a timer and check if it exceeds the time limit


((time_limit -= 5))
if [ $time_limit -le 0 ]; then
echo "User '$username' did not log in within the specified time limit."
exit 1
fi
done
Here's how the script works:
1. Define the username you want to monitor and the time_limit (in seconds) within
which the user should log in.
2. The script enters an infinite loop using while true; do.
3. Inside the loop, it uses the who command along with grep to check if the specified
user has logged in.
4. If the user logs in, it prints a message and exits the script.
5. If the user does not log in within the specified time limit, it prints a message and exits
the script.
6. The script includes a sleep command to wait for a specified period (5 seconds in this
example) before checking again. This prevents the script from consuming too many
system resources.
Remember to replace "your_username" with the actual username you want to monitor.
Save the script with a .sh extension (e.g., user_login_monitor.sh) and make it executable
using the command chmod +x user_login_monitor.sh.
You can then run the script:
./user_login_monitor.sh
The script will continuously check for the specified user's login and terminate if the user logs
in within the specified time limit or if the time limit is reached.
Q14. Installation of SAMBA, APACHE, TOMCAT.
To install SAMBA, Apache, and Tomcat, you'll need to use package managers specific to
your Linux distribution. Here are instructions for some popular distributions:
1. Installation on Ubuntu/Debian:
Open a terminal and run the following commands:
SAMBA:
sudo apt update sudo apt install samba
Apache:
sudo apt update sudo apt install apache2
Tomcat:
sudo apt update sudo apt install tomcat9
2. Installation on CentOS/RHEL:
SAMBA:
sudo yum install samba
Apache:
sudo yum install httpd
Tomcat:
sudo yum install tomcat
3. Installation on Fedora:
SAMBA:
sudo dnf install samba
Apache:
sudo dnf install httpd
Tomcat:
sudo dnf install tomcat
4. Installation on Arch Linux:
SAMBA:
sudo pacman -S samba
Apache:
sudo pacman -S apache
Tomcat:
bashCopy code
sudo pacman -S tomcat
Configuration and Starting Services:
SAMBA:
• Once installed, you'll need to configure SAMBA by editing /etc/samba/smb.conf.

• Start the SAMBA service:


sudo systemctl start smbd
Apache:
• The default configuration files are usually sufficient for basic usage.

• Start the Apache service:


sudo systemctl start httpd
Tomcat:
• Tomcat's configuration is done in the /etc/tomcat directory.

• Start the Tomcat service:


bashCopy code
sudo systemctl start tomcat
Access:
• SAMBA: Use a file manager and navigate to smb://<server_ip> to access shared
folders.
• Apache: Open a web browser and go to http://<server_ip> to access the default
Apache page.
• Tomcat: Open a web browser and go to http://<server_ip>:8080 to access the
Tomcat manager interface.
Remember to replace <server_ip> with the actual IP address of your server.
These are basic installation steps. Depending on your specific use case, you may need to
perform additional configurations or customizations. Always refer to the official
documentation and community resources for detailed instructions.
Q15. Implementation of DNS, LDAP services,
Implementing DNS (Domain Name System) and LDAP (Lightweight Directory Access
Protocol) services involves configuring and setting up servers for these services. Below are
general steps for each:
Implementation of DNS:
1. Install DNS Server:
• Install a DNS server software like BIND (Berkeley Internet Name Domain) on
your chosen platform (e.g., Linux).
2. Configure DNS Zone Files:
• Define DNS zone files that specify mappings between domain names and IP
addresses.
3. Edit DNS Configuration Files:
• Configure the DNS server settings, including zone files, forwarders, and other
parameters.
4. Start and Enable DNS Service:
• Start the DNS server service and set it to start automatically on system boot.
5. Set Up Forwarders (Optional):
• Configure DNS forwarders to resolve queries for external domains.
6. Test DNS Resolution:
• Verify that the DNS server can successfully resolve domain names to IP
addresses.
7. Update DNS Records:
• As needed, add, modify, or remove DNS records for your domains.
Implementation of LDAP:
1. Install LDAP Server:
• Install an LDAP server software like OpenLDAP on your chosen platform
(e.g., Linux).
2. Configure slapd.conf (for OpenLDAP):
• Edit the slapd.conf file to define the LDAP server's settings, including base
DN, suffix, and other parameters.
3. Set Up Initial LDAP Structure:
• Populate the LDAP directory with the initial structure, including
organizational units (OUs) and entries.
4. Start and Enable LDAP Service:
• Start the LDAP server service and set it to start automatically on system boot.
5. Add Users and Groups:
• Use LDAP administration tools (e.g., ldapadd, ldapmodify) to add users,
groups, and organizational units.
6. Configure LDAP Client (Optional):
• Set up systems to use the LDAP server for authentication and user/group
information.
7. Implement TLS/SSL (Optional):
• Secure LDAP communication by setting up SSL/TLS encryption.
8. Backup and Recovery:
• Regularly back up the LDAP database to ensure data integrity and recovery in
case of failure.
9. Monitoring and Maintenance:
• Implement monitoring solutions and perform regular maintenance tasks like
purging stale accounts.
Remember, the specific steps and commands may vary depending on the LDAP server
software you choose and the Linux distribution you're using. Always refer to the official
documentation and community resources for detailed instructions and best practices.
Q16. Study & installation of Firewall & Proxy server
Studying and setting up a firewall and a proxy server involves several steps. Below, I'll
provide an overview of both concepts along with basic steps for installation.
Firewall:
1. What is a Firewall?
• A firewall is a network security device that monitors and filters incoming and
outgoing network traffic based on an applied rule set.
2. Types of Firewalls:
• Hardware Firewall: A standalone device placed between a local network and the
internet.
• Software Firewall: Software installed on a computer or server to filter traffic.
3. Firewall Functions:
• Packet Filtering: Decides whether to allow or block traffic based on defined rules.

• Stateful Inspection: Keeps track of active connections and allows related traffic.
• Proxy Services: Acts as an intermediary between internal and external systems.
• Intrusion Prevention System (IPS): Detects and prevents known threats.
4. Installation of a Firewall:
• Hardware Firewall: Purchase a dedicated hardware firewall device and follow the
manufacturer's installation instructions.
• Software Firewall: Install a firewall application on your operating system. For
Linux, iptables is commonly used.
Proxy Server:
1. What is a Proxy Server?
• A proxy server acts as an intermediary between a client and the internet, forwarding
requests from the client to the server and vice versa.
2. Types of Proxy Servers:
• Forward Proxy: Sits between clients and the internet to provide anonymity and control
access.
• Reverse Proxy: Sits between servers and the internet to enhance security and
performance.
3. Proxy Server Functions:
• Caching: Stores copies of frequently accessed resources to reduce bandwidth usage.

• Filtering: Filters requests based on defined rules, allowing or blocking certain content.
• Anonymity: Masks the client's IP address when accessing websites.
4. Installation of a Proxy Server:
• Squid Proxy Server (Linux):

• Install Squid using your package manager (apt, yum, etc.).


• Configure Squid by editing the squid.conf configuration file.
• Start the Squid service and set it to start automatically.
• Microsoft Forefront TMG (Windows):
• Install Forefront TMG on a Windows server and follow the setup wizard.
• Configure the rules for web access, caching, and other proxy features.
• NGINX (Reverse Proxy):
• Install NGINX and configure it as a reverse proxy by defining proxy pass
directives.
Remember to consult the official documentation and community resources for detailed
instructions on specific firewall and proxy server solutions, as the steps may vary depending
on the software and operating system you choose.

You might also like