Vous êtes sur la page 1sur 15

Q2.

We set GID in this manner as we wanted that a particular


number of users be in a particular group.

TASK 3 :

Q1.

sumit@sumit-desktop:~$ mkdir depts

sumit@sumit-desktop:~$ cd depts

sumit@sumit-desktop:~/depts$ mkdir {sales,hr,web}

sumit@sumit-desktop:~/depts$ ls

hr sales web

sumit@sumit-desktop:~/depts$ cd ..

Q2.
sumit@sumit-desktop::~$ cd depts.

sumit@sumit-desktop::~/depts$ chgrp john sales

sumit@sumit-desktop::~/depts$ chgrp sumit sales

sumit@sumit-desktop::~/depts$ chgrp dave hr

sumit@sumit-desktop::~/depts$ chgrp bob hr

sumit@sumit-desktop::~/depts$ chgrp zak web

sumit@sumit-desktop::~/depts$ chgrp eddy web

Q3.

sumit@sumit-desktop:~$ chmod 755 depts

sumit@sumit-desktop:~$ chmod 770 depts/{sales,hr,web}

sumit@sumit-desktop:~/depts$ ls -l

total 12

drwxrwx--- 2 sumit sumit 4096 2010-09-0420:05 hr

drwxrwx--- 2 sumit sumit 4096 2010-09-0420:05 sales

drwxrwx--- 2 sumit sumit 4096 2010-09-0420:05 web


ADVANCE EXPERIMENTS 3

TASK 1 :

Q1.

sumit@sumit-desktop:~$ pwd

/home/sumit

sumit@sumit-desktop:~$ whoami

sumit

sumit@sumit-desktop:~$ groups

admin adm dialout fax cdrom floppy tape audio dip video
plugdev fuse lpadmin netdev sambashare

sumit@sumit-desktop:~$ id

uid=1000(sumit) gid=119(admin)
groups=4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape
),29(audio),30(dip),44(video),46(plugdev),104(fuse),105(lpadmi
n),112(netdev),119(admin),122(sambashare)

Q2.

sumit@sumit-desktop:~$ users

sumit sumit

sumit@sumit-desktop:~$ who

sumit tty7 2010-09-0416:00(:0)

sumit pts/0 2010-09-0416:01 (:0.0)

sumit@sumit-desktop:~$ w

16:06:23 up 6 min, 2 users, load average: 0.35, 0.25, 0.12

USER TTY FROM LOGIN@ IDLE JCPU


PCPU WHAT

administ tty7 :0 16:00 5:56 4.55s 0.06s


gnome-session
administ pts/0 :0.0 16:01 0.00s 0.70s
0.01s w

Q3.

sumit@sumit-desktop:~$ su - john

Password:

No directory, logging in with HOME=/

$ whoami

john

$ groups

Sales adm dialout fax cdrom floppy tape audio dip video
plugdev fuse lpadmin admin sambashare

$ id

uid=1001(john) gid=10000(Sales)
groups=4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape
),29(audio),30(dip),44(video),46(plugdev),104(fuse),105(lpadmi
n),119(admin),122(sambashare),10000(Sales)

Q4.

$ users

sumit sumit

$ who

sumit tty7 2010-09-0416:00(:0)

sumit pts/0 2010-09-0416:01 (:0.0)

$ w

16:07:11 up 7 min, 2 users, load average: 0.06, 0.17, 0.10

USER TTY FROM LOGIN@ IDLE JCPU


PCPU WHAT

administ tty7 :0 16:00 7:44 4.96s 0.06s


gnome-session

administ pts/0 :0.0 16:01 0.00s 0.72s


0.88s gnome-terminal
TASK 2 :

$ su - sumit

Password:

sumit@sumit-desktop:~$ id

uid=1000(sumit) gid=119(admin)
groups=4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape
),29(audio),30(dip),44(video),46(plugdev),104(fuse),105(lpadmi
n),112(netdev),119(admin),122(sambashare)

sumit@sumit-desktop:~$ pwd

/home/sumit

sumit@sumit-desktop:~$ su john

Password:

$ id

uid=1001(john) gid=10000(Sales)
groups=4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape
),29(audio),30(dip),44(video),46(plugdev),104(fuse),105(lpadmi
n),119(admin),122(sambashare),10000(Sales)

$ pwd

$ su sumit

Password:

sumit@sumit-desktop:/$ pwd

sumit@sumit-desktop:/$ id

