0% found this document useful (0 votes)
16 views29 pages

Linux Practical 2 To 7

Uploaded by

Sumi Dhara
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)
16 views29 pages

Linux Practical 2 To 7

Uploaded by

Sumi Dhara
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/ 29

Name: Sumi Dhara Practical No.: 2 Roll no.

: 6208

Practical No. 2

 Create a directory structure given below:

IT

FYIT SYIT TYIT

SemI SemII SemIII SemIV SemV SemVI

P1.txt P2.c P3.txt P4.cpp P5.txt P6.java

To create the above directory structure, we need to follow the steps given below:

i) We are creating this directory structure inside Desktop so we will move the prompt to Desktop using
‘cd’ command.
ii) After getting inside Desktop, we will create a directory named IT using ‘mkdir’ command.
iii) We will change directory to IT using ‘cd’ command and inside IT directory we will create three new
directories FYIT, SYIT and TYIT namely using ‘mkdir’ command.
iv) We get inside FYIT directory and inside it we will again two more directories using ‘mkdir’ command
SemI and SemII namely.
v) Using ‘cd’ command we will get inside SemI directory and create P1.txt file using ‘cat >’ command and
check the file using ‘cat’ command.

vi) After creating P1.txt file, we will now go back to above directory FYIT using ‘cd ..’ command and the
change the directory to SemII directory and inside it creates a P2.c file using vi editor to write and
execute a C program to find factorial of a number and after writing the program, to close the vi editor
Name: Sumi Dhara Practical No.: 2 Roll no.: 6208

environment we will press Esc + :wq! and then to compile a C program we will use ‘gcc’ command and
to execute the output we will use ./P2.out.

(Programming part in vi editor environment)

vii) Now to change our current directory from SemII to SYIT, we will use ‘cd ../..’ to directly jump two
directories above which is FYIT.
viii) After coming to FYIT we will use ‘cd’ command to change the current directory to SYIT.
ix) Inside SYIT, we will create two new directories SemIII and SemIV using ‘mkdir’ command. (Then
repeat the same steps)
x) Using ‘cd’ command we will get inside SemIII directory and create P3.txt file using ‘cat >’ command
and check the file using ‘cat’ command.

xi) After creating P3.txt file, we will now go back to above directory SYIT using ‘cd ..’ command and the
change the directory to SemIV directory and inside it creates a P4.cpp file using vi editor to write and
execute a C++ program to perform addition of two numbers and after writing the program, to close the
Name: Sumi Dhara Practical No.: 2 Roll no.: 6208

vi editor environment we will press Esc + :wq! and then to compile a C++ program we will use ‘g++’
command and to execute the output we will use ./P4.out.

(Programming part in vi editor environment)

xii) Now to change our current directory from SemIV to TYIT, we will use ‘cd ../..’ to directly jump two
directories above which is SYIT.
xiii) After coming to SYIT we will use ‘cd’ command to change the current directory to TYIT.
xiv) Inside TYIT, we will create two new directories SemV and SemVI using ‘mkdir’ command. (Then
again repeat the same steps)
xv) Using ‘cd’ command we will get inside SemV directory and create P5.txt file using ‘cat >’ command
and check the file using ‘cat’ command.

xvi) After creating P5.txt file, we will now go back to above directory TYIT using ‘cd ..’ command and the
change the directory to SemVI directory and inside it creates a P6.java file using vi editor to write and
execute a Java program to even numbers from 1 to 10 and after writing the program, to close the vi
editor environment we will press Esc + :wq! and then to compile a Java program we will use ‘javac’
command and to execute the output we will use java P6.
xvii) To close the command prompt, we will use ‘exit’ command.
Name: Sumi Dhara Practical No.: 2 Roll no.: 6208

(Programming part in vi editor environment)


Name: Sumi Dhara Practical No.: 3 Roll no.: 6208

Practical No. 3

 Define the use of all the basic Linux commands and implement them:
