TITLE :- Work instruction Sheet / Unix/Linux programming
AIM OF EXPERIMENT:- Familiarize with Unix/Linux Logging/logout and simple
commands
TOOLS/LIABILITIES/ S/W USED:- Bash shell, vi editor, RedHat Linux 4.0
H/W/USED:- Standard PC
PRE CONDITION/INPUT:- Login name and password
POSTCONDITION: - Login successful
LOGGING AND LOGGING OUT:-
Logging in: - If you have the name puneet as your user id , you will be expected to enter
this name when you see a promote similarly to this on the terminal:
LOGIN :
This login promote screen can be in variable forms sometimes you may see the machine
name too (cozy every machine has a name is UNIX) one some system you may see
username instead
Since you now have an account Puneet entire this starting at the prompt. Then process
enters key over the string:
LOGIN: Puneet
Password:
The system now ask you to enter the password, it is a secrete code handled to you by
your Administrator.
So type your password:
Logon puneet
Password:
Unique advantage: You may see that the password your entered is not display on the
screen. This is another security features. If you type wrong password then press back
space key and retype your password , also when you entire some wrong enter then error
message will be displayed
LOGIN : incorrect
LOGIN
When your entire is valid then the first message after login you will get is :
Last login this sep. 16 [Link] on tty1
.
LOGGING OUT.---
There are some simple key board short kit and also by mouse:
$ (ctrl-d) –keep (ctrl) pressed and then press of login:
Ctrl+d is generated by pressing ctrl key and creator .The login message confirms that the
session has been terminated, m the terminal is evadible for the next user .If you do not
see the login but see this
Use log out to log out
It means that ctrl +d does not week.
You can use log out command tasted of ctrl +d -% log out (enter)-------% is the prompt.
Login:
Use exit command like layout.
SIMPLE COMMANDS
date:-date command prints system date and time
Syntax:-
date [OPTION]... [+FORMAT]
or:
date [OPTION] [MMDDhhmm[[CC]YY][.ss]]
where format can be
%D Date -MM/DD/YY
%H Hour -00 to 23
%I Hour -00 to 11
%M Minute -00 to 59
%s Second -00 to 59
%T Time -HH:MM:SS
%y Year's last two digits
%w Day of the week(0 for sunday ,1 for monday and so on )
%r Time in AM/PM
To display system date and time.
[root@192 ~]# date
Tue Dec 19 [Link] IST 2006
To display system time in AM/PM format.
[root@192 ~]# date +%r
[Link] AM
To display day of week.
[root@192 ~]# date +%w
2
To display date in MM/DD/YY format.
[root@192 ~]# date +%D
12/19/06
To display Hours.
[root@192 ~]# date +%H
09
To display Minutes.
[root@192 ~]# date +%M
30
To display Seconds.
[root@192 ~]# date +%S
44
who:-This command is used to display who is currently logged on the system.
syntax:-who
Checking who is currently logged on.
[root@192 ~]# who
root :0 Dec 19 08:55
root pts/1 Dec 19 09:08 (:0.0)
The first column of output represents the user names. The second column represents the
corresponding terminal names and remaining represents at which the users are logged on.
Linux is a multi-user operating system. So multiple can logged on at the same time.
who am i:-Tells who you are.
syntax:-who am i
Checking who you are.
[root@192 ~]# who am i
root pts/2 Dec 19 09:38 (:0.0)
cal:-This command will display calendar for specified month and year.
syntax:-cal [month] <year>
Display calendar for year 2006
[root@192 ~]# cal 2006
It will display calendar for year 2006.
Display calendar for first month of year 2006.
[root@192 ~]# cal 1 2006
January 2006
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
lpr:- This command is used to print one or more files on printer.
Syntax:-lpr [options] <file1> <file2>..........
Where options may be
m inform you when printing is over.
r removes files from directory after printing.
Printing a file on printer.
[root@192 ~]# lpr [Link]
Contents of file [Link] will be printed on printer.
tee:-It will send output to standard output as well as specified file. This command
performs the operation of pipe and redirection.
syntax:-<command> | tee <filename>
Example:-
[root@192 ~]# cat [Link]
hello
c
language is a middle level language
C++ is an object oriented language
java is purely object oriented language
[root@192 ~]# cat [Link]>[Link]
we can combine these two commands into single command using tee command.
[root@192 ~]# cat [Link] | tee [Link]
hello
c
language is a middle lavel language
C++ is an object oriented language
java is purely object oriented language
history:-To display to see list of remembered commands.
syntax:-history [option]
To see history of previously executed commands
[root@192 ~]# history
1 history
2 man clear
3 ln [Link] [Link]
4 ls -l [Link]
5 chmod 777 [Link]
clear:-To clear the screen
Syntax:-clear
Example:-To clear the screen
[root@192 ~]#clear
expr:-This command is used to perform arithmetic operations( operators + for addition,-
for subtraction ,* for multiplication , % for remainder ,/ for division is used) on integers.
Example:-To multiply 6 with 7
[root@192 ~]# x=6
[root@192 ~]# y=7
[root@192 ~]# expr $x \* $Y
[root@192 ~]# 42
Directory oriented commands:-
A) mkdir:- This command ids used to create a new directory.
syntax :-
mkdir <directory-name>
Creating a new directory
[root@localhost ~]# mkdir linux
This command will create a new subdirectory with name linux of current directory .
Creating more than one directories in single move.
[root@localhost ~]# mkdir x y z
This will create three directories having names x,y,z respectively.
B) rmdir :- This command is used to remove a directory. Directory should be empty
before deletion.
syntax:-
rmdir <directory-name>
Example :- Removing a directory
[root@localhost ~]# rmdir pan
This will remove directory having name pan.
Example :- Removing subdirectories in a directory with single rmdir
-p option is used for this.
[root@localhost ~]# rmdir -p linux/teji/teji1/
C)Pwd:- This command will displays full path name for present working directory.
syntax:-pwd
Example:-To see current working directory
[root@localhost ~]# pwd
/root
Present working directory is /root
D) cd:- This command is used for changing current directory to specified directory.
syntax:- cd <directory-name>
Example:-To move to a specified directory
[root@localhost ~]# cd dir/dir2
[root@localhost dir2]#
If we use pwd command it will display present working directory as
[root@localhost dir2]# pwd
/root/dir/dir2
Example:-To move to a parent directory
[root@localhost dir2]# cd ..
[root@localhost dir]# pwd
/root/dir
Now we are on parent directory of dir2.
Example:-To move to a root directory
[root@localhost dir]# cd ~
[root@localhost ~]#pwd
/root
E) ls:- This command is used to list the contents of specified directory
syntax:- ls [options] <directory-name>
options :-
Example:-Lists all files and directories including hidden files.
-a(All) option is used for this purpose.
[root@localhost ~]# ls -a
. .gnome2 .ssh
.. .gnome2_private .sversionrc
.[Link] .gstreamer-0.8 .swp
[Link]~ .gtkrc [Link]
.[Link] .gtkrc-1.2-gnome2 [Link]
.bash_history .ICEauthority [Link]
.bash_logout ishan [Link]
.bash_profile linux book .tcshrc
.bashrc linux slides [Link]
[Link] .mailcap [Link]
[Link] .metacity teji
C___C___PROJECTS .[Link] [Link]
cd .mozilla [Link]
.config .nautilus tejinder
.cshrc naveen .[Link]
Desktop .openoffice-install-log .thumbnails
dir .openoffice-lock .Trash
Directory oriented [Link] pan .viminfo
.dmrc ram .[Link]
Example:-Lists all files and directories in long format.
-l (long) option is used for this purpose.
List files in long format (- represents file ,d represents directory, file permissions ,number
of links ,owner of file ,file size ,file creation /modification time, name of file )
[root@localhost ~]# ls -l [Link]
-rw-r--r-- 1 root root 107 Dec 14 10:51 [Link]
[root@localhost ~]# ls -l dir
total 24
drwxr-xr-x 2 root root 4096 Dec 14 11:37 dir1
-rw-r--r-- 1 root root 77 Dec 14 11:05 [Link]
-rw-r--r-- 1 root root 43 Dec 14 11:31 [Link]
This command will displays directory dir1 as well as all contained files in long format .
Example:-Lists all files and directories in reverse order
-r(reverse) option is used for this purpose.
[root@localhost ~]# ls -r
win [Link] pan nitin cd
web slides [Link] naveen C___C___PROJECTS
tejinder [Link] linux slides [Link]
[Link] [Link] linux book [Link]
[Link] solar system ishan [Link]~
teji rpms Directory oriented [Link]
[Link] [Link] dir
[Link] ram Desktop
Example:-Recursively lists all files and directories as well as files in subdirectories
[root@localhost ~]# ls -R dir
dir:
dir1 [Link] [Link]
dir/dir1:
[Link]
Example:-Puts a slash after each directory
[root@localhost ~]# ls -p
[Link]~ ishan/ solar system/ [Link]
[Link] linux book/ [Link] [Link]
[Link] linux slides/ [Link] tejinder
naveen/ [Link] web slides/
cd/ pan/ [Link] win/
Desktop/ ram/ [Link]
dir/ [Link] [Link]
rpms/ teji/
Example:-Displays the number of storage blocks used by a file
-s(storage)option is used for this purpose.
[root@localhost ~]# ls -s [Link]
8 [Link]
This shows file size 8 byte used by file [Link].
Example:-Displays * after files for those user has executable permission
-F option is used for this purpose
[root@localhost ~]# ls -F [Link]
[Link]