linux assignment ii

18
UNIX Assignments: 2 1. List all the files and sub directories of the directory /bin. himanshu@ubuntu:~$ ls /bin bash dumpkeys mount sh bunzip2 echo mountpoint sh.distrib busybox ed mt sleep bzcat egrep mt-gnu static-sh bzcmp false mv stty bzdiff fgconsole nano su bzegrep fgrep nc sync bzexe fuser nc.openbsd tailf bzfgrep fusermount netcat tar bzgrep grep netstat tempfile bzip2 gunzip nisdomainname touch

Upload: himanshu-rustagi

Post on 31-Oct-2014

43 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Linux Assignment II

UNIX Assignments: 2

1. List all the files and sub directories of the directory /bin.

himanshu@ubuntu:~$ ls /bin

bash dumpkeys mount sh

bunzip2 echo mountpoint sh.distrib

busybox ed mt sleep

bzcat egrep mt-gnu static-sh

bzcmp false mv stty

bzdiff fgconsole nano su

bzegrep fgrep nc sync

bzexe fuser nc.openbsd tailf

bzfgrep fusermount netcat tar

bzgrep grep netstat tempfile

bzip2 gunzip nisdomainname touch

bzip2recover gzexe ntfs-3g true

bzless gzip ntfs-3g.probe ulockmgr_server

bzmore hostname ntfs-3g.secaudit umount

Page 2: Linux Assignment II

cat ip ntfs-3g.usermap uname

chgrp kbd_mode open uncompress

chmod kill openvt unicode_start

chown less pidof vdir

chvt lessecho ping vmmouse_detect

cp lessfile ping6 which

cpio lesskey plymouth ypdomainname

dash lesspipe ps zcat

date ln pwd zcmp

dbus-cleanup-sockets loadkeys rbash zdiff

dbus-daemon login readlink zegrep

dbus-uuidgen lowntfs-3g rm zfgrep

dd ls rmdir zforce

df lsmod rnano zgrep

dir mkdir run-parts zless

dmesg mknod sed zmore

dnsdomainname mktemp setfont znew

Page 3: Linux Assignment II

domainname more setupcon

2. List all the files including hidden files in your current directory.

himanshu@ubuntu:~$ ls -a

. .gconfd Pictures

.. .gnome2 play

.bash_history .gnome2_private .printer-groups.xml

.bash_logout .gstreamer-0.10 .profile

.bashrc .gtk-bookmarks Public

.cache .gvfs .pulse

.compiz him.sh .pulse-cookie

.config .him.txt.swp .recently-used.xbel

.dbus hr11.sh .sudo_as_admin_successful

Desktop hr9.sh .swp

.dmrc .ICEauthority system

Documents install.sh Templates

Downloads .local .thumbnails

.esd_auth .mozilla Videos

Page 4: Linux Assignment II

examples.desktop Music .xsession-errors

.fontconfig .nautilus .xsession-errors.old

.gconf .openoffice.org

3. List all the files starting with letter ‘r’ in your current directory.

himanshu@ubuntu:~$ ls -f r*

roshan .sh

4. List all the files having three characters in their names, from your current directory.

himanshu@ubuntu:~$ ls ???

him:

his:

5. List all the files with extension .doc in your current directory.

himanshu@ubuntu:~$ ls *.doc

Linux assignment-II.doc Linux assignment-III.doc Linux assignment-IV.doc

6. List all the files having the first letter of their name within the range ‘l’ to‘s’, from your current directory.

himanshu@ubuntu:~$ ls [l-s]*

Linux assignment-I.docx Linux assignment-III.doc roshan .sh

Linux assignment-II.doc Linux assignment-IV.doc

Music:

Page 5: Linux Assignment II

Pictures:

play:

Public:

system:

hardware software

7. Create a file text1 and read its input from keyboard.

himanshu@ubuntu:~$ cat > text1

hi i m himanshu doing mca rom dkes -scs

^C

8. Copy the contents of file text1 to another file text2.

himanshu@ubuntu:~$ cp text1 text2

himanshu@ubuntu:~$ cat text2

hi i m himanshu doing mca rom dkes -scs

