OS Lab#02
OS Lab#02
Operating systems
SHELL PROGRAMMING
LAB MANUAL 2
Date:
Name:
Reg#: Group:
Marks: Signature:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Operating systems
Lab Objective: This lab introduces few of the basic commands of Linux.
Getting Started with Linux
The login prompt may be graphical or simple text
If text, logging in will present a shell
If graphical, logging in will present a desktop
o Some combination of mouse and keystrokes will make a terminal
window appear
o A shell runs in the terminal window
Linux Command Line
The shell is where commands are invoked
A command is typed at a shell prompt
o Prompt usually ends in a dollar sign ($)
After typing a command press Enter to invoke it
o The shell will try to obey the command
o Another prompt will appear
Example:
$ date
Sat March 01 11:59:05 BST 2008
$
o The dollar represents the prompt in this course, do not type it
Logging Out
To exit from the shell, use the exit command
Pressing Ctrl+D at the shell prompt will also quit the shell
o Quitting all programs should log you out
o If in a text-only single-shell environment, exiting the shell should be
sufficient
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Operating systems
In a window environment, the window manager should have a log out command
for this purpose
After logging out, a new login prompt should be displayed
Command Syntax
Most commands take parameters
o Some commands require them
o Parameters are also known as arguments
o For example, echo simply displays its arguments:
$ echo
$ echo Hello there
Hello there
Commands are case-sensitive
o Usually lower-case
$ echo whisper
whisper
$ ECHO SHOUT
bash: ECHO: command not found
Files
Data can be stored in a file
Each file has a filename
o A label referring to a particular file
o Permitted characters include letters, digits, hyphens (-), underscores (_),
and dots (.)
o Case-sensitive — NewsCrew.mov is a different file from NewScrew.mov
The ls command lists the names of files
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Operating systems
Operating systems
Operating systems
Filename Completion
The shell can making typing filenames easier
Once an unambiguous prefix has been typed, pressing Tab will automatically
‘type’ the rest
For example, after typing this:
$ rm sho
Pressing Tab may turn it into this:
$ rm shopping_list
This also works with command names
o For example, da may be completed to date if no other commands start ‘da’
Command History
Often it is desired to repeat a previously-executed command
The shell keeps a command history for this purpose
o Use the Up and Down cursor keys to scroll through the list of previous
commands
o Press Enter to execute the displayed command
Commands can also be edited before being run
o Particularly useful for fixing a typo in the previous command
o The Left and Right cursor keys navigate across a command
o Extra characters can be typed at any point
o Backspace deletes characters to the left of the cursor
o Del and Ctrl+D delete characters to the right
Take care not to log out by holding down Ctrl+D too long
Skills Developed
By completing the second lab, one should have basic understanding of Linux
environment and few Linux commands.
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Operating systems
Lab Exercises
(Note: you have to perform each lab exercise and submit them accordingly with
snapshots and suitable commands with them. Submit lab exercises only, not whole
manual)
Q1
a. Log in. Open a terminal window, to start a shell.
b. Exit from the shell; the terminal window will close.
c. Start another shell. Enter each of the following commands in turn.
i. date
ii. whoami
iii. hostname
iv. uname
v. uptime
Q2
a. Use the ls command to see if you have any files.
b. Create a new file using the cat command as follows:
$ cat > hello.txt
Hello world!
This is a text file.
c. Press Enter at the end of the last line, then Ctrl+D to denote the end of the file.
d. Use ls again to verify that the new file exists.
e. Display the contents of the file.
f. Display the file again, but use the cursor keys to execute the same command again
without having to retype it.
Q3
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Operating systems