0% found this document useful (0 votes)
9 views

L6 Simple Commands

This document provides a comprehensive work instruction sheet for Unix/Linux programming, focusing on logging in and out, as well as basic commands. It includes detailed explanations of commands such as 'date', 'who', 'cal', 'lpr', 'tee', 'history', and various directory-oriented commands like 'mkdir', 'rmdir', 'pwd', 'cd', and 'ls'. The document serves as a practical guide for users to familiarize themselves with Unix/Linux command-line operations.

Uploaded by

realkaran07
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

L6 Simple Commands

This document provides a comprehensive work instruction sheet for Unix/Linux programming, focusing on logging in and out, as well as basic commands. It includes detailed explanations of commands such as 'date', 'who', 'cal', 'lpr', 'tee', 'history', and various directory-oriented commands like 'mkdir', 'rmdir', 'pwd', 'cd', and 'ls'. The document serves as a practical guide for users to familiarize themselves with Unix/Linux command-line operations.

Uploaded by

realkaran07
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

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 10:09:17 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 09:23:31 IST 2006

To display system time in AM/PM format.

[root@192 ~]# date +%r


09:25:10 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 text.txt
Contents of file text.txt 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 text.txt
hello
c
language is a middle level language
C++ is an object oriented language
java is purely object oriented language

[root@192 ~]# cat text.txt>text1.txt


we can combine these two commands into single command using tee command.

[root@192 ~]# cat text.txt | tee text1.txt


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 shi1.txt shi2.txt
4 ls -l shi1.txt
5 chmod 777 shi1.txt

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
.aaa.sh.swp .gstreamer-0.8 .swp
ani.sh~ .gtkrc t1.doc
.ani.sh.swp .gtkrc-1.2-gnome2 t1.txt
.bash_history .ICEauthority t3.doc
.bash_logout ishan t4.doc
.bash_profile linux book .tcshrc
.bashrc linux slides t.doc
c1.txt .mailcap te.doc
c2.txt .metacity teji
C___C___PROJECTS .mime.types teji1.doc
cd .mozilla teji.doc
.config .nautilus tejinder
.cshrc naveen .teji.txt.swp
Desktop .openoffice-install-log .thumbnails
dir .openoffice-lock .Trash
Directory oriented commands.doc pan .viminfo
.dmrc ram .viminfo.tmp

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 t1.doc


-rw-r--r-- 1 root root 107 Dec 14 10:51 t1.doc
[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 t4.txt
-rw-r--r-- 1 root root 43 Dec 14 11:31 teji.txt
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 t4.doc pan nitin cd
web slides t3.doc naveen C___C___PROJECTS
tejinder t1.txt linux slides c2.txt
teji.doc t1.doc linux book c1.txt
teji1.doc solar system ishan ani.sh~
teji rpms Directory oriented commands.doc
te.doc ram.txt dir
t.doc ram Desktop

Example:-Recursively lists all files and directories as well as files in subdirectories


[root@localhost ~]# ls -R dir
dir:
dir1 t4.txt teji.txt

dir/dir1:
t.txt

Example:-Puts a slash after each directory


[root@localhost ~]# ls -p
ani.sh~ ishan/ solar system/ teji1.doc
c1.txt linux book/ t1.doc teji.doc
c2.txt linux slides/ t1.txt tejinder
naveen/ t3.doc web slides/
cd/ pan/ t4.doc win/
Desktop/ ram/ t.doc
dir/ ram.txt te.doc
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 t1.doc
8 t1.doc
This shows file size 8 byte used by file t1.doc.
Example:-Displays * after files for those user has executable permission
-F option is used for this purpose
[root@localhost ~]# ls -F teji.doc
teji.doc

You might also like