Basic Linux commands and their uses:
i) pwd
pwd (print working directory) : Displays the current directory you're in. It's useful for confirming your present location
within the directory structure.
ii) mkdir
mkdir (make directory) : Creates a new directory with the specified name.
iii) cd
cd (change directory) : Changes the current directory to the specified directory.
a) cd .. : Moves up one directory level.
b) cd – : Switches to the previous directory you were in.
c) cd ~ : Moves to the home directory of the current user.
iv) touch
touch : Creates an empty file with the specified name. If the file already exists, it updates the file's access and modification
timestamps.
v) cat
cat (concatenate): Displays the content of a file or concatenates multiple files and displays the output.
a) cat > filename : Creates or overwrites a file with the specified name and allows the user to input text to the file until they
press Ctrl+D.
vi) tac
tac : Displays the content of a file in reverse order (last line first).
a) tac > filename : Similar to ‘cat >’, but the input will be reversed and then written to the file.
vii) head
head : Displays the first 10 lines of a file by default. You can specify the number of lines to display using ‘-n’.
viii) tail
tail : Displays the last 10 lines of a file by default. You can specify the number of lines to display using ‘-n’.
ix) more
more : Displays the content of a file one screen at a time. You can navigate through the file using the spacebar to scroll down.
x) less
less : Similar to ‘more’, but with more functionality. It allows for both forward and backward navigation through the file.
xi) cp
cp (copy) : Copies files or directories from one location to another.
xii) mv
mv (move) : Moves or renames files or directories.
xiii) ls
ls (list) : Lists the contents of a directory.
a) ls -l : Lists the contents in long format, showing detailed information like permissions, number of links, owner, group, size,
and time of last modification.
b) ls -a : Lists all contents, including hidden files (those starting with a dot).
c) ls -d : Lists directories themselves rather than their contents.
xiv) rm
rm (remove) : Deletes files or directories. Use with caution, as this command can permanently remove data.
a) rm -r : Recursively deletes directories and their contents.
xv) rmdir
rmdir (remove directory) : Deletes empty directories. It will not remove directories that contain files or other directories.
Name: Sumi Dhara Practical No.: 3 Roll no.: 6208

o Implementation of all the basic Linux commands.


Name: Sumi Dhara Practical No.: 3 Roll no.: 6208
Name: Sumi Dhara Practical No.: 3 Roll no.: 6208
Name: Sumi Dhara Practical No.: 3 Roll no.: 6208
Name: Sumi Dhara Practical No.: 3 Roll no.: 6208
Name: Sumi Dhara Practical No.: 3 Roll no.: 6208
Name: Sumi Dhara Practical No.: 4 Roll no.: 6208

Practical No. 4

a) Create both the links(hard link & soft/symbolic link) for a file and show its management:

Steps to create hard link and soft(symbolic) link of a file:

• For creating hard link :


i) Create a file f1.
(Using ‘echo’ command or any command we are comfortable with or the command which is compatible
for the type of our file)
ii) Check inode number and details of f1.
(Using ‘ls -ial’ command)
iii) Create hard link between f1 and f2.
(Using ‘ln’ command)
iv) Check inode of both the files.
(Using ‘ls -ial’ command)
(Both has same inode number because f2 is hard link of f1. If you change anything in f1, it will reflect to
f2)
v) Change the content of file f1.
(Using ‘cat >>’ command)
vi) Check the content of file f1.
(Using ‘cat’ command)
vii) Check the content of f2.
(Using ‘cat’ command)
• For creating soft(symbolic) link :
i) Create two soft links f3 and f4 with file f1 and f2 respectively.
(Using ‘ln -s’ command)
ii) Check inode value of all files.
(Using ‘ls -ial f*’ command)
(File f1 and f2 has same inode because f2 is hard link of f1 but inside of f3 and f4 is different because f3
and f4 are soft links)
iii) Change the content of file f1.
(Using ‘cat >>’ command)
(Changes in all files are affected because f2 and f3 are direct hard and soft link with f1 respectively and
f4 is direct soft link with f2. As f2 changes, it will do the changes in file f4)
iv) Check the content of all files.
(Using ‘cat’ command)
v) Remove the file f1.
(Using ‘rm’ command)
(The soft link of f1 which is f3 is affected. As f2 is hard link with f1, it will not affect the file f2)
vi) Check the content of all files.
(Using ‘cat’ command)
Name: Sumi Dhara Practical No.: 4 Roll no.: 6208

o Implementation of Hard Links.

o Implementation of Soft(Symbolic) Links.


Name: Sumi Dhara Practical No.: 4 Roll no.: 6208

b) Create a backup file for files and directories and compress the size of it:

Steps to create and compress a backup file for different files and directories:

• For creating a backup file:


i) Create empty files f1 f2 f3 f4 f5 f6.
(Using ‘touch’ command)
ii) Create some directories d1 d2 d3.
(Using ‘mkdir’ command)
iii) Create a backup file backup.tar.
(Using ‘tar’ command)
iv) Check the size of backup file.
(Using ‘du -sh’ command)
• For compressing the backup file size:
v) Compress the backup file.
(Using ‘gzip’ or ‘bzip’ commands. Here we are using ‘gzip’ command)
vi) Check the details of all files.
(Using ‘ls -l’ command)
vii) Check the compress size of backup zip file.
(Using ‘du -sh’ command)

(Note: ‘-cvf’ along with ‘tar’ is used to create a backup file and ‘-xvf’ along with ‘tar’ is used to restore
original files or directories)

o Implementation of backup and compress.


Name: Sumi Dhara Practical No.: 5 Roll no.: 6208

Practical No. 5

a) Create a repository using yum(Yellowdog Updater Modified) command and check the
repository list :

• Steps to create a repository using yum command :

i) Login as root user.


