Stud Towrite
-
Upload
vidhya-dhivakar -
Category
Documents
-
view
226 -
download
0
Transcript of Stud Towrite
-
7/31/2019 Stud Towrite
1/33
Ex no:2 BASIC UNIX COMMANDS
AIM:
To execute UNIX general purpose commands in UNIX Operating system
1. THE DATE COMMAND
The date command is used to display the current date with day of week, month, Day,time (24 Hours clock) and the year.
Syntax: $date
Example: $date
Output: Mon Sep 3 23:33:45: 1 st 2005
( It display the current day, month, date, year, hours, minutes, seconds)
OPTION : $ date +%m ( 02months digits)
$ date +%h ( Febmonths letters)
$ date +%d ( 08date digits)
$ date +%y ( 11year last two digits)
$ date +%H ( 22Hours)
$ date +%M ( 02minutes)
$ date +%S ( 02Seconds)
2. THE ECHO COMMAND
The echo command is used to print the message on the screen
Syntax: $echo text
Example: $echo learning UNIX
Output: learning UNIX
3.THE UNIX CALENDER: CAL
-
7/31/2019 Stud Towrite
2/33
The calendar (cal) command helps us to keep track of our days .It displays the specifiedmonth or year calendar.
Syntax: $cal month or year
Example 1: $cal 2011
Output: prints the calendar for the entire year
Example 2: $cal 9 2011
Output: prints the calendar for the month of September 2011
4. UNIX CALCULATOR:BC
UNIX offers an online calculator and can be invoked by the command bc. Thiscalculator is programmable and has complex functions.
Syntax: $bc
Example: $bc
Output: 5+5
10
( bc continuous this process until your given CTRL + D to terminate)
5. THE WHO COMMAND
The who command is more powerful and used to displays data about all the users, whoare currently logged into the system.
Syntax: $who
Example1: $who
Output: user1 tty1 Sep 03 09:30
(It display the output login name, terminal line, login date and time)
Example 2: $whoh
Output: NAME LINE TIME
user1 tty1 Sep 03 09:30
(display the column header)
-
7/31/2019 Stud Towrite
3/33
6. THE WHO AM I COMMAND
The whocommand with am and idisplay a single line of output pertaining to thelogin details of the user.
Example: $ who am i
Output: User1 tty1 Apr 4 09:30
(It identifiers the user and lists the user name, terminal line, the date and time of login)
7. THE FINGER COMMAND
The finger command gathers and displays the information about the users, whichincludes login name, real name, home directory etc.
Syntax: $finger username
Output: login name: root name: root
Directory: / root shell:/bin/bash
On since wed Jan 19 23:20 (IST) on pst/0 from 192.168.1.29
2 hours 2 minutes idle
On since Thu Jan 20 23:20 (IST) on pst/1 from 192.168.1.14
New mail received wed Jan 19 21:20 2011 (IST)
Unread since Thu Dec 20 23:20 2010 (IST)
No plan
(To display such information of a particular user)
Example 2: $finger
Login name Tty idle login time office office phone
root root pts/0 2:01 Jan 18 20:10 (192.168.1.29)
(Display the information about all users who are currently logged on)
-
7/31/2019 Stud Towrite
4/33
8 THE ID COMMAND
The id command is used to display the numerical value that corresponds to your loginname .UNIX user is assigned a login name, a user- id and a grouped- id
Syntax: $ id
Example: $ id
Output: uid= 347(user1) gid= 50(group)
9. THE TTY COMMAND
The tty (teletype) command is used to know the terminal name that we are using.
Syntax: $ tty
Eg : $ tty
Output: /dev/tty1
(Means, the terminal file tty1 resident in /dev directory.)
10 .CHANGE THE PASSWORD: PASSWD
If your account still does not have a password , or has one that is already known toothers, the password can be changed by using the passwd command.
Syntax: $ passwd
Output: UX: passwd: INFO: changing password for local
Old password : ***********
New password: ***********
Re-Enter New password: *****
Result:
Thus the above commands has been verified and executed.
-
7/31/2019 Stud Towrite
5/33
Ex no:3 WORKING WITH FILES
AIM:
To create a file and working with file using UNIX.
DEFINITION:
A file in a collection of related information such as letters, numbers, some specialcharacters and it may be a program.
FILE SYSTEM:
A file system is a group of files containing relevant information regarding it. Everythingin UNIX can be represented by a file such as directories, device drivers etc..
FILE IN UNIX:
File has divided into four categories
Ordinary files Directory files Special files Standard files
FILE COMMAND:
UNIX provides the file command to determine the types of file.
Syntax: $ file filename
Example: $ file shivani
Output: shivani ascii text
1. CREATE A FILEThe cat command is used to create a new file
Syntax: $ cat > filename
Example: $cat > test
My first file is UNIX
UNIX is a multi-user OS
(After finished typing, press CTRL+D)
-
7/31/2019 Stud Towrite
6/33
2. DISPLAY A FILE:
The cat command is also used to viewthe content of a file
Syntax: $ cat filename
Example: $ cat test
Output: My first file is UNIX,UNIX is a multi-user OS
3 MERGE THE FILE:
Cat commandservices to concatenated multiple files into asingle file
Syntax: $ cat file file1 >file2
Example: $ cat test test1>test2
Output: cat test
My first file is UNIX, UNIX is a multi-user OS
Cat test1
Os is software
Cat test test1 >test2
Cat test2
My first file is UNIX, UNIX is a multi-user OS
Os is software
4 COPING A FILE:
The cp command is used to copy the contents of one file to another.
Syntax:$ cp oldfile newfile
Example: $ cp test2 test3
Output: cat test2
My first file is UNIX, UNIX is a multi-user OS
Os is software.
Cp test2 test3
-
7/31/2019 Stud Towrite
7/33
Cat test3
My first file is UNIX, UNIX is a multi-user OS
Os is software
5 REMOVING A FILE:
The remove command is used to remove (or) erase an existing file.
Syntax: $ rm filename
Example: $ rm test3
Output: cat test3
No such a file
6 MOVING A FILE:
The mv command is used to move a file from one place to another
Syntax : $ mvoldfile newfile
Example: $ mv test2 test4
Output: cat test4
My first file is UNIX, UNIX is a multi-user OS
Os is software.
7 COUNTING NUMBER OF WORDS:
The wc command is used to count the number of words, lines, characters in a file
Syntax: $ wc filename
Example : $ wc filename
nl nw nc filename
where:
nlis the numbers of lines
nw - is the numbers of words
-
7/31/2019 Stud Towrite
8/33
nc - is the numbers of characters
output: $ wc test1
1 3 12 test1
Syntax: $ wc l file name (only line)
Syntax: $ wc w filename (only words)
Syntax: $ wc c filename (only characters)
8 SORTING THE CONTENT OF THE FILES:
The sort command is used for sort the contents of a file name.
Syntax : $ sort filename
Example: $ cat> mech
New
Morning
Apple
Output : $ sort mech
Apple
Morning
new
option: $ sort -r filename ( reverse order)
. $ sortc filename (disorder)
Result:
Thus the above command are verified and executed.
-
7/31/2019 Stud Towrite
9/33
Ex No:4 WORKING WITH DIRECTORIES
AIM
To learn about the working with directories using UNIX
1 CURRENT WORKING DIRECTORY
The pwd command is provided to know the current using directory.
Syntax : $ pwd
Example : $ pwd
Output : home 10me01
2 CREATE A DIRECTORY
A mk dir is used to create an empty directory in a desk.
Syntax : $ mk dir directory name
Example : $ mk dir MECH
3 REMOVING A DIRECTORY:
The rmdir is used to remove a directory from the disk before removing the directory mustbe empty.
Syntax : $ rmdir directory name
Option: rmdir -r file name ( search delete the file and subdirectories)
rmdir -I filename (warn message)
rmdie -f filename (write protected)
4 CHANGING THE WORKING DIRECTORY:
The cd command is used to changing the directory from one directory to another.
Syntax : $ cd directory name
-
7/31/2019 Stud Towrite
10/33
5 THE PATH :
The path command is used to specify the current path of the operating system
Syntax : $ echo $ PATH
(root of path will be display)
6 CLEARING THE SCREEN :
Clear command is used to clear the screen
Syntax : $ tput clear
RESULT :
Thus the above commands has been executed and verified successfully.
-
7/31/2019 Stud Towrite
11/33
ExNo:6 PIPES
AIM:
To learn about the pipes in UNIX a pipe is a mechanism by which output ofthe one command can be used into the input of another command is effected by thecharacter ( | ) And which is paced between the two characters.
Syntax: $ who | wc -l
Syntax: $ ls | sort | wc -l
THE TEE COMMAND
The tee command copies the incoming data on input to output,in the mean time it saves acopy in specified file.
Syntax: $ command | tee file
Example: $ who | tee sample | wc -l
RESULT:
The above commands has been executed and verified successfully.
-
7/31/2019 Stud Towrite
12/33
ExNo:7 WORKING WITH FILTERS
AIM:
To study a about simple filter using UNIX
1. THE HEAD FILTERAs the name simples the displays the first ten lines of a file.Syntax: $ head file name
example: $ head -13 myfile
2. THE TAIL FILTER:-The tail command is the opposite to the head command. It displays 10 lines of a file
from the end of the file.
Syntax: $ tail file name
Example: $ tail myfile
3. THE MORE COMMANDTo continue scrolling with the more command, you have
to press space barnot the Enter keyas in pg command.
Syntax: $ more myfile
Syntax: $ More file 2 file 3.
4. THE GREP Command:-It is used to search and print specified pattern form file.
Syntax: Grep [option] pattern file(s)
Example: $ grep Asia data
5. THE UNDO COMMAND
We just saw not soft remove then the n option.
-
7/31/2019 Stud Towrite
13/33
6 ADDING LINE NUMBERS NL
The nl filter adds line numbers to a file and it displays the file and not provides accessto edit but simply displays the contents on the screen. The following filter adds line number
To a specified file.
Syntax: $ nl file name
7.SELECTING FIELDS FROM A LINE-CUT:
We can select specified files from a line
of text using cut command.
Syntax: $ cutc file name
Where
-c : option cut on the specified character
position from each line.
filename :specifies name of the file.
8 PASTING FILES:
When you cut some of the characters in a file using the cut command those can be pastedback with the paste command.
Syntax: $ paste command
Example: $ paste std
9. COMPARTING FILES
To know weather two files are identical in all respects so that one of item may be deleted.This cmp command is used to carryout this task.
Syntax: $ cmp file1 file 2
Example: $ cmp std1 std2
-
7/31/2019 Stud Towrite
14/33
10. COMPARISON & DIFFERENCES
Comm command is used to compare two sorted files, and compares each line of the first filewith its corresponding line in the second.
The diff command can be used to display file differences but unlike it follow members cmp
and comm. It also tells you which lines in one file have to be changed to make the two filesidentical.
Syntax: $ comm. File1 file2
Syntax: $ diff file1 file 2
Result:
Thus the above commands have been executed successfully.
-
7/31/2019 Stud Towrite
15/33
-
7/31/2019 Stud Towrite
16/33
Ex. No:8
-
7/31/2019 Stud Towrite
17/33
Ex. No:9
Ex. No:10
-
7/31/2019 Stud Towrite
18/33
-
7/31/2019 Stud Towrite
19/33
COMMAND LINE ARGUMENT
Ex no : ADDING THE COMMAND LINE ARGUMENTS
AIM:
To write a shell program for using command line arguments.
ALGORITHM:
Step 1: Start the program
Step2: Read the arguments
Step3: Initialize the total
Step4: Loop to calculate the sum of arguments
Step5: Print the sum of arguments
Step6: Stop the program
RESULT:
Thus the program has been executed .
-
7/31/2019 Stud Towrite
20/33
Ex no 9b: SHIFTING THE COMMAND LINE ARGUMENTS
AIM:
To write a shell program for using command line arguments .
ALGORITHM:
Step 1: Start the program
Step2: Read the arguments
Step3: Initialize the arguments
Step4: shift the arguments
Step5: Print the result
Step6: Set the value for arguments
Step7: Stop the program
RESULT:
Thus the program has been executed .
-
7/31/2019 Stud Towrite
21/33
Ex no 9c: PRINTING THE NUMBER OF ARGUMENTS
AIM:
To write a shell program for using command line arguments .
ALGORITHM:
Step 1: Start the program
Step2: Read the arguments
Step3: Conditional statement to they determine the number of arguments
Step4: Print the number of arguments
Step6: Stop the program
RESULT:
Thus the program has been executed .
-
7/31/2019 Stud Towrite
22/33
-
7/31/2019 Stud Towrite
23/33
11. DYNAMIC STORAGE ALLOCATION
Ex no 11a: DYNAMIC STORAGE OF AN ARGUMENT
AIM:
To write a C program for dynamic storage of an argument.
ALGORITHM:
Step 1: Start the program
Step2: Read the argument value.
Step3: To locate the memory address of the argument value.
Step4: Print the address of the argument.
Step6: Stop the program
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
24/33
Ex no 11b: DYNAMIC MEMORY ALLOCATION USING MALLOC()
AIM:
To write a C program for dynamic memory allocation using malloc().
ALGORITHM:
Step 1: Start the program
Step2: Read the number of students using malloc().
Step3: Read the marks of students.
Step3: To calculate the average of the marks of the students.
Step4: Print the average of the marks.Step6: Stop the program
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
25/33
12.FUNCTIONS
Ex no 12A:FINDING ncr USING FACTORIAL FUNCTIONAIM:
To write a C program for finding ncr using factorial function
ALGORITHM:
Step 1: Start the program
Step2: Read the value of n and r.
Step3: Write a function for factorial fact().
Step4: using factorial function fact() calculate the ncr value.
Step5: Print the result value of ncr.
Step6: Stop the program
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
26/33
Ex no 12b:COSINE SERIES USING FUNCTIONAIM:
To write a C program for finding cosine series using function.
ALGORITHM:
Step 1: Start the program
Step2: Let the x value of cosine series starts with 0.
Step3: Write a function for cosine calculation cosine().
Step4: using cosine function cosine() calculate cosine series from 0 to 180 degree.
Step5: Print the cosine series value from 0 to 180 degree.
Step6: Stop the program
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
27/33
Ex no 12c:FUNCTION WITH ARGUMENTS AND RETURN VALUES
AIM:To write a C program for finding largest among 2 numbers using function.
ALGORITHM:
Step 1: Start the program
Step2: Read the function arguments.
Step3: Write a function largest(int a1,int b1).
Step4: Find the largest number calling largest().
Step5: Return the largest value to the main() function.
Step5: Print the largest value.
Step6: Stop the program
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
28/33
13.POINTERS
Ex no 13a: Basic Calculator using pointers
AIM:To write a C program to perform Arithmetic operations using pointers.
ALGORITHM:
Step 1: Start the program
Step2: Read the values for the pointer variables.
Step3: Using switch statement select any one of the operation addition, subtraction,
multiplication, division or modulus.
Step4: Find the result of the operation.
Step5: Print the result of the operation.
Step6: Stop the program.
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
29/33
Ex no 13b: Pass by value and reference using pointers
AIM:
To write a C program to swap the value or reference using pointers.
ALGORITHM:
Step 1: Start the program
Step2: Read the values for the pointer variables.
Step3: Using the functions swapval() and swapref() swap the value and reference address
respectively.
Step4: Print the swapped output for swapval() and swapref().
Step5: Stop the program.
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
30/33
Ex no 13c: String copy using pointers
AIM:To write a C program to copy from one string to another using pointers.
ALGORITHM:
Step 1: Start the program
Step2: Read the string for the pointer variables.
Step3: create a function stringcopy().
Step4: Call stringcopy() to copy from source to destination.
Step5: Print the source string and destination string.
Step5: Stop the program.
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
31/33
14. FILE HANDLING
Ex no 14a: Displaying file contents
AIM:To write a C program to display the contents of file, imitating cat command using FILEpointer.
ALGORITHM:
Step1: Start the program
Step2: Read the file name at the command line.
Step4: Open the file and read the content.
Step5: Display the content of the file.
Step6: Stop the program.
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
32/33
Ex no 14b: Copying a file
AIM:To write a C program to copy file, imitating cp command using FILE pointer.
ALGORITHM:
Step1: Start the program.
Step2: Read the source and destination file names at the command line.
Step4: Open the file and read the content.
Step5: Copy the content to the destination file.
Step6: Display the content of the file.
Step7: Stop the program.
RESULT:
Thus the program has been executed.
-
7/31/2019 Stud Towrite
33/33
Ex no 14c: Write to a file character-by-character
AIM:To write a C program to input File using getc and putc functions using FILE pointer.
ALGORITHM:
Step1: Start the program.
Step2: File name is provided at the program.
Step4: On execution, type the contents of the file and press cntrl+D.
Step5: File contents are updated.
Step6: Using the cat command, display the content of the file.
Step7: Stop the program.
RESULT:
Thus the program has been executed.