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. It’s 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. If you want to know the filename of your terminal. Even the terminals connected are represented as files. OPTIONS: tty: It will tell on which terminal are you. OUTPUT: 4. you can do so by using tty command. WHO: SYNOPSIS: $ who . TTY: SYNOPSIS: $ tty DESCRIPTION: Linux treats everything as files.

] . OUTPUT: 5.. 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.DESCRIPTION: In a multiuser environment a number of users might be working at the same time. OPTIONS: who: It will tell who are currently logged in. who –b :Report information about last reboot.. who –a :It will tell all who are logged in. Echo: Synopsis: $ echo [ String . who –h: same as simple who except it shows the heading of all descriptions.

Strings are separated by spaces. Ls display the name of files. a blank line (new-line character) is displayed.Description: The echo command writes character strings to standard output. Ls display the names of files. OPTIONS: ls :ls command is used in Linux to display a list of files and directories in the current directory. ls –a : It is used to display hidden files. OUTPUT: . and a new-line character follows the last String parameter specified. OUTPUT: 6. LS: SYNOPSIS: $ ls DESCRIPTION: It is used to display a list of files and directories in the current directory. ls –r : It is used view the list of files in reverse alphabetical order. ls –l : It is used to display the permissions on files and directories. If no String parameter is specified.

.

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

Options: Y :Allow write access to your terminal. 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. OUTPUT: 9. N : Disallow write access to your terminal.OUTPUT: 8. mesg prints out the current access state of your terminal. Finger: Synopsis:$ finger Description: The finger displays information about the system users. OUTPUT: . If no option is given.

Options: cd myfiles :t o switch to a subdirectory (of the current directory) named myfiles. By default. : To move to the parent directory of the current directory. OPTIONS: pwd :It will show present working directory. But at a time you are located in one directory. This directory is your current working directory.10. OUTPUT: 11. Cd: Synopsis: $ cd (relative address) . Description: This command changes your current directory location. cd/home/ (absolute address) .. your Unix login session begins in your home directory. cd . enter: . You can move from one directory to another directory very easily. 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 remove a directory by using rmdir command only if it is empty....cd / : To move to the root directory. Cat: Synopsis: $ cat [OPTION] [FILE]. OUTPUT 14. If you try to remove a directory that is not empty.. enter: mkdir /tmp/morestuff OUTPUT: 13. DESCRIPTION: The rmdir command removes directories. OUTPUT: 12.. DIRECTORY.. Mkdir: Synopsis: $ mkdir [OPTION] DIRECTORY. 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. OPTIONS: rmdir dir name: It will remove the directory as the given name. you will get an error message.. Rmdir: SYNOPSIS: rmdir [OPTION]. Description: Directories are created with mkdir(make directory) command. .

and cat is often the most convenient program for this purpose. Touch : Synopsis: $ touch Description: It is used for creating empty files (if empty file doesn’t exist). It has three related functions with regard to text files: displaying them.. OUTPUT: 16.. cat >> filename1 filename2 : To concate the contents of filename1 with filename2.. The program is terminated and the normal command prompt is restored by pressing the CONTROL and d keys simultaneously. SOURCE DEST $ mv [OPTION]. 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. MV: SYNOPSIS: $ mv [OPTION]...Description: This command outputs the contents of a text file. combining copies of them and creating new ones.. DESCRIPTION: This command is used to rename or move a file. DIRECTORY $ mv [OPTION]. OPTIONS: .. cat > filename: To create a file we need to write this angular bracket between the cat command and filename than enter to add contents... SOURCE. OUTPUT: 15.. --target-directory=DIRECTORY SOURCE. Options: cat filename : The most common use of cat is to read the contents of files. This command can also be a user to move a file from one directory to another.

OPTIONS: cp file1 file2: It copies file1 into file2.mv oldfilename newfilename: It is used for moving the contents of oldfilename to newfilename. CP: SYNOPSIS: $ cp filename1 …. OUTPUT: 17.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: mail username: It will send mail to username. receive and read mails by using mail command.OUTPUT: 18. MAIL: SYNOPSIS: $ mail username DESCRIPTION: Linux allows you to send. OUTPUT: .

OPTIONS: head filename: This command will display the first part of file. HEAD: SYNOPSIS: $ head filename DESCRIPTION: This command will display first few lines of one or more files. WALL: SYNOPSIS: $ wall DESCRIPTION: If you want to send a particular message to every currently logged in.19. OUTPUT: 20. OUTPUT: . 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. you can use wall command.

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

.

.

b: To move backward one window. OPTIONS: f or spacebar: To move forward one window. However the main objective is same. The less command can be used to display different portions of the file interactively. LESS: SYNOPSIS: $ less filename DESCRIPTION: The less command is an advanced version of more command.23. .

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

.

If two files have the same contents.24. 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: . you may want to delete one of them. To know whether two files are identicalor not you can use this command. CMP: SYNOPSIS: $ cmp filename1 filename2 DESCRIPTION: cmp command is used to compare two files.

Chmod: Permission about particular file . 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.25. OUTPUT: 26.

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

2.) Insert mode in which entered text is inserted into the file. 5 AIM : To study the VI (Visual) Editor. THEORY: The default editor that comes with the UNIX operating system is called vi (visual editor). For Example: vi RAJAT opens the file called RAJAT . .Experiment No. 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. The UNIX vi editor is a full screen editor and has two modes of operation: 1.) Command mode commands which cause action to be taken on the file. vi has no menus but instead uses combinations of keystrokes in order to accomplish commands.

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 .

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 .E end of next word.

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 . repeat last f.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. or characters P p bring back before cursor bring back after cursor Find Commands ? / f F t it T before it . words. t. F. Put Command brings back previous deletion or yank of lines.

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 .Miscellaneous Commands .

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.n w filename :m.n w>> filename :r filename :r !command Deletes nth line.n co p :m. Executes shell command and output of the command is read at the At current curser position.n d :n mo p :m. :!'cmd' Block Commands Block commands work on a group of lines(a block of text) rather than an isolated line. The various block commands that you can perform on vi are : :nd :m.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. 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.n mo p :m co p :m. we can make block commands to work on single lines. For example. .

OUTPUT INSERT MODE COMMAND MODE Ex-COMMAND MODE .

6 .Experiment No.

OUTPUT: . For Example: vi rajathello opens the file called rajathello OUTPUT: II.)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.)echo SYNOPSIS: Echo “TEXT” DESCRIPTION: Prints the text written after it. COMMANDS: I.AIM : Write a program to print “Hello!! This is YOUR_NAME and this is my first program in SHELL Programming”.

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