9. Append the contents of file text2 to file text1.

himanshu@ubuntu:~$ cat >> text1 text2

himanshu@ubuntu:~$ cat text1

hi i m himanshu doing mca rom dkes -scs

Page 6: Linux Assignment II

hi i m himanshu doing mca rom dkes -scs

10. Count the number of files in the current directory.

himanshu@ubuntu:~$ ls|wc -w

29

11. Display the output of command ls –l to a file and on the output screen.

himanshu@ubuntu:~$ ls|cat > text3|cat text3

Desktop

Documents

Downloads

examples.desktop

him

him.sh

his

hr11.sh

hr9.sh

install.sh

Linux assignment-I.docx

Linux assignment-II.doc

Page 7: Linux Assignment II

Linux assignment-III.doc

Linux assignment-IV.doc

Music

Pictures

play

Public

roshan .sh

system

Templates

text1

text2

text3

Videos

12. From file text1 print all lines starting from 10th line.

himanshu@ubuntu:~$ tail -n +10 text3

install.sh

Linux assignment-I.docx

Linux assignment-II.doc

Page 8: Linux Assignment II

Linux assignment-III.doc

Linux assignment-IV.doc

Music

Pictures

Public

roshan .sh

system

Templates

text1

text2

text3

Videos

himanshu@ubuntu:~$

13. Find the number of users currently logged on to the system.

himanshu@ubuntu:~$ who|wc -l

2

14. Delete all the files with their names starting with “tmp”.

himanshu@ubuntu:~$ rm tmp*

Page 9: Linux Assignment II

