0% found this document useful (0 votes)
45 views9 pages

Linux Exp

The document describes a shell script to find the smallest of three numbers entered by the user. The script first prompts the user to enter three numbers. It then compares the numbers to find the smallest using if/else conditional statements. If the numbers are equal, it prints a message saying so, otherwise it prints the smallest number.

Uploaded by

rapil43576
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)
45 views9 pages

Linux Exp

The document describes a shell script to find the smallest of three numbers entered by the user. The script first prompts the user to enter three numbers. It then compares the numbers to find the smallest using if/else conditional statements. If the numbers are equal, it prints a message saying so, otherwise it prints the smallest number.

Uploaded by

rapil43576
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/ 9

Experiment No -7

Aim: Create a program to find out the inode number of any desired file.
Theory & Command Codes:
1. INODE
Every file in a Linux system has unique ID known as inode number. These unique IDs allow Linux
system to easily manage files in its filesystem database. In Linux, whenever a new file is created, it is
given a file name and an inode number. This number works as the unique identifier for that file. As a
user, we will use the file name to access the file but Linux OS will first map that filename with an
Inode number in a database to access the fil.

An inode is a data structure that points refer to the individual blocks, making the file. All of the
administrative data required to read a file is included in the inode. The metadata for each file is kept in
inodes in a table structure and this data includes:
 File types ( executable, block special etc )
 Permissions ( read, write etc )
 UID ( Owner )
 GID ( Group )
 FileSize
 Time stamps including last access, last modification and last inode number change.
 File deletion time
 Number of links ( soft/hard )
 Location of ile on harddisk.
 Some other metadata about file.
2. Commands:
 Using ls command: The -i option with ls commands displays inode number.
Example: $ ls -li

 Using stat command: stat command is used to view inode number of single file. It
basically provides lot of details about given file/directory, along with its inode number.
Example:$ stat ./html

OUTPUT
(NOTE: Output must draw on plane pages.)
Experiment No -8
Aim: Study & use of the Command for changing file permissions.
Theory & Command Codes:
1. FILE PERMISSIONS
File permissions are core to the security model used by Linux systems. They determine who can access
files and directories on a system and how. For effective security, Linux divides authorization into 2
levels.
1. Ownership
2. Permission
1.1 Linux File Ownership:
Every file and directory in Linux system is assigned 3 types of owner. They are:
1. User: A user is the owner of the file. By default, the person who created a file becomes its
owner. Hence, a user is also sometimes called an owner.
2. Group: A user- group can contain multiple users. All users belonging to a group will have the
same Linux group permissions access to the file.
3. Other: Any other user who has access to a file. This person has neither created the file, nor he
belongs to a user group who could own the file.
1.1 Linux File Permissions:
Every file and directory in /Linux system has following 3 permissions defined for all the 3 owners.
They are:
1. Read: This permission give you the authority to open and read a file. Read permission on a
directory gives you the ability to lists its content.
2. Write: The write permission gives you the authority to modify the contents of a file. The
write permission on a directory gives you the authority to add, remove and rename files
stored in the directory.
3. Execute: In Linux, we cannot run a program unless the execute permission is set.
2. COMMANDS
 ls – l

r = read permission
w = write permission
x = execute permission
– = no permission

 CHMOD Command
chmod’ command which stands for ‘change mode’. Using the command, we can set permissions (read,
write, execute) on a file/directory. There are 2 ways to use the command –
 Absolute mode
 Symbolic mode

Absolute(Numeric) Mode in Linux


In this mode, file permissions are not represented as characters but a three-digit octal number.
The table below gives numbers for all for permissions types.
Number Permission Type Symbol
0 No Permission —
1 Execute –x
2 Write -w-
3 Execute + Write -wx
4 Read r–
5 Read + Execute r-x
6 Read +Write rw-
7 Read + Write +Execute rwx
Symbolic Mode in Linux
In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can modify
permissions of a specific owner. It makes use of mathematical symbols to modify the Unix file
permissions.
Operator Description
+ Adds a permission to a file or directory

– Removes the permission

= Sets the permission and overrides the permissions set earlier.

The various owners are represented as –


User Denotations
u user/owner

g group

o other

a all

EXAMPLES:
1. $ chmod 755 public_dir
2. $ chmod 700 my_script

OUTPUT
(NOTE: Output must draw on plane pages.)

$ ls -ld public_dir
drwxr--r-- 1 ignatz staff 6023 Nov 2 12:06 public_dir
$ chmod 755 public_dir
$ ls -ld public_dir
drwxr-xr-x 1 ignatz staff 6023 Aug 5 12:06 public_dir

$ ls -l my_script
-rw------- 1 ignatz staff 6023 Nov 2 12:06 my_script
$ chmod 700 my_script
$ ls -l my_script
-rwx------ 1 ignatz staff 6023 Aug 5 12:06 my_script
Experiment No -9
Aim: Write a shell script that accepts any number of arguments and prints them in
the reverse order.
Theory & Command Codes:

1. SHELL SCRIPTING
Shell Scripting is a program to write a series of commands for the shell to execute. It can combine
lengthy and repetitive sequences of commands into a single and simple script that can be stored and
executed anytime which, reduces programming efforts. Shell Scripts are written using text editors.
Each shell script is saved with `.sh` file extension e.g., myscript.sh.
A shell script comprises the following elements –
 Shell Keywords – if, else, break etc.
 Shell commands – cd, ls, echo, pwd, touch etc.
 Functions
 Control flow – if..then..else, case and shell loops etc.

Need of shell scripts


There are many reasons to write shell scripts:

 To avoid repetitive work and automation


 System admins use shell scripting for routine backups.
 System monitoring
 Adding new functionality to the shell etc.

2. Shell Script to print command line arguments in reverse


#!/bin/sh
if [ $# -eq 00 ]
then
echo "no arguments given"
exit
fi
echo "Total number of arguments: $#"
echo "The arguments are: $*"
echo "The arguments in reverse order:"
rev=" "
for i in $*
do
rev=$i" "$rev
done
echo $rev

OUTPUT
(NOTE: Output must draw on plane pages.)

Output 1
$ ./print-arguments-in-reverse.sh
no arguments given

Output 2
$ ./print-arguments-in-reverse.sh Indians are great
Total number of arguments: 3
The arguments are: Indians are great
The arguments in reverse order:
great are Indians
Experiment No -10
Aim: Write a shell script to find the smallest of three numbers that are read from
the keyboard.
Theory & Command Codes:

2. Shell Script

.#!/bin/bash
echo "Enter 3 numbers"
read a
read b
read c
if [ $a -eq $b -a $b -eq $c ]
then
echo "All numbers are equal"
exit
fi
if [ $a -lt $b ]
then
s1=$a
s2=$b
else
s1=$b
s2=$a
fi
if [ $s1 -gt $c ]
then
s2=$s1
s1=$c
fi
echo "smallest number is $s1
OUTPUT
(NOTE: Output must draw on plane pages.)
Output 1
$ ./reverse.sh
Enter 3 numbers
589
smallest number is 5

Output 2
$ ./reverse.sh
Enter 3 numbers
888
All numbers are equal

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