Sei sulla pagina 1di 17

14PGIT014

IT720: ADVANCED OPERATING SYSTEM


PRACTICAL 1(a)

Aim: To study Linux commands and its basic applications . Perform the actions as stated and
answer the questions.
EXERCISE 1
1. Log on a Linux machine Enter your login (user name) and password at relevant prompts.
2. Enter these commands at the UNIX prompt, and try to interpret the output.
1. echo hello world
It takes the input given along with the command and displays it on the screen.
2. passwd
It allows user to change current Unix password.
It asks for current password for authentication and then asks for new password.
Normal user can change his password only, whereas Super user can change pwd for any
other user too. It also allows to lock/unlock password, expire pwd, make account inactive,
set pwd validity
period etc..
3. date
It allows to set or display system date and time in desired format.
Format can be controlled by format options, OR by STRING option.
The display includes Day, Month, time( h/m/s), time zone, year
4. hostname
Hostname is used to display the system's DNS name, and to display set its hostname or
NIS domain name.
5. arch
It prints machine hardware/Architecture name.
6. uname -a
Prints system information, specified by options. -a option gives all info.
Info. May include Kernal, node name, kernal rel/ver, machine hardware name, processor
type, hardware platform, OS, date and time
7. dmesg | more (you may need to press q to quit)
It reads all messages from kernel ring buffer and Prints it OR it controls the kernel ring
buffer. The Options include to clear the buffer, to set console on/off for printing, showing
time delta betw. Messages, set buffer size, set message logging level etc..
It displays all device drivers loaded, hardware info, of all ports, total and shared memory
details.
a. Display all the devices drivers loaded in to kernel.

M. Tech IT

Page 1

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

b. Display hardware information related to Ethernet port eth0

c. Display USB details

M. Tech IT

Page 2

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

d. Display total memory available and shared memory details

8. uptime
Gives a one line display of the following information. The current time, how long the
system has been running, how many users are currently logged on, and the system load
averages for the past 1, 5,and 15 minutes.
9. who am i
Print the user name , last logon time associated with the current effective user ID.
10. who
Prints information about users who are currently logged in.
11. id
Prints user and group information for the specified USERNAME, or for the current user
12. last
Last searches back through the file /var/log/wtmp (or the file designated by the -f flag)
and displays a list of all users logged in (and out) since that file was created. Names of
M. Tech IT

Page 3

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

users and tty's can be given, in which case last will show only those entries matching
the arguments.
13. finger
user information lookup program.
Options are: -s: displays the user's login name, real name, terminal name, idle time, login
time, office location and office phone number.
-l Produces a multi-line format displaying all of the information described for the -s option
as well as the user's home directory, home phone number, login shell, mail status
14. w
Displays information about the users currently on the machine, and their processes. The
header shows, in this order, the current time, how long the system has been running,
how many users are currently logged on, and the system load averages for the past 1, 5, and
15 minutes.
15. top (you may need to press q to quit)
The top program provides a dynamic real-time view of a running system. It can display
system summary information as well as a list of tasks currently being managed by the
Linux kernel The program provides a limited interactive interface for process manipulation
as well as a much more extensive interface for personal configuration
a. Find out what each column indicates
Columns may include : PID, User ID, Priority, Resident/Swap memory used, % CPU/MEM
usage etc..
16. echo $SHELL
It displays Shell program currently used, which is stored in variable $SHELL
There are different Shells including Born, Corn, C shell
17. echo {con,pre}{sent,fer}{s,ed}
It combines words from sets given along and displays all combinations in given order

18. man ls (you may need to press q to quit)


man command gives detailed info. About any UNIX command specified
man ls gives all info. About LS command and various options it offers
19. man who (you may need to press q to quit)
man command gives detailed info. About any UNIX command specified
man who gives all info. About WHO command and various options it offers
20. who can tell me why i got divorced
Invaild options specificed along with WHO, so it gives error message
Who displays only 2 strings specified, but 3rd string gives error
21. clear
M. Tech IT

Page 4

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

it clears the screen


22. cal 2000
It displays calendar for specified year

23. cal 9 1752 (do you notice anything unusual?)


Some dates are missing ( 3-13) in Sep 1752 calendar.

