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

Experiment No. 4 Aim: To Study Various UNIX Command: Commands

This document summarizes various UNIX commands including: 1. The date command displays the current date and time and allows changing the date. 2. The cal command displays a calendar of a given month or year. 3. The tty command displays the terminal name. 4. The who command lists users currently logged in.

Uploaded by

Dia Kapoor
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Experiment No. 4 Aim: To Study Various UNIX Command: Commands

This document summarizes various UNIX commands including: 1. The date command displays the current date and time and allows changing the date. 2. The cal command displays a calendar of a given month or year. 3. The tty command displays the terminal name. 4. The who command lists users currently logged in.

Uploaded by

Dia Kapoor
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 34

Experiment No.

4 Aim: To study various UNIX command


Commands:
1. DATE: SYNOPSIS: $date DESCRIPTION: The date command displays current date and time in various formats. It also allows the system administrator to change the date and time as and when required. OPTIONS: date: It will display the current date and time. date d particular date: It will display the day and time of that particular date. date r filename: It will display the last date and time when the file was modified. date s particular date: It is used for replacing the current date with given date. Its permission is only on the administrator hand. date u : It will display the universal date and time of the system. date +today is %d %b %y: It will display the current day, month and year of system. For more we use help command. Date help: It is used for help purpose to know various options of date command. OUTPUT:

2. CAL: SYNOPSIS: $ cal DESCRIPTION: The cal command helps you to see the calendar of any month or a complete year. If you do not give any argument, it prints the current month. OPTIONS: cal: It will display the current month of the system. cal s: It will display the Sunday as staring day of week. cal m: It will display the Monday as staring day of week. cal y: It will the current year of the system. cal j: It will display the particular day according to year.

OUTPUT:

3. TTY: SYNOPSIS: $ tty DESCRIPTION: Linux treats everything as files. Even the terminals connected are represented as files. If you want to know the filename of your terminal, you can do so by using tty command. OPTIONS: tty: It will tell on which terminal are you. OUTPUT:

4. WHO: SYNOPSIS: $ who

DESCRIPTION: In a multiuser environment a number of users might be working at the same time. If you want to see the list of the other users who are currently logged in then Linux provides you who command for this purpose. OPTIONS: who: It will tell who are currently logged in. who a :It will tell all who are logged in. who b :Report information about last reboot. who h: same as simple who except it shows the heading of all descriptions. OUTPUT:

5. Echo: Synopsis: $ echo [ String ... ]

Description: The echo command writes character strings to standard output. Strings are separated by spaces, and a new-line character follows the last String parameter specified. If no String parameter is specified, a blank line (new-line character) is displayed. OUTPUT:

6. LS: SYNOPSIS: $ ls DESCRIPTION: It is used to display a list of files and directories in the current directory. Ls display the name of files. OPTIONS: ls :ls command is used in Linux to display a list of files and directories in the current directory. Ls display the names of files. ls a : It is used to display hidden files. ls l : It is used to display the permissions on files and directories. ls r : It is used view the list of files in reverse alphabetical order.

OUTPUT:

7. Write: SYNOPSIS: $ write user [ttyname] DESCRIPTION: If you want to communicate with any of the other user who are currently logged in. Linux provides you WRITE command to send a message to the other users. OPTIONS: write username: This command will write a concerned message to concerned user screen.

OUTPUT:

8. Mesg: Synopsis:$ mesg [y|n] Description: Mesg controls the access to your terminal by others. It's typically used to allow or disallow other users to write to your terminal. Options: Y :Allow write access to your terminal. N : Disallow write access to your terminal. If no option is given, mesg prints out the current access state of your terminal. OUTPUT:

9. Finger: Synopsis:$ finger Description: The finger displays information about the system users. OUTPUT:

10. Pwd: Synopsis: $ pwd [OPTION] DESCRIPTION: Uniux provides a great facility to the user by placing him in a directory when he makes a login. You can move from one directory to another directory very easily. But at a time you are located in one directory. This directory is your current working directory. OPTIONS: pwd :It will show present working directory. OUTPUT:

11. Cd: Synopsis: $ cd (relative address) , cd/home/ (absolute address) , Description: This command changes your current directory location. By default, your Unix login session begins in your home directory. Options: cd myfiles :t o switch to a subdirectory (of the current directory) named myfiles, cd .. : To move to the parent directory of the current directory, enter:

cd / : To move to the root directory, OUTPUT:

