Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
M. Tech IT
Page 2
14PGIT014
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
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
Page 4
14PGIT014
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
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
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
14. cd /etc
15. ls -al |more
M. Tech IT
Page 8
14PGIT014
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
/initrd
/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
/mnt
Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.
/net
/opt
/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
/tmp
Temporary space for use by the system, cleaned upon reboot, so don't use this for
saving any work!
/usr
/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
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
M. Tech IT
Page 11
14PGIT014
Page 12
14PGIT014
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?
M. Tech IT
Page 13
14PGIT014
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
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
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
-i
M. Tech IT
Page 16
14PGIT014
-R
M. Tech IT
Page 17