uid=1000(sumit) gid=119(admin)
groups=4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape
),29(audio),30(dip),44(video),46(plugdev),104(fuse),105(lpadmi
n),112(netdev),119(admin),122(sambashare)

sumit@sumit-desktop:/$ whoami

sumit

sumit@sumit-desktop:/$ su - sumit

Password:
sumit@sumit-desktop:~$ pwd

/home/sumit

sumit@sumit-desktop:~$ id

uid=1000(sumit) gid=119(admin)
groups=4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape
),29(audio),30(dip),44(video),46(plugdev),104(fuse),105(lpadmi
n),112(netdev),119(admin),122(sambashare)

sumit@sumit-desktop:~$ users

sumit sumit

TASK 3:

Q1.

sumit@sumit-desktop:~$ umask

0022

Q2.

sumit@sumit-desktop:~$ touch {umtest1,umtest2}

sumit@sumit-desktop:~$ ls

depts Documents examples.desktop nit projects


sales typescript umtest1 Videos

Desktop Downloads Music Pictures Public


Templates Ubuntu One umtest2

sumit@sumit-desktop:~$ mkdir umtestdir1

sumit@sumit-desktop:~$ ls

depts Documents examples.desktop nit projects


sales typescript umtest1 umtestdir1

Desktop Downloads Music Pictures Public


Templates Ubuntu One umtest2 Videos

Q3.

sumit@sumit-desktop:~$ umask 027

sumit@sumit-desktop:~$ touch {umtest3,umtest4}

sumit@sumit-desktop:~$ mkdir umtestdir2

sumit@sumit-desktop:~$ ls

depts Documents examples.desktop nit projects


sales typescript umtest1 umtest3 umtestdir1 Videos
Desktop Downloads Music Pictures Public
Templates Ubuntu One umtest2 umtest4 umtestdir2

sumit@sumit-desktop:~$ ls -ld um*

-rw-r--r-- 1 sumit admin 0 2010-09-0421:15 umtest1

-rw-r--r-- 1 sumit admin 0 2010-09-0421:15 umtest2

-rw-r----- 1 sumit admin 0 2010-09-0421:17 umtest3

-rw-r----- 1 sumit admin 0 2010-09-0421:17 umtest4

drwxr-xr-x 2 sumit admin 4096 2010-09-0421:16 umtestdir1

drwxr-x--- 2 sumit admin 4096 2010-09-0421:17 umtestdir2

sumit@sumit-desktop:~$
ADVANCE EXPERIMENTS 4

TASK1:

Q1.

sumit@sumit-desktop:~$ ln words hard

sumit@sumit-desktop:~$ ln -s words soft

Q2.

sumit@sumit-desktop:~$ head hard

sumit@sumit-desktop:~$ head soft

sumit@sumit-desktop:~$ head words

sumit@sumit-desktop:~$ ls

depts Documents examples.desktop Music Pictures Public


soft typescript umtest1 umtest3 umtestdir1 Videos

Desktop Downloads hard nit projects sales


Templates Ubuntu One umtest2 umtest4 umtestdir2 words

Q3.

sumit@sumit-desktop:~$ ls -il hard soft

159319 -rw-r--r-- 2 sumit admin 0 2010-08-29 11:50 hard

148477 lrwxrwxrwx 1 sumit admin 5 2010-08-29 11:51 soft ->


words

sumit@sumit-desktop:~$ stat hard soft

File: `hard'

Size: 0 Blocks: 0 IO Block: 4096


regular empty file

Device: 700h/1792d Inode: 159319 Links: 2


Access: (0644/-rw-r--r--) Uid: ( 1000/sumit) Gid: ( 119/
admin)

Access: 2010-08-29 11:52:50.496452561 +0530

Modify: 2010-08-29 11:50:55.486453299 +0530

Change: 2010-08-29 11:51:25.776452736 +0530

File: `soft' -> `words'

Size: 5 Blocks: 0 IO Block: 4096


symbolic link

Device: 700h/1792d Inode: 148477 Links: 1

Access: (0777/lrwxrwxrwx) Uid: ( 1000/sumit) Gid: ( 119/


admin)

Access: 2010-08-29 11:52:55.866453368 +0530

Modify: 2010-08-29 11:51:48.986453314 +0530

Change: 2010-08-29 11:51:48.986453314 +0530

a) Reported file size of Hard 0 and soft 5.

b) Actual number of data blocks used by hard 0 and soft 0.

c) Link count listed for Hard 2 and soft 1.

d) Ownership ( UID/GID) for Hard 1000/sumit 119/ admin and