12. Mkdir: Synopsis: $ mkdir [OPTION] DIRECTORY... Description: Directories are created with mkdir(make directory) command. The command is followed by names of the directories to be created. Options: To create a subdirectory named mystuff in the current directory, enter: mkdir mystuff To create a subdirectory named morestuff in the existing directory named /tmp, enter: mkdir /tmp/morestuff OUTPUT:

13. Rmdir: SYNOPSIS: rmdir [OPTION]... DIRECTORY... DESCRIPTION: The rmdir command removes directories. You can remove a directory by using rmdir command only if it is empty. If you try to remove a directory that is not empty, you will get an error message. OPTIONS: rmdir dir name: It will remove the directory as the given name. OUTPUT

14. Cat: Synopsis: $ cat [OPTION] [FILE]...

Description: This command outputs the contents of a text file. It has three related functions with regard to text files: displaying them, combining copies of them and creating new ones. Options: cat filename : The most common use of cat is to read the contents of files, and cat is often the most convenient program for this purpose. All that is necessary to open a text file for viewing on the display monitor is to type the word cat followed by a space and the name of the file and then press the ENTER key. cat > filename: To create a file we need to write this angular bracket between the cat command and filename than enter to add contents. The program is terminated and the normal command prompt is restored by pressing the CONTROL and d keys simultaneously. cat >> filename1 filename2 : To concate the contents of filename1 with filename2. OUTPUT:

15. Touch : Synopsis: $ touch Description: It is used for creating empty files (if empty file doesnt exist). OUTPUT:

16. MV: SYNOPSIS: $ mv [OPTION]... SOURCE DEST $ mv [OPTION]... SOURCE... DIRECTORY $ mv [OPTION]... --target-directory=DIRECTORY SOURCE... DESCRIPTION: This command is used to rename or move a file. This command can also be a user to move a file from one directory to another. OPTIONS:

mv oldfilename newfilename: It is used for moving the contents of oldfilename to newfilename.

OUTPUT:

17. CP: SYNOPSIS: $ cp filename1 ..filename n DESCRIPTION: This command is used to copies a file or group of files to another file. It simply creates an image of the file with different name. OPTIONS: cp file1 file2: It copies file1 into file2.

OUTPUT:

18. MAIL: SYNOPSIS: $ mail username DESCRIPTION: Linux allows you to send, receive and read mails by using mail command. OPTIONS: mail username: It will send mail to username. OUTPUT:

19. WALL: SYNOPSIS: $ wall DESCRIPTION: If you want to send a particular message to every currently logged in, you can use wall command. This command is used in emergency by the system administrator when the server has to be shut down immediately when other users are logged in. OPTIONS: wall message: This command will broadcast the message written. OUTPUT:

20. HEAD: SYNOPSIS: $ head filename DESCRIPTION: This command will display first few lines of one or more files. OPTIONS: head filename: This command will display the first part of file. OUTPUT:

21. TAIL: SYNOPSIS: $ tail filename DESCRIPTION: This command will display last few lines of one or more files. OPTIONS: tail filename: This command will display the last part of file. OUTPUT:

22. MORE: SYNOPSIS: $ more filename DESCRIPTION: The more command allows you to through a file by lines, or full screens and also provides you the facility to move either in backward direction or in forward direction and also search for patterns. OPTIONS: spacebar: To move forward by a screen. enter: The first screen full of contents of file will be displayed on screen. ctrl-d: To move forward by half screen. ctrl-b: To move backward by half screen. OUTPUT:

23. LESS:
SYNOPSIS: $ less filename DESCRIPTION: The less command is an advanced version of more command. However the main objective is same. The less command can be used to display different portions of the file interactively.

OPTIONS: f or spacebar: To move forward one window. b: To move backward one window.

y: To move backward one line. e or enter: To move forward one line. OUTPUT:

24. CMP: SYNOPSIS: $ cmp filename1 filename2 DESCRIPTION: cmp command is used to compare two files. If two files have the same contents, you may want to delete one of them. To know whether two files are identicalor not you can use this command. OPTIONS: cmp file1 file2: This command will compare file1 with file2 and in output it tells you the line number and the position where the two files differ. OUTPUT:

25. COMM: SYNOPSIS: $ comm filename1 filename2 DESCRIPTION: comm command is used to find out the data that is available in one file and not in other and what is common in two files. OUTPUT:

26. Chmod: Permission about particular file

Synopsis: $chmod[OPTION]...MODE[,MODE]...FILE... $chmod[OPTION]...OCTAL-MODEFILE... $chmod [OPTION]... --reference=RFILE FILE... Description: chmod changes the permissions of each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new permissions. Options: G-: To apply the changes for a group. U-: To apply the changes for a user. O- : To apply the changes for a others. A- : To apply the changes for all. Adding: no permission

