Assignment3 Complexproblems

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

NAME- SANA SACHDEVA

UID- 20BCA1658

1. Mention the commands only to create myvdo with 5G logical size. please take
/dev/vdc for that. format the volume with xfs file system. and mount it on /mnt/storage
permanently.
Main Features of XFS
 XFS supports metadata journaling, which facilitates quicker crash recovery.
 The XFS file system can be defragmented and enlarged while mounted and
active.
 In addition, Red Hat Enterprise Linux 7 supports backup and restore utilities
specific to XFS.
Allocation Features
XFS features the following allocation schemes:
 Extent-based allocation
 Stripe-aware allocation policies
 Delayed allocation
 Space pre-allocation
2. Create a 500MB extended partition. then Create a 1GB primary partition check df -h
and lsblk command. Later delete extended partition and create a 1MB primary
partition then change type to linux lvm and then save it.

fdisk is started by typing (as root) fdisk device at the command


prompt. device might be something like /dev/hda or /dev/sda The
basic fdisk commands you need are:
p print the partition table
n create a new partition
d delete a partition
q quit without saving changes
w write the new partition table and exit
3. Create archive as archive1.tar for two files file1 and file2 then using command append
file3 in archive then check list of files archived and then unarchive it. create the
archive of all files using gzip compression as archive2 and archive3 using bzip2
compression. check the list of all the files

To combine multiple files into a single archive file (for example, my_files.tar), use
the following command (replace file1 and file2 with the names of the files you
want to combine):

tar -cvf my_files.tar file1 file2

To combine all the files in a directory into a single archive file (for
example, my_files.tar), use the following command
(replace /path/to/my/directory with the absolute path to the directory containing
the files you want to combine):

tar -cvf my_files.tar /path/to/my/directory

 To use tar and gzip to combine multiple files into a compressed archive file


(for example, my_files.tar.gz), use the following command
(replace file1 and file2 with the names of the files you want to combine):

 tar -cvzf my_files.tar.gz file1 file2

 To use tar and gzip to combine all the files in a directory into a compressed


archive file (for example, my_files.tar.gz), use the following command
(replace /path/to/my/directory with the absolute path to the directory
containing the files you want to combine):

tar -cvzf my_files.tar.gz /path/to/my/directory


4. Use tar to backup /etc in /mnt/backup/etc_date.tgz, the backup must be gzipped.
(Replace date with the current date) Use tar to backup /bin to
/mnt/backup/bin_date.tar.bz2, the backup must be bzip2'd. Choose a file in /etc and
restore it from the cpio archive into your home directory. Choose a file in /etc
compress with bzip2 and /bin and compress with gzip
 tar - is the command that creates the archive. It is modified by each letter immediately following, each
is explained bellow.
o c - create a new backup archive.
o v - verbose mode, tar will print what it's doing to the screen.
o p - preserves the permissions of the files put in the archive for restoration later.
o z - compress the backup file with 'gzip' to make it smaller.
o f <filename> - specifies where to store the backup, backup.tar.gz is the filename used in this
example. It will be stored in the current working directory, the one you set when you used the
cd command.
 --exclude=/example/path - The options following this model instruct tar what directories NOT to
backup. We don't want to backup everything since some directories aren't very useful to include. The
first exclusion rule directs tar not to back itself up, this is important to avoid errors during the
operation.
 --one-file-system - Do not include files on a different filesystem. If you want other filesystems, such as
a /home partition, or external media mounted in /media backed up, you either need to back them up
separately, or omit this flag. If you do omit this flag, you will need to add several more --
exclude= arguments to avoid filesystems you do not want. These would
be /proc, /sys, /mnt, /media, /run and /dev directories in root. /proc and /sys are virtual
filesystems that provide windows into variables of the running kernel, so you do not want to try and
backup or restore them. /dev is a tmpfs whose contents are created and deleted dynamically by udev,
so you also do not want to backup or restore it. Likewise, /run is a tmpfs that holds variables about
the running system that do not need backed up.
 It is important to note that these exclusions are recursive. This means that all folders located within the
one excluded will be ignored as well. In the example, excluding the /media folder excludes all
mounted drives and media there.
o If there are certain partitions you wish to backup located in /media, simply remove the
exclusion and write a new one excluding the partitions you don't want backed up stored within
it. For example:
 --exclude=/media/unwanted_partition
 / - After all options is the directory to backup. Since we want to backup everything on the system we
use / for the root directory. Like exclusions, this recursively includes every folder below root not listed
in the exclusions or other options.
5. Write a shell script to enter three numbers and check the largest among three it should
check the equality of three numbers also. Write another shell script to create a
calculator using case statement.
Part a)
#!bin/bash
read a b c
if [ $a -eq $b -a $a -eq $c ]; then
echo "All the three numbers are equal"
elif [[ $a -eq $b || $b -eq $c || $c -eq $a ]]; then
echo "I cannot figure out which number is largest"
else
if [ $a -gt $b -a $a -gt $c ]; then
echo "$a is biggest number"
elif [ $b -gt $a -a $b -gt $c ]; then
echo "$b is biggest number"
elif [ $c -gt $a -a $c -gt $b ]; then
echo "$c is biggest number"
fi
fi
Part b)
Approach:  
o Read Two Numbers
o Input Choice (1-Addition, 2-Subtraction, 3-Multiplication, 4-
Division)
o if Choice equals 1
 Calculate res = a + b
 else If Choice equals 2
 Calculate res = a - b
 else if Choice equals 3
 Calculate res = a * b
 else if Choice equals 4
 Calculate res = a / b
o Output Result, res

# !/bin/bash
 
# Take user Input
echo "Enter Two numbers : "
read a
read b
 
# Input type of operation
echo "Enter Choice :"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
read ch
 
# Switch Case to perform
# calculator operations
case $ch in
  1)res=`echo $a + $b | bc`
  ;;
  2)res=`echo $a - $b | bc`
  ;;
  3)res=`echo $a \* $b | bc`
  ;;
  4)res=`echo "scale=2; $a / $b" | bc`
  ;;
esac
echo "Result : $res"

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy