0% found this document useful (0 votes)
8 views11 pages

Assignment 1

The document is an assignment from Asansol Engineering College's Computer Science and Engineering department, detailing various UNIX commands and their usage. It covers commands for displaying date and time, managing files and directories, and using the vi editor, among others. Each command is accompanied by its syntax and options, providing a comprehensive guide for executing tasks in a UNIX environment.

Uploaded by

Amitayu das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Assignment 1

The document is an assignment from Asansol Engineering College's Computer Science and Engineering department, detailing various UNIX commands and their usage. It covers commands for displaying date and time, managing files and directories, and using the vi editor, among others. Each command is accompanied by its syntax and options, providing a comprehensive guide for executing tasks in a UNIX environment.

Uploaded by

Amitayu das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ASANSOL ENGINEERING COLLEGE

Department of Computer Science and Engineering

ASSIGNMENT 1

UNIX COMMANDS

AIM :
To study and execute the commands in UNIX.

COMMAND :
1. Date Command:
This command is used to display the current data and time.
Syntax :
$date
$date +%ch
Options : -
a = Abbrevated weekday.
A = Full weekday.
b = Abbrevated month.
B = Full month.
c = Current day and time.
C = Display the century as a decimal number.
d = Day of the month.
D = Day in „mm/dd/yy‟ format
h = Abbrevated month day.
H = Display the hour.
L = Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
T = HH:MM:SS format
u = Week of the year.
y = Display the year in 2 digit.
Y = Display the full year.
Z = Time zone.
To change the format:
Syntax :
$date „+%H-%M-%S‟

2. Calendar Command :
This command is used to display the calendar of the year or the particular month of
calendar year.
Syntax :
a. $cal <year>

Operating System Lab Manual PCC-CS 592 Page 3


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering
b. $cal <month> <year>

Here the first syntax gives the entire calendar for given year & the second Syntax gives
the calendar of reserved month of that year.

3. Echo Command:
This command is used to print the arguments on the screen.
Syntax : $echo <text>
Multi line echo command:
To have the output in the same line , the following commands can be used.
Syntax : $echo <text\>text
To have the output in different line, the following command can be used.
Syntax : $echo ―text
>line2
>line3‖
4. Banner Command :
It is used to display the arguments in „#‟ symbol .
Syntax : $banner <arguments>

5. ’who’ Command :
It is used to display who are the users connected to our computer currently.
Syntax : $who – option‟s
Options : -
H–Display the output with headers.
b–Display the last booting date or time or when the system was lastely rebooted.

6. ’who am i’ Command :
Display the details of the current working directory.
Syntax : $who am i

7. ’tty’ Command :
It will display the terminal name.
Syntax : $tty

8. ’Binary’ Calculator Command :


It will change the „$‟ mode and in the new mode, arithematic operations such as +,-
,*,/,%,n,sqrt(),length(),=, etc can be performed . This command is used to go to the binary
calculus mode.
Syntax :
$bc

Base :

1 base –inputbase
0 base – outputbase
are used for base
conversions.
Operating System Lab Manual PCC-CS592 Page 4
ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering
Decimal = 1 Binary = 2 Octal =8 Hexa = 16

9. ’CLEAR’ Command :
It is used to clear the screen.
Syntax : $clear
10. ’MAN’ Command :

It help us to know about the particular command and its options & working. It is like
„help‟ command in windows .
Syntax : $man <command name>

11. MANIPULATION Command :


It is used to manipulate the screen.
Syntax : $tput <argument>
Arguments :
1. Clear – to clear the screen.
2. Longname – Display the complete name of the terminal.
3. SMSO – background become white and foreground become black color.
4.rmso – background become black and foreground becomes white color.
5.Cop R C – Move to the cursor position to the specified location.
6.Cols – Display the number of columns in our terminals.

12. LIST Command :


It is used to list all the contents in the current working directory.
Syntax : $ ls – options <arguments>
If the command does not contain any argument means it is working in the
Current directory.
Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.

DIRECTORY RELATED COMMANDS :


1. Present Working Directory Command :
To print the complete path of the current working directory.
Syntax : $pwd

2. MKDIR Command :
To create or make a new directory in a current directory .
Syntax : $mkdir <directory name>

Operating System Lab Manual PCC-CS592 Page 5


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering
3. CD Command :
To change or move the directory to the mentioned directory .
Syntax : $cd <directory name.
4. RMDIR Command :
To remove a directory in the current directory & not the current directory itself.
Syntax : $rmdir <directory name>

FILE RELATED COMMANDS :


1. CREATE A FILE :
To create a new file in the current directory we use CAT command.
Syntax :
$cat > <filename.
The > symbol is redirectory we use cat command.

2. DISPLAY A FILE :
To display the content of file mentioned we use CAT command without „>‟ operator.
Syntax :
$cat <filename.
Options –s = to neglect the warning /error message.

3. COPYING CONTENTS :
To copy the content of one file with another. If file doesnot exist, a new file is created
and if the file exists with some data then it is overwritten.
Syntax :
$ cat <filename source> >> <destination filename>
$ cat <source filename> >> <destination filename> it is avoid
overwriting.
Options : -
-n content of file with numbers included with blank lines.
Syntax :
$cat –n <filename>

4. SORTING A FILE :
To sort the contents in alphabetical order in reverse order.
Syntax :
$sort <filename >
Option : $ sort –r <filename>

5. COPYING CONTENTS FROM ONE FILE TO ANOTHER :


To copy the contents from source to destination file . so that both contents are same.
Syntax :
$cp <source filename> <destination filename>
$cp <source filename path > <destination filename path>
6. MOVE Command :
To completely move the contents from source file to destination file and to remove the
source file.

Operating System Lab Manual PCC-CS592 Page 6


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering
Syntax :
$ mv <source filename> <destination filename>

7. REMOVE Command :
To permanently remove the file we use this command .
Syntax :
$rm <filename>

8. WORD Command :
To list the content count of no of lines , words, characters .
Syntax :

Options :
$wc<filename>

-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.

9. LINE PRINTER :
To print the line through the printer, we use lp command.
Syntax :
$lp <filename>

10. PAGE Command :


This command is used to display the contents of the file page wise & next page can be
viewed by pressing the enter key.
Syntax :
$pg <filename>

FILTERS AND PIPES


11.
HEAD : It is used to display the top ten lines of file.
Syntax: $head<filename>

TAIL : This command is used to display the last ten lines of file.
Syntax: $tail<filename>

PAGE : This command shows the page by page a screen full of information is displayed after
which the page command displays a prompt and passes for the user to strike the enter key to
continue scrolling.

Syntax: $ls –a\p

MORE : It also displays the file page by page .To continue scrolling with more command ,

Operating System Lab Manual PCC-CS592 Page 7


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering
press the space bar key.
Syntax: $more<filename>

GREP :This command is used to search and print the specified patterns from the file.
Syntax: $grep [option] pattern <filename>

SORT : This command is used to sort the datas in some order.


Syntax: $sort<filename>

PIPE : It is a mechanism by which the output of one command can be channeled into the input
of another command.
Syntax: $who | wc-l

TR :The tr filter is used to translate one set of characters from the standard inputs to another.
Syntax: $tr ―[a-z]‖ ―[A-Z]‖

COMMUNICATION THROUGH UNIX COMMANDS


MESG
Description: The message command is used to give permission to other users to send
message to your terminal.
Syntax: $mesg y

2. Command: WRITE
Description: This command is used to communicate with other users, who are logged in at
the same time.
Syntax: $write <user name>

3. Command: WALL
Description: This command sends message to all users those who are logged in using the
unix server.
Syntax: $wall <message>

4. Command: MAIL
Description: It refers to textual information, that can be transferred from one user to
another
Syntax: $mail <user name>

5. Command: REPLY
Description: It is used to send reply to specified user.
Syntax: $reply<user name>

Operating System Lab Manual PCC-CS592 Page 8


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering

VI EDITOR COMMANDS
AIM : To study the various commands operated in vi editor in UNIX.

DESCRIPTION :
The Vi editor is a visual editor used to create and edit text, files, documents and
programs. It displays the content of files on the screen and allows a user to add, delete or
change part of text . There are three modes available in the Vi editor , they are

1. Command mode
2.Input (or) insert mode.

Starting Vi :
The Vi editor is invoked by giving the following commands in UNIX prompt.
Syntax : $vi <filename> (or)
$vi
This command would open a display screen with 25 lines and with tilt (~) symbol at the
start of each line. The first syntax would save the file in the filename mentioned and for the
next the filename must be mentioned at the end.
Options :
1.vi +n <filename> - this would point at the nth line (cursor pos).
2.vi –n <filename> - This command is to make the file to read only to change
from one mode to another press escape key.

INSERTING AND REPLACING COMMANDS :


To move editor from command node to edit mode, you have to press the <ESC> key.
For inserting and replacing the following commands are used.

1. ESC a Command:
This command is used to move the edit mode and start to append after the current
character.

Syntax : <ESC> a

2. ESC A COMMAND :
This command is also used to append the file , but this command append at the end of
current line.
Syntax : <ESC> A

Operating System Lab Manual PCC-CS 592 Page 9


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering

3. ESC i Command :
This command is used to insert the text before the current cursor position.
Syntax : <ESC> i

4. ESC I Command :
This command is used to insert at the beginning of the current line.
Syntax : <ESC> I

5. ESC o Command :
This command is insert a blank line below the current line & allow insertion of
contents.
Syntax : <ESC> o

6. ESC O Command :
This command is used to insert a blank line above & allow insertion of contents.
Syntax : <ESC> O

7. ESC r Command :
This command is to replace the particular character with the given characters.
Syntax : <ESC> rx Where x is the new character.

8. ESC R Command :
This command is used to replace the particular text with a given text.
Syntax : <ESC> R text

9. <ESC> s Command :
This command replaces a single character with a group of character .
Syntax : <ESC> s
10. <ESC> S Command :
This command is used to replace a current line with group of characters.
Syntax : <ESC> S

CURSOR MOVEMENT IN vi :
1. <ESC> h:
This command is used to move to the previous character typed. It is used to move to
left of the text . It can also used to move character by character (or) a number of characters.
Syntax : <ESC> h – to move one character to left.
<ESC> nh – tomove „n‟ character to left.

2. <ESC> l:
This command is used to move to the right of the cursor (ie) to the next character. It can
also be used to move the cursor for a number of character.
Syntax : <ESC> l – single character to right.
<ESC> nl - „n‟ characters to right.

Operating System Lab Manual PCC-CS 592 Page 10


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering

3. <ESC> j:
This command is used to move down a single line or a number of lines.
Syntax :
<ESC> j – single down movement.
<ESC> nj – „n‟ times down movement.

4. <ESC> k:
This command is used to move up a single line or a number of lines.
Syntax :
<ESC> k – single line above.
<ESC> nk – „n‟ lines above.

5. ENTER (OR) N ENTER :


This command will move the cursor to the starting of next lines or a group of lines
mentioned.
Syntax :
<ESC> enter <ESC> n enter.

6.<ESC> + Command :
This command is used to move to the beginning of the next line.
Syntax :
<ESC> + <ESC> n+

7.<ESC> - Command :
This command is used to move to the beginning of the previous line.
Syntax :
<ESC> - <ESC> n-
8.<ESC> 0 :
This command will bring the cursor to the beginning of the same current line.
Syntax :
<ESC> 0

9.<ESC> $ :
This command will bring the cursor to the end of the current line.
Syntax :
<ESC> $

10.<ESC> ^ :
This command is used to move to first character of first lines.
Syntax :
<ESC> ^

11. <ESC> b Command :


This command is used to move back to the previous word (or) a number of words.
Operating System Lab Manual PCC-CS 592 Page 11
ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering

Syntax :
<ESC> b <ESC>nb

12. <ESC> e Command :


This command is used to move towards and replace the cursor at last character of the
word (or) no of words.
Syntax :
<ESC> e <ESC>ne

13. <ESC> w Command :


This command is used to move forward by a single word or a group of words.
Syntax :
<ESC> w <ESC> nw
DELETING THE TEXT FROM Vi :
1. <ESC> x Command :
To delete a character to right of current cursor positions , this command is used.
Syntax :
<ESC> x <ESC> nx

2. <ESC> X Command :
To delete a character to left of current cursor positions , this command is used.
Syntax :
<ESC> X <ESC> nX
3. <ESC> dw Command :
This command is to delete a single word or number of words to right of current cursor
position.
Syntax :
<ESC> dw <ESC> ndw
4. db Command :
This command is to delete a single word to the left of the current cursor position.
Syntax :
<ESC> db <ESC> ndb

5. <ESC> dd Command :
This command is used to delete the current line (or) a number of line below the current
line.
Syntax :
<ESC> dd <ESC> ndd

6. <ESC> d$ Command :
This command is used to delete the text from current cursor position to last character of
current line.
Syntax : <ESC> d$

Operating System Lab Manual PCC-CS 592 Page 12


ASANSOL ENGINEERING COLLEGE
Department of Computer Science and Engineering

SAVING AND QUITING FROM vi :-


1. <ESC> wCommand :
To save the given text present in the file.
Syntax : <ESC> : w

2. <ESC> q! Command :
To quit the given text without saving.
Syntax : <ESC> :q!
3. <ESC> wq Command :
This command quits the vi editor after saving the text in the mentioned file.
Syntax : <ESC> :wq
4. <ESC> x Command :
This command is same as „wq‟ command it saves and quit.
Syntax : <ESC> :x
5. <ESC> q Command :
This command would quit the window but it would ask for again to save the file.
Syntax : <ESC> : q

Operating System Lab Manual PCC-CS 592 Page 13

You might also like