+ permission OUTPUT:

Experiment No. 5
AIM : To study the VI (Visual) Editor. THEORY:
The default editor that comes with the UNIX operating system is called vi (visual editor). The UNIX vi editor is a full screen editor and has two modes of operation: 1.) Insert mode in which entered text is inserted into the file. 2.) Command mode commands which cause action to be taken on the file, and

COMMANDS: vi
SYNOPSIS: vi file_name DESCRIPTION: The vi editor (short for visual editor) is a screen editor which is available on almost all Unix systems. vi has no menus but instead uses combinations of keystrokes in order to accomplish commands. For Example: vi RAJAT opens the file called RAJAT .

Cursor Movement
ASEEM

h j k l

move left (backspace) move down move up move right (spacebar)

[return] move to the beginning of the next line $ 0 ^ w last column on the current line move cursor to the first column on the current line move cursor to first nonblank column on the current line move to the beginning of the next word or punctuation mark

W move past the next space b B e move to the beginning of the previous word or punctuation mark move to the beginning of the previous word, ignores punctuation end of next word or punctuation mark

E end of next word, ignoring punctuation H M L move cursor to the top of the screen move cursor to the middle of the screen move cursor to the bottom of the screen

Screen Movement
G xG z+ z z^F ^B ^D ^U ^R ^L move to the last line in the file move to line x move current line to top of screen move current line to the middle of screen move current line to the bottom of screen move forward one screen move backward one line move forward one half screen move backward one half screen redraw screen ( does not work with VT100 type terminals ) redraw screen ( does not work with Televideo terminals )

Inserting
r R i a A O replace character under cursor with next character typed keep replacing character until [esc] is hit insert before cursor append after cursor append at end of line open line above cursor and enter append mode

Deleting
x dd dw db delete character under cursor delete line under cursor delete word under cursor delete word before cursor

Copying Code
yy (yank)'copies' line which may then be put bythe p(put) command. Precede with a count for multiple lines.

Put Command
brings back previous deletion or yank of lines, words, or characters P p bring back before cursor bring back after cursor

Find Commands
? / f F t it T before it ; repeat last f, F, t, T find a character on the current line going backward and stop one character finds a word going backwards finds a word going forwards finds a character on the line under the cursor going forward finds a character on the line under the cursor going backwards find a character on the current line going forward and stop one character before

Miscellaneous Commands
. u U xp J ^G % mx 'x repeat last command undoes last command issued undoes all commands on one line deletes first character and inserts after second (swap) join current line with the next line display current line number if at one parenthesis, will jump to its mate mark current line with character x find line marked with character x

Line Editor Mode


Any commands form the line editor ex can be issued upon entering line mode. To enter: type ':' To exit: press[return] or [esc]

READING FILES
copies (reads) filename after cursor in file currently editing :r filename

WRITE FILE
:w saves the current file without quitting

MOVING
:# :$ move to line # move to last line of file

SHELL ESCAPE
executes 'cmd' as a shell command. :!'cmd'

Block Commands
Block commands work on a group of lines(a block of text) rather than an isolated line. For example, we may want to delete a group of lines from the file by using a single command or we may want to copy a group of lines from a file by using a single command. we can make block commands to work on single lines. The various block commands that you can perform on vi are : :nd :m,n d :n mo p :m,n mo p :m co p :m,n co p :m,n w filename :m,n w>> filename :r filename :r !command Deletes nth line. Deletes lines from m to n Moves line n after line p Moves line m to n after line p Copies line m after line p Copies lines m to n after line p Writes lines m to n to a file Appends lines m to n to a file Reads the contents of the file filename at current curser position. Executes shell command and output of the command is read at the At current curser position.

OUTPUT
INSERT MODE

COMMAND MODE

Ex-COMMAND MODE

Experiment No. 6

AIM : Write a program to print Hello!! This is YOUR_NAME and this is my first program in SHELL Programming. COMMANDS: I.)vi
SYNOPSIS: vi file_name DESCRIPTION: The vi editor (short for visual editor) is a screen editor which is available on almost all Unix systems. vi has no menus but instead uses combinations of keystrokes in order to accomplish commands. For Example: vi rajathello opens the file called rajathello OUTPUT:

II.)echo
SYNOPSIS: Echo TEXT

DESCRIPTION: Prints the text written after it. OUTPUT:

III.)sh
SYNOPSIS: sh file_name DESCRIPTION: Shows the Output. OUTPUT:

You might also like