The guy that originally wrote the "cal" command on some old Version 7 machine had an off-by-one
error in his code. This showed up as some erroneous output when a malloc'd variable overwrote 12
extra bytes with zeroes, thus leading to the strange calendar output seen above.
24. bc -l (type quit or press Ctrl-d to quit)
BC is command line calculator program for Linux. -l option defines standard math library, and
allows to do math calculations in interactive mode.

M. Tech IT

Page 5

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

25. echo 5+4 | bc -l


Output of echo is passed to bc, which calculates the expr. and gives result 9

26. yes please (you may need to press Ctrl-c to quit)


yes outputs the string following it, repeatedly untill it's killed by Ctrl-c.
27. time sleep 5
The time command runs the specified program command with the given arguments. When
command finishes, time writes a message to standard output giving timing statistics about
this program run. These statistics consist of (i) the elapsed real time between invocation and
termination, (ii) the user CPU time (the sum of the tms_utime and tms_cutime values in a
struct tms as returned by times(2)), and (iii) the system CPU time28. history

Exercise : 2
Try the following command sequence:
1. cd
/home/ritesh -------No change to dir
2. pwd
/home/ritesh --------Gives prensent dir
3. ls -al
Lists all files and subdirectories in current directory
4. cd .
/home/ritesh -------No change to dir
5. pwd (where did that get you?)
/home/ritesh -------No change to dir
6. cd ..
/home ----------Moves to parent dir
M. Tech IT

Page 6

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

7. pwd
/home
8. ls -al
9. cd ..
10. pwd
/ -----------Root Directory
11. ls -al

12. cd ..
13. pwd (what happens now)
/ ----------------------It stays in root directory, no change.

M. Tech IT

Page 7

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

14. cd /etc
15. ls -al |more

16. cat passwd (What does file contain)


/etc/passwd is a text file, that contains a list of the system's accounts, giving for each account some
useful information like user ID, group ID, home directory, shell, etc.
The encrypted users passwords are stored in /etc/shadow file which is readable by only superuser.

M. Tech IT

Page 8

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

17. cd 18. pwd


/---------------------It moves to root directory
2. Continue to explore the filesystem tree using cd, ls, pwd and cat. Look in /bin, /usr/bin,
/sbin, /tmp and /boot. What do you see?Explain the functioning of each file system in brief.
Directory Content
/bin

Common programs, shared by the system, the system administrator and the users.

/boot

The startup files and the kernel, vmlinuz. In some recent distributions also grub data.
Grub is the GRand Unified Boot loader and is an attempt to get rid of the many
different boot-loaders we know today.

/dev

Contains references to all the CPU peripheral hardware, which are represented as files
with special properties.

/etc

Most important system configuration files are in /etc, this directory contains data
similar to those in the Control Panel in Windows

/home

Home directories of the common users.

/initrd

(on some distributions) Information for booting. Do not remove!

/lib

Library files, includes files for all kinds of programs needed by the system and the
users.

/lost+found

Every partition has a lost+found in its upper directory. Files that were saved during
failures are here.

/misc

For miscellaneous purposes.

/mnt

Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.

/net

Standard mount point for entire remote file systems

/opt

Typically contains extra and third party software.

/proc

A virtual file system containing information about system resources. More information
about the meaning of the files in proc is obtained by entering the command man proc
in a terminal window. The file proc.txt discusses the virtual file system in detail.

/root

The administrative user's home directory. Mind the difference between /, the root
directory and /root, the home directory of the root user.

/sbin

Programs for use by the system and the system administrator.

/tmp

Temporary space for use by the system, cleaned upon reboot, so don't use this for
saving any work!

/usr

Programs, libraries, documentation etc. for all user-related programs.

/var

Storage for all variable files and temporary files created by users, such as log files, the
mail queue, the print spooler area, space for temporary storage of files downloaded
from the Internet, or to keep an image of a CD before burning it.

M. Tech IT

Page 9

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

3. Explore /dev. Can you identify what devices are available? Which are character-oriented
and which are block-oriented? Can you identify your tty. (terminal)device (typing who am i
might help); who is the owner of your tty (use ls -l)?