rm: cannot remove `tmpe': Is a directory

15. List only the directories in your current directoryhimanshu@ubuntu:~$ ls -d

.

Section 2:1. Display your current working directory.

himanshu@ubuntu:~$ pwd

/home/himanshu

2. Create following directory structure under your Home directory(Note: Your home directory is where you login to.)

SYSTEM (SUB DIRECTORY)

HARDWARE (SUB-SUB DIRECTORY) SOFTWARE

INPUT OUTPUT (SUB-SUB-SUB) APPL SYS

MOUSE PRINTER ( FILES ) WORDSTAR OS SCANNER VDU (FILES ) LOTUS LINKERS

himanshu@ubuntu:~$ mkdir -p system/hardware/input

himanshu@ubuntu:~$ mkdir -p system/hardware/output

himanshu@ubuntu:~$ mkdir -p system/software/appl

himanshu@ubuntu:~$ mkdir -p system/software/sys

himanshu@ubuntu:~$ cd system/hardware/input

himanshu@ubuntu:~/system/hardware/input$ cat > mouse

i am mouse ^C

Page 10: Linux Assignment II

himanshu@ubuntu:~/system/hardware/input$ cat > scanner

iam scanner

^C

himanshu@ubuntu:~/system/hardware/input$ cd ..

himanshu@ubuntu:~/system/hardware$ cd output

himanshu@ubuntu:~/system/hardware/output$ cat > printer

i am a printer

^C

himanshu@ubuntu:~/system/hardware/output$ cat > vdu

i am a vedio display unit

^C

himanshu@ubuntu:~/system/hardware/output$ cd ../..

himanshu@ubuntu:~/system$ cd software/appl

himanshu@ubuntu:~/system/software/appl$ cat > wordstar

i am a wordstar

^C

himanshu@ubuntu:~/system/software/appl$ cat > lotus

i am a lotus

^C

himanshu@ubuntu:~/system/software/appl$ cd ..

himanshu@ubuntu:~/system/software$ cat > os

i am an os

^C

himanshu@ubuntu:~/system/software$

Page 11: Linux Assignment II

himanshu@ubuntu:~/system/software$ cat > linker

i am a linker

^C

himanshu@ubuntu:~/system/software$

3. List detailed information about all the files and directories of Hardware directory while your current directory is still the home directory.himanshu@ubuntu:~$ ls -l system/hardware

total 8

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:59 input

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 21:01 output

4. Change your current directory to SYS and list the names of all files and subdirectories in the directory sub tree starting that starts from your home directory.

himanshu@ubuntu:~$ cd system/software/sys

himanshu@ubuntu:~/system/software/sys$

himanshu@ubuntu:~/system/software/sys$ ls ~

Desktop him.sh Linux assignment-I.docx Pictures Videos

Documents his Linux assignment-II.doc play

Downloads hr11.sh Linux assignment-III.doc Public

examples.desktop hr9.sh Linux assignment-IV.doc system

him install.sh Music Templates

5. Copy the file SCANNER to directory SYSTEM while your current directory is APPL.

himanshu@ubuntu:~/system/software/appl$ cp ~/system/hardware/input/scanner ~/system/scanner.copy

himanshu@ubuntu:~/system/software/appl$

6. Rename the file SCANNER to SCAN. himanshu@ubuntu:~/system/software/appl$ mv ~/system/hardware/input/scanner

Page 12: Linux Assignment II

~/system/hardware/input/scan

7. Read some text form Keyboard and append it to the file SCAN.

himanshu@ubuntu:~/system/software/appl$ cat >> ~/system/hardware/input/scan

now i am scan

^C

himanshu@ubuntu:~/system/software/appl$

8. Remove the directory sub tree starting from SYSTEM in one go. (Note: This command is potentially dangerous)

himanshu@ubuntu:~$ rm -rf system

Page 13: Linux Assignment II

Section 3:1. List the contents of ls command page wise.

himanshu@ubuntu:~$ ls -l|more

total 276

drwxr-xr-x 3 himanshu himanshu 4096 2012-10-03 18:04 Desktop

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-02 08:36 Documents

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Downloads

-rw-r--r-- 1 himanshu himanshu 179 2012-08-28 14:50 examples.desktop

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:20 him

-rw-r--r-- 1 himanshu himanshu 17 2012-08-28 14:58 him.sh

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:20 his

-rw------- 1 himanshu himanshu 404 2012-09-29 21:07 hr11.sh

-rw-r--r-- 1 himanshu himanshu 601 2012-09-29 20:40 hr9.sh

-rw-r--r-- 1 himanshu himanshu 29583 2012-09-12 14:36 install.sh

-rw-r--r-- 1 himanshu himanshu 6366 2012-10-07 21:57 Linux assignment-I.docx

-rw-r--r-- 1 himanshu himanshu 56320 2012-09-25 10:14 Linux assignment-II.doc

-rw-r--r-- 1 himanshu himanshu 57856 2012-09-25 10:15 Linux assignment-III.doc

-rw-r--r-- 1 himanshu himanshu 59904 2012-09-25 10:16 Linux assignment-IV.doc

Page 14: Linux Assignment II

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Music

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Pictures

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-07 21:37 play

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Public

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Templates

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Videos

2. Create a file FILE2 with some text in it. Increase the no. of hard links to the file FILE2 to 3 and check the inode number and link count for those names.himanshu@ubuntu:~$ cat >> file2

hlo i m himanshu how are you

^C

himanshu@ubuntu:~$ ln file2 file22

himanshu@ubuntu:~$ ln file2 file21

himanshu@ubuntu:~$ ln file2 file23himanshu@ubuntu:~$ ls -i file2*

418754 file2 418754 file21 418754 file22 418754 file23

himanshu@ubuntu:~$ ls -l file2*

-rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file2

-rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file21

-rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file22

-rw-r--r-- 4 himanshu himanshu 29 2012-10-08 23:10 file23

3. Using one single command, display the output of “who” and “pwd” commands.himanshu@ubuntu:~$ who;pwd

Page 15: Linux Assignment II

himanshu tty7 2012-10-08 23:03 (:0)

himanshu pts/0 2012-10-08 23:04 (:0.0)

himanshu pts/1 2012-10-08 23:13 (:0.0)

/home/himanshu

4. Find out whether the users with a pattern“itp9” in their names have logged in ?

himanshu@ubuntu:~$ who|cut -d " " -f1|fgrep itp9

5. Find out whether a particular user “itp9” has logged in ?

log.sh

n=`expr who|cut -d " " -f1|fgrep itp9|wc -l`

if [ $n -ne 0];

then

echo "no"

else

echo "yes"

fi