(Using ‘su’ command)
ii) Create a directory and name it /repo.
(Using ‘mkdir’ command)
iii) Go to disc inside media directory.
(Using ‘cd’ command)
iv) Inside disc go to Packages.
(Using ‘cd’ command)
v) Check details of files and directories inside Packages.
(Using ‘ls -ltr’ command)
(All the list of .rpm files are displayed)
vi) Copy three .rpm files (including createrepo file) to /repo.
(Using ‘cp’ command)
vii) Change directory to /repo.
(Using ‘cd’ command)
viii) Install the copied rpm files in /repo.
(Using ‘rpm -ivh’ command)
ix) Make /repo a repository.
(Using ‘createrepo’ command)
x) Check repolist of /repo.
(Using ‘yum repolist’ command) (Initially it’ll be 0)
xi) Go to yum.repos.d inside /etc.
(Using ‘cd’ command)
xii) Create a file myrepo.repo and add content to it.
(Using ‘vi’ editor)
xiii) Check the number of files inside yum.repos.d.
(Using ‘ls -ltr’ command)
xiv) Check the list of repo files added to /repo repository.
(Using ‘yum repolist’ command)
(Repolist will increase with some large number than before)
Name: Sumi Dhara Practical No.: 5 Roll no.: 6208

o Implementation of creating a repository.


Name: Sumi Dhara Practical No.: 5 Roll no.: 6208
Name: Sumi Dhara Practical No.: 5 Roll no.: 6208

(Content inside myrepo.repo)


Name: Sumi Dhara Practical No.: 5 Roll no.: 6208

b) Show management of processes using ps command:

• Managing processes using ps command:


Name: Sumi Dhara Practical No.: 5 Roll no.: 6208
Name: Sumi Dhara Practical No.: 5 Roll no.: 6208
Name: Sumi Dhara Practical No.: 6 Roll no.: 6208

Practical No. 6

a) Create a primary partition:

• Steps to create a primary partition:

i) Type fdisk -cu /dev/sda.


ii) Type d - To delete the existing partition.
iii) Type n - To create a new partition.
iv) Type p - To select primary partition. (i.e. (1-4) as only 4 primary partitions can be created)
v) Enter partition size in K-Kilobytes, M-Megabytes or G-Gigabytes. (E.g.:- +500M)
vi) Type p - To print the partition.

o Implementation of creating a primary partition.


Name: Sumi Dhara Practical No.: 6 Roll no.: 6208
Name: Sumi Dhara Practical No.: 6 Roll no.: 6208

Practical No. 6

b) Create an extended(logical) partition:

• Steps to create an extended(logical) partition:

i) Type fdisk -cu /dev/sda.


ii) Type d - To delete the existing partition.
iii) Type n - To create a new partition.
iv) Type e - To select extended partition.
v) Do not enter partition size. Press Enter to select all available spaces.
vi) Type p - To print the partition.

o Implementation of creating an extended(logical) partition.


Name: Sumi Dhara Practical No.: 6 Roll no.: 6208
Name: Sumi Dhara Practical No.: 7 Roll no.: 6208

Practical No. 7

a) Configure server for file sharing to client using NFS: (Server side)

• Steps to configure server for file sharing using nfs:

Setting up nfs server

(Always log in as a root)


i) rpm -qa | grep nfs (To check if nfs files are installed)
ii) ifconfig (To check ip address)
(First ping with client using ‘ping’ command)
iii) ping ip address of client
(Go to home directory and inside home make your own directory ‘servernfs’)
iv) mkdir servernfs
(Now create files to share with client)
v) cd servernfs
vi) cat > filename
(Add some content in it)
vii) vi /etc/exports
(It is a blank file. Now add line to it)
viii) /home/servernfs *(rw,sync)
(Now save and exit using - :wq!)
ix) service nfs restart
(If the service is not started fully then run the following command)
x) RPCBIND_ARGS= “-i”
service rpcbind restart
xi) service iptables stop
xii) service iptables status
xiii) showmount -e ip address of server
xiv) service vsftpf stop
xv) service vsftpd status
xvi) chmod -R 777 /home/servernfs
Name: Sumi Dhara Practical No.: 7 Roll no.: 6208

o Implementation:
Name: Sumi Dhara Practical No.: 7 Roll no.: 6208

(Inside vi editor)
Name: Sumi Dhara Practical No.: 7 Roll no.: 6208

Practical No. 7

b) Configure client for accepting file from server and checking shared file using NFS: (Client
side)

• Steps to configure client:

Setting up nfs client

(Here, we have to install nfs packages and then follow the step (i) of server nfs.
i) mkdir clientnfs
(Create a directory in /home)
ii) mount -t nfs ip address of server :/home/servernfs/ /home/clientnfs/
(Now go to clientnfs directory and check shared file.
iii) cd clientnfs
iv) ls
(Check the content of shared file in clientnfs)
v) cat shared filename

o Implementation:

You might also like