serial ports are displayed with ttyS0-ttyS3, other than than keyboard, mouse, console are serial charoriented devices. Disk, USB, audio/video, CD/DVD devices are block oriented
4. Explore /proc. Display the contents of the files interrupts, devices, cpuinfo, meminfo and
uptime using cat. Can you see why we say /proc is a pseudo-filesystem which allows access to
kernel data structures?
procfs (or the proc filesystem) is a special filesystem that presents information about processes and
other system information in a hierarchical file-like structure, providing a more convenient and
standardized method for dynamically accessing process data held in the kernel than traditional
tracing methods or direct access to kernel memory. Typically, it is mapped to a mount point
named /proc at boot time.
inside /proc, there is a directory for each running process, named with its process ID. These
directories contain files that have useful information about the processes, such as exe, which is a
symbolic link to the file on disk the process was started from
cwd, which is a symbolic link to the working directory of the process
wchan, which, when read, returns the waiting channel the process is on
maps, which, when read, returns the memory maps of the process
/proc/cmdline returns the command line passed to the running kernel
M. Tech IT

Page 10

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

/proc/cpuinfo returns information about the running CPUs


/proc/uptime returns the uptime as two decimal values in seconds, separated by a space: the
amount of time since the kernel was started
the amount of time that the kernel has been idle
/proc/version returns detailed information about the kernel; more than you'd get from uname -a

M. Tech IT

Page 11

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

5. Change to the home directory of another user directly, using cd ~username. 4


6. Change back into your home directory.
7. Make subdirectories called work and play.
$mkdir work
$mkdir play
8. Delete the subdirectory called work.
$rmdir work
9. Copy the file /etc/passwd into your home directory.

10. Move it into the subdirectory play.


cp passwd ./play
11. What is a hard & soft(symbolic) link. How it can be created? Change into
subdirectory play and create a symbolic link called terminal that points to your tty device.
What happens if you try to make a hard link to the tty device?
SOft / Symb. link doesnt contain any information about contents of the file, instead of that, it
simply contains the pointer to the location of the destination file. In more technical words, in soft
link, a new file is created with a new inode, which have the pointer to the inode location of the
original file.
M. Tech IT

Page 12

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

In softlink a new file and a new Inode is created, but in hard link, only an entry into directory
structure is created for the file, but it points to the inode location of the original file. Which means
there is no new inode creation in the hard link.
If you want to link files across the filesystems, you can only use symlinks/soft links.
If you want to link directories, then you must be using Soft links, as you cant create a hard link to a
directory.

12. What is the difference between listing the contents of directory play with ls -l and ls -L?
ls -l gives list of files/directories with all details
ls -L dereferences symbolic links and gives only info. about files (original) and not the links

13. Create a file called hello.txt that contains the words "hello world". Can you use "cp "
using "terminal" as the source file to achieve the same effect?

14. Copy hello.txt to terminal. What happens?

M. Tech IT

Page 13

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

15. Imagine you were working on a system and someone accidentally deleted the ls command
(/bin/ls). How could you get a list of the files in the current directory? Try it.(Do not delete ls
command,copy it to some other location from bin)
1) echo *
2) find -maxdepth 1 -ls

16. How would you create and then delete a file called "$SHELL"? Try it.

M. Tech IT

Page 14

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

17. How would you create and then delete a file that begins with the symbol #?Try it.

18. How would you create and then delete a file that begins with the symbol -? Try it.

19. What is the output of the command: echo {con,pre}{sent,fer}{s,ed}? Now,from your home
directory, copy /etc/passwd and /etc/group into your home directory in one command given that
you can only type /etc once.

M. Tech IT

Page 15

14PGIT014

IT720: ADVANCED OPERATING SYSTEM

20. Still in your home directory, copy the entire directory play to a directory called
preserving the symbolic link.

work,

21. Delete the work directory and its contents with one command. Accept no complaints or queries.

22. Change into a directory that does not belong to you and try to delete all the files (avoid /proc or
/dev, just in case!)
23. Experiment with the options on the ls command. What do the d, i, R and F options do?
-F

show directories with a trailing '/' .


executable files with a trailing '*'

-i

print the inode number of each file

M. Tech IT

Page 16

14PGIT014
-R

IT720: ADVANCED OPERATING SYSTEM


list all subdirectories encountered

M. Tech IT

Page 17

Potrebbero piacerti anche