Soft 1000/sumit 119/ admin.

sumit@sumit-desktop:~$ ln words hard

ln: creating hard link `hard': File exists

sumit@sumit-desktop:~$ ln word soft ; ls

ln: accessing `word': No such file or directory

depts Documents examples.desktop Music Pictures Public


soft typescript umtest1 umtest3 umtestdir1 Videos

Desktop Downloads hard nit projects sales


Templates Ubuntu One umtest2 umtest4 umtestdir2 words

Q4.

No we cannot make hard link to a target exiting already.

sumit@sumit-desktop:~$ ln -s sumit soft1

sumit@sumit-desktop:~$ ls

depts Downloads Music projects soft


typescript umtest2 umtestdir1 words
Desktop examples.desktop nit Public soft1
Ubuntu One umtest3 umtestdir2

Documents hard Pictures sales Templates


umtest1 umtest4 Videos

sumit@sumit-desktop:~$ ln -s sumit soft1 ; ls

ln: creating symbolic link `soft1': File exists

depts Downloads Music projects soft


typescript umtest2 umtestdir1 words

Desktop examples.desktop nit Public soft1


Ubuntu One umtest3 umtestdir2

Documents hard Pictures sales Templates


umtest1 umtest4 Videos

sumit@sumit-desktop:~$ ln -s niti soft2 ; ls

depts Downloads Music projects soft


Templates umtest1 umtest4 Videos

Desktop examples.desktop nit Public soft1


typescript umtest2 umtestdir1 words

Documents hard Pictures sales soft2 Ubuntu


One umtest3 umtestdir2

sumit@sumit-desktop:~$ ls -il soft2

159324 lrwxrwxrwx 1 sumit admin 4 2010-08-29 11:57 soft2 ->


niti

Q5.

Yes we can make a symbolic link to a "target" that doesnot


exist. The output of ls indicates by highlighting it in a
different colour from normal soft link made to an existing
target.

sumit@sumit-desktop:~$ ln soft hard1 ; ls -li hard1

148477 lrwxrwxrwx 2 sumit admin 5 2010-08-29 11:51 hard1 ->


words

Q6.

Yes we can make a hard link to a symbolic link. The hard link
made so becomes a soft link which acts a soft link made to
original target file.

TASK2:

Q1.

sumit@sumit-desktop:~$ df
Filesystem 1K-blocks Used Available Use%
Mounted on

/dev/loop0 9821012 2230724 7091396 24% /

none 501972 300 501672 1% /dev

none 506640 1504 505136 1%


/dev/shm

none 506640 80 506560 1%


/var/run

none 506640 0 506640 0%


/var/lock

none 506640 0 506640 0%


/lib/init/rw

/dev/sdb1 40957684 37253412 3704272 91% /host

/dev/sr0 706626 706626 0 100%


/media/Linux

Q2.

sumit@sumit-desktop:~$ df -h

Filesystem Size Used Avail Use% Mounted on

/dev/loop0 9.4G 2.2G 6.8G 24% /

none 491M 300K 490M 1% /dev

none 495M 1.5M 494M 1% /dev/shm

none 495M 80K 495M 1% /var/run

none 495M 0 495M 0% /var/lock

none 495M 0 495M 0% /lib/init/rw

/dev/sdb1 40G 36G 3.6G 91% /host

/dev/sr0 691M 691M 0 100% /media/Linux

sumit@sumit-desktop:~$ df -H

Filesystem Size Used Avail Use% Mounted on

/dev/loop0 11G 2.3G 7.3G 24% /

none 515M 308k 514M 1% /dev

none 519M 1.6M 518M 1% /dev/shm

none 519M 82k 519M 1% /var/run

none 519M 0 519M 0% /var/lock


none 519M 0 519M 0% /lib/init/rw

/dev/sdb1 42G 39G 3.8G 91% /host

/dev/sr0 724M 724M 0 100% /media/Linux

sumit@sumit-desktop:~$ ls -li

total 64

159039 drwxr-xr-x 5 sumit sumit 4096 2010-08-29 00:06 depts

129906 drwxr-xr-x 2 sumit sumit 4096 2010-09-0401:22 Desktop

129919 drwxr-xr-x 2 sumit sumit 4096 2010-09-0401:22 Documents

129911 drwxr-xr-x 2 sumit sumit 4096 2010-09-0401:22 Downloads

159036 -rw-r--r-- 1 sumit sumit 179 2010-09-0401:19


examples.desktop

159319 -rw-r--r-- 2 sumit admin 0 2010-08-29 11:59


hard

148477 lrwxrwxrwx 2 sumit admin 5 2010-08-29 11:51


hard1 -> words

129929 drwxr-xr-x 2 sumit sumit 4096 2010-09-0401:22 Music

159223 drwxr-xr-x 2 sumit sumit 4096 2010-09-0423:43 nit

129940 drwxr-xr-x 3 sumit sumit 4096 2010-09-0423:45 Pictures

159243 drwxr-xr-x 5 sumit sumit 4096 2010-09-0422:57 projects

129918 drwxr-xr-x 2 sumit sumit 4096 2010-09-0401:22 Public

159490 -rw-r--r-- 1 sumit sumit 0 2010-09-0423:56 sales

148477 lrwxrwxrwx 2 sumit admin 5 2010-08-29 11:51


soft -> words

159323 lrwxrwxrwx 1 sumit admin 6 2010-08-29 11:56


soft1 -> sumit

159324 lrwxrwxrwx 1 sumit admin 4 2010-08-29 11:57


soft2 -> niti

129916 drwxr-xr-x 2 sumit sumit 4096 2010-09-0401:22 Templates

148404 -rw-r--r-- 1 sumit sumit 895 2010-09-0401:55


typescript

159265 drwxrwxr-x 2 sumit sumit 4096 2010-09-0423:43 Ubuntu


One

159149 -rw-r--r-- 1 sumit admin 0 2010-08-29 11:47


umtest1
159310 -rw-r--r-- 1 sumit admin 0 2010-08-29 11:47
umtest2

159316 -rw-r----- 1 sumit admin 0 2010-08-29 11:48


umtest3

159317 -rw-r----- 1 sumit admin 0 2010-08-29 11:48


umtest4

159154 drwxr-xr-x 2 sumit admin 4096 2010-09-0421:16


umtestdir1

159318 drwxr-x--- 2 sumit admin 4096 2010-09-0421:17


umtestdir2

129941 drwxr-xr-x 2 sumit sumit 4096 2010-09-0401:22 Videos

159319 -rw-r--r-- 2 sumit admin 0 2010-08-29 11:59


words

Q3.

df -h represent free space in terms of 1000 and df -H


represent free space in terms of 1024.
SCRIPT TO PERFORM ARITHMETIC OPERATIONS ON TWO NUMBERS

echo "Enter the first number x : "

read x

echo "Enter the second number y : "

read y

echo "The numbers x and y are : $x $y "

sum=`expr $x + $y`

echo "The sum of numbers is : $sum "

sub=`expr $x - $y`

echo "The difference of numbers is : $sub"

mul=`expr $x \* $y`

echo "The product of numbers is : $mul"

div=`expr $x / $y`

echo "The division of numbers is : $div"

OUTPUT

sumit@sumit-desktop:~$ vi arithmetic

sumit@sumit-desktop:~$ sh arithmetic

Enter the first number x :

Enter the second number y :

The numbers x and y are : 8 4

The sum of numbers is : 12

The difference of numbers is : 4

The product of numbers is : 32

The division of numbers is : 2

sumit@sumit-desktop:~$

SCRIPT TO FIND WHETHER NUMBER IS EVEN OR ODD


echo "Enter the number : "

read x

y=`expr $x % 2`

if [ $y -eq 0 ] ; then

echo "The number is even"

else

echo "The number is odd"

fi

OUTPUT

sumit@sumit-desktop:~$ vi even

sumit@sumit-desktop:~$ sh even

Enter the number :

10

The number is even

sumit@sumit-desktop:~$ sh even

Enter the number :

The number is odd

SCRIPT TO FIND THE GREATEST OF THREE NUMBERS


echo "Please enter three numbers : "

read a b c

# compare a with b and c

if [ $a -gt $b -a $a -gt $c ]

then

big=$a

elif [ $b -gt $a -a $b -gt $c ] # compare b with a and c

then

big=$b

elif [ $c -gt $a -a $c -gt $b ] # compare c with a and b

then

big=$c

elif [ $a -eq $b -a $a -eq $c -a $b -eq $c -a $c -eq $b ] #


see if all of them are equal or not

then

big="All three numbers are same (equal)"

fi

echo "Result : $big"

OUTPUT

sumit@sumit-desktop:~$ vi greatest

sumit@sumit-desktop:~$ sh greatest

Please enter three numbers :

4 8 9

Result : 9

Vous aimerez peut-être aussi