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

Orinetal Institue of Science and Technology

The document contains a summer internship report submitted by Priyesh Zope to Kuldeep Mishra. It includes an introduction to programming languages like C and features of the C programming language. It also includes examples of different C programs demonstrating the use of operators, conditional statements, loops and functions. The programs cover calculating sums and swapping numbers, finding percentages, reversing numbers, checking leap years, and simulating an ATM. The document provides a good overview of basic C programming concepts through examples.

Uploaded by

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

Orinetal Institue of Science and Technology

The document contains a summer internship report submitted by Priyesh Zope to Kuldeep Mishra. It includes an introduction to programming languages like C and features of the C programming language. It also includes examples of different C programs demonstrating the use of operators, conditional statements, loops and functions. The programs cover calculating sums and swapping numbers, finding percentages, reversing numbers, checking leap years, and simulating an ATM. The document provides a good overview of basic C programming concepts through examples.

Uploaded by

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

ORINETAL INSTITUE OF SCIENCE AND

TECHNOLOGY

SUMMER INTERNSHIP REPORT

SUBMITTED BY: SUBMITTED TO:


Priyesh zope KULDEEP MISHRA
IT B TRAINING HEAD OIST

1
INDEX

2
INTRODUCTION
# SOFTWARE:
Collection of data or computer instructions that tell the computer
how to work.
Computer hardware and software require each other and neither
can be realistically used on its own.

# PROGRAMMING LANGUAGE
A programming language is a vocabulary and set of grammatical
rules for instructing a computer or computing device to perform
specific tasks.
There are two types of language-
1. Low level language
- First generation language
- Second generation language
2. High level language
- Third generation language
- Fourth generation language
- Fifth generation language

3
C programming language
# INTRODUNCTION
It was developed at bell labs by Dennis Ritchie between 1972 &
1973.
C language is still popular and used so widely because of its
flexibility of its use for memory management. Programmers have
opportunities to control how, when and where to allocate and
deallocate memory.
It is the obvious choice to many code starters and builds
programming skills & mostly C is used.
# FEATURES OF C PROGRAMMING LANGUAGE
1. C is a simple language in the sense that is provides a
structured approach.
2. It is machine independent and portable language.
3. It is structured programming language
4. It supports the feature of dynamic memory allocation.
5. C language is extensible because it can easily adopt new
features.
6. C language provides a lot of inbuilt functions.
1-Program to calculate sum of two numbers
#include <stdio.h>
void main()
{
int a=10,b=10,c=0;
c=a+b;
printf("Sum= %d",c);
}

4
OUTPUT:

2-Program to display any two numbers


#include <stdio.h>
void main()
{
int a=10;
float b=20.00;
printf("Number %d, %f",a,b);
}
OUTPUT

3-Program to swap two numbers without using third variable


#include <stdio.h>
void main()
{
int a=10,b=20;
printf("Before swap a=%d b=%d",a,b);
a=a*b;
b=a/b;
a=a/b;
printf("\nAfter swap a=%d b=%d",a,b);
}
5
Output:

4-Program to calculate the percentage of a student in 5


subjects
#include <stdio.h>
void main()
{
float s1,s2,s3,s4,s5,perc=0.0;
int total;
printf("\n Enter the total marks: ");
scanf("%d",&total);
printf("\n Enter the marks obtained:- ");
printf("\n 1st subject: ");
scanf("%f",&s1);
printf("\n 2nd subject: ");
scanf("%f",&s2);
printf("\n 3rd subject: ");
scanf("%f",&s3);
printf("\n 4th subject: ");
scanf("%f",&s4);
printf("\n 5th subject: ");
scanf("%f",&s5);
perc=((s1+s2+s3+s4+s5)/total)*100;
printf("Percentage obtained= %f",perc);
}

6
Output:

# OPERATORS
1. Arithmetic operators:
 Addition operator : +
 Subtraction operator : -
 Multiply operator : *
 Divide operator : /
 Modulus operator : %
 Decrement operator : --
-Reduces the value by 1
 Increment operator : ++
-Increases the value with 1
 Assignment operator : ==
Assigns the value to the variables
2. Relational operator:
 Less than operator : <

7
 Greater than operator : >
 Less than or equal to : <=
 Greater than or equal to : >=
 Equal to : ==
 Not equal to : !=
3. Logical operator:
 AND operator : &&
 OR operator : ||
 NOT operator : !
4. Bitwise operator:
5-Program to reverse the entered number
#include <stdio.h>
void main()
{
int n,reverse=0,rem;
printf("\n Enter the number: ");
scanf("%d",&n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("\n Reversed number: %d",reverse);
}
Output:

8
# CONDITIONAL STATEMENTS
1. if statement-
- Have only one condition
- The condition may be true or false.
6-Program to explain if statement
#include <stdio.h>
void main()
{
int a=200;
if(a==200)
{
printf("\n Hello!!!!");
}
}

Output:

2. if-else statement
- Two conditions may be true.
- If the first condition is false then the control goes to
check the second condition
7-Program to explain if-else statement:
9
#include <stdio.h>
void main()
{
int a=10;
if(a==30)
{
printf("\nOGI\n");
}
else
printf("\nHello World!!!\n");
}

Output:

3. if-else-if statement:
- If the condition is true in between then the control will
go back from the true.
Program to explain if-else-statement
4. Nested if statement:
- Control will check all the condition whether the first
condition is true or false.
8-Program to check the number is even or odd number
#include <stdio.h>
void main()
{
int a;
10
printf("\n Enter a number: ");
scanf("%d",&a);
if(a%2==0)
{
printf("\n The number entered is even\n");
}
else
printf("\n The number entered is odd \n");
}

Output:

9-Program to check leap year or not


#include <stdio.h>
void main()
{
int year;
printf("\n Enter the year: ");
scanf("%d",&year);
if(year%400==0)
{
printf("%d is leap year",year);
}

11
else if(year%100==0)
printf("%d is not a leap year",year);
else if(year%4==0)
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
}
Output:

# Switch statement:
-One condition but multiple output whereas in if else if we have
multiple condition but one output.
10-Program to check eligibility for voting
#include <stdio.h>
void main()
{
int age;
printf("Enter your age: ");
scanf("%d",&age);
if(age>=18)
{
printf("You are eligible for voting");
}
else
printf("You are not eligible for voting");
}

12
Output:

11-Program of calendar
#include <stdio.h>
void main()
{
int d,r;
printf("Enter the date and month of 2020: ");
scanf("%d \n %d",&d,&r);
if(d<=31 && r<=12)
{
d=d%7;
switch(r)
{
case 1:
d=(d+2)%7;
break;
case 2:
d=(d+5)%7;
break;
case 3:
d=(d+6)%7;
break;
case 4:
d=(d+2)%7;
break;
case 5:
13
d=(d+4)%7;
break;
case 6:
d=d%7;
break;
case 7:
d=(d+2)%7;
break;
case 8:
d=(d+5)%7;
break;
case 9:
d=(d+3)%7;
break;
case 10:
d=(d+3)%7;
break;
case 11:
d=(d+6)%7;
break;
case 12:
d=(d+1)%7;
break;
}
switch(d)
{
case 0:
printf("Sunday");
break;
case 1:

14
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
}
}
else if(r>12 && d>31)
{
printf("Your entered date and month both are wrong");
}
else if(d>31)
{
printf("You entered a wrong date");
}
else
printf("You entered the wrong month");
}

15
Output:

# while loop
-  A while loop is a control flow statement that allows
code to be executed repeatedly based on a given
Boolean condition.
- The while loop can be thought of as a repeating if
statement.
# do-while loop
- A do-while loop is a control flow statement that
executes a block of code at least once.
- It either repeatedly executes the block, or stops
executing it, depending on a given Boolean condition at
the end of the block.
12-Program to print number & their sum from number 0 to 10
#include <stdio.h>
void main()
{
int a=0,sum=0;
do
{
printf("%d\n",a);
sum+=a;
a++;
}
while(a<=10);
printf("sum= %d",sum);
16
}

Output:

13-Program to print the table of 5


#include <stdio.h>
void main()
{
int i;
for(i=1;i<=10;i++)
{
printf("5 x %d = %d",i,5*i);
printf("\n");
}
}
Output:

17
# for loop
- It is primitive control loop
- It is entry control loop / primitive entry control loop.
14-Program to print factorial of any number
#include <stdio.h>
void main()
{
int a,fact=1;
printf("Enter the number: ");
scanf("%d",&a);
for(a;a>=1;a--)
{
fact=fact*a;
}
printf("%d",fact);
}
Output:

15-Program of an atm
#include <stdio.h>

18
#include <stdlib.h>

int main()
{
int ch,pin,Bal=100000,money,i,new_pin,new_pin2;
char ans;

printf("\nWELCOME TO ORIENTAL BANK\n ");


printf("\n Enter your pin: ");
scanf("%d",&pin);
if(pin<1500)
{
printf("\n\n\n");
printf("\n Hello sharad shrivastava \n");

printf("\nPress 1 for Balance Enquiry");


printf("\nPress 2 for Money Withdrawal");
printf("\nPress 3 for Mini Statement");
printf("\nPress 4 for Changing Pin");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
{

printf("\n\tYour Account Balance is = %d",Bal);


break;
}
case 2:

19
{

printf("\nEnter the amount you want to withdrawal:");


scanf("%d",&money);
if(money<Bal)
{
printf("\nollect your cash");
printf("\nDo you want reciept Y/N");
scanf("%c",&ans);
if(ans=='y' || ans=='y')
{
printf("\nCollect your reciept");
break;
}
else
break;
}
else
{
printf("\nInsufficient balance")
break;
}

}
case 3:
{
printf("\nCollect the reciept");
break;
}
case 4:

20
{
printf("\nEnter your old pin:");
scanf("%d",&pin);
printf("\nEnter the new pin:");
scanf("%d",&new_pin);
printf("\nEnter the pin once again:");
scanf("%d",&new_pin2);
if(new_pin==new_pin2 && new_pin2<=1500)
{
printf("\nYour pin change successfully");
break;
}
else
{
printf("\nError please try again");
break;
}

default:
{
break;
}
}
}
else
{
printf("\nYou entered the wrong pin\n");
break;

21
}
return 0;
}

Output:

16-Pattern 1
#include <stdio.h>
void main()
{
int i,j;
for(i=0;i<=4;i++)
{
for(j=1;j<=i;j++)
{

22
printf("* ");
}
printf("\n");
}
}

Output:

16-Pattern 2
#include <stdio.h>
void main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
}
Output:

23
17-Pattern 3
#include <stdio.h>
void main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",i);
}
printf("\n");
}
}
Output:

18-Pattern 4
#include <stdio.h>

24
void main()
{
int i,j;
for(i=3;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%d ",j);
}
printf("\n");
}
}
Output:

19-Pattern 5
#include <stdio.h>
void main()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=3;j>=i;j--)
{
printf("%d ",j);
}
printf("\n");
25
}
}

Output:

20-Pattern 6
#include <stdio.h>
void main()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=i;j++)
{
printf("A ");
}
printf("\n");
}
}
Output:

26
21-Pattern 7
#include <stdio.h>
void main()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=1; j<=i; j++)

{
printf("%d ",j*j);
}
printf("\n");
}
}
Output:

27
22-Pattern 8
#include <stdio.h>
void main()
{
int i,j,prod=1;
for(i=0;i<5;i++)
{
prod=1;
for(j=0;j<i;j++)
{
printf("%d ",prod);
prod=prod*2;
}
printf("\n");
}
}
Output:

23-Pattern 9
#include <stdio.h>

void main()
{
int i,space,rows,k=0;
printf(" Enter the number of rows: ");

28
scanf("%d",&rows);
for(i=1;i<=rows;i++,k=0)
{
for(space=1;space<=rows-i;space++)
{
printf(" ");
}
while(k!=2*i-1)
{
printf("* ");
k++;
}
printf("\n");
}
}
Output:

24-Pattern 10
#include <stdio.h>
void main()
{
int i,j;
char ch;
for(i=1;i<=3;i++)
29
{
ch='A';
for(j=1;j<=i;j++)
{
printf("%c ",ch++);
}
printf("\n");
}
}
Output:

25-Pattern 11
#include <stdio.h>
void main()
{
int a,b,c;
for(a=1;a<=3;a++)
{
for(b=3;b>a;b--)
{
printf("* ");
}
for(c=1;c<=a;c++)
{
printf("%d ",c);

30
}
printf("\n");
}
}

Output:

# TYPE CASTING
- Type casting refers to changing an variable of one data
type into another.
- The compiler will automatically change one type of data
into another if it makes sense.
- Type casting is of two types:
1. Implicit type casting
2. Explicit type casting
26-Program to explain both the type casting:
#include <stdio.h>
void main()
{
int x=10;
char y='a';
double b=1.2;

31
//y is implicitly converted to int ASCII
//value of 'a' is 97
x=x+y;
//x is implicitly converted to float
float z=z+1.0;
printf("x=%d, z=%f",x,z);
//explicit conversion from double to int
int sum=(int)b+1;
printf("\nsum=%d",sum);
}
Output:

#ADDRESS OF OPERATOR
- The address of operator denoted by the ampersand
character (&), & is a unary operator, which returns the
address of a variable.
#POINTER
- The pointer in c language is a variable, it is known as
locator or indicator that points to an address of a value.
- Syntax of pointer-
int *a; // pointer to int
->NULL pointer:
A pointer that is not assigned with any value but NULL is known
as NULL pointer.
Syntax-
Int *ptr=NULL; //declaration of NULL pointer

32
#C POINTER TO POINTER
- In C pointer to pointer concept, a pointer refers to the
address of another pointer.

#FUNCTION
- A function is a group of statements that together
perform a task.
- Advantages of using a function in C-
1. Reusability
2. Easy to define
3. Reduces the size of program.
27-Function without argument & without return value
Program –
#include <stdio.h>
void printName(); //declaration of function
void main()
{
printf("Hello World!\n");
printName(); //calling of function
}
void printName() //function definition
{
printf("OGI");
}
Output:

28-Function without argument & with return value

33
#include <stdio.h>
int sum();
void main()
{
int result;
printf("\n Going to calculate the sum of two number\n");
result=sum();
printf("%d",result);
}
int sum()
{
int a,b;
printf("\n Enter the two numbers: ");
scanf("%d %d",&a,&b);
return a+b;
}
Output:

29-function with argument but without return type


Program-
#include <stdio.h>
void sum(int, int);
void main()
{

34
int a,b;
printf("\n Going to calculate the sum of two numbers");
printf("\n Enter the two numbers: ");
scanf("%d %d",&a,&b);
sum(a,b);
}
void sum(int a,int b)
{
printf("\n The sum of two numbers: %d",a+b);
}
Output:

30-function with argument & with return value


Program-
#include <stdio.h>
int sum(int ,int);
void main()
{
int a,b;
printf("\n Going to calculate the sum of two numbers\n");
printf("\n Enter the two numbers: ");
scanf("%d %d",&a,&b);
printf("\n The sum of two number: %d",sum(a,b));
}

35
int sum(int a, int b)
{
return a+b;
}

Output:

31-Program to check whether the entered number is even or


odd using a function
#include <stdio.h>

int check(int );
void main()
{
int a;
printf("\n Going to check whether the given number is even or
odd\n");
printf("\n Enter the number: ");
scanf("%d",&a);
check(a);

36
}
int check(int a)
{
if(a%2==0)
return printf("\n Entered number is even");
else
return printf("\n Entered number is odd");
}
Output:

# VARIABLES IN C
- A variable in a name of memory location. It is used to
store data. Its value can be changed & it can be reused
many times.
- There are three types of variables in C:
1. Local variables
2. Global variables
3. Static variables
# COMMENTS IN C
- There are three types of comments
1. Single line comments
Syntax:
int x=10 //comments
2. Multiple line comments

37
Syntax:
/*comment………
…………..
………..*/
3. Multiple comments
Syntax:
/*….
*……..
*………
*………
*/
# FUNCTION CALLING
1. Call by value
The call by value method of passing arguments to a function
copies the actual value of an argument into the formal
parameter of the function.
Value is not modified in call by value
32-Program to explain passing the value in function / call by
value
#include <stdio.h>
void change(int num)
{
printf("\n Before adding value inside function num= %d",num);
num=num+10;
printf("\n After adding value inside function num= %d",num);
}
void main()
{
int x=100;
printf("Before function call x=%d",x);

38
change(x); //passing the value in the function
printf("\n After function call x=%d",x);
getch();
}

Output:

2. Call by reference
The call by reference method of passing arguments to a
function copies the address of an argument into the formal
parameter.
Inside the function, the address is used to access the actual
argument used in the call.
33-Program to explain call by reference
#include <stdio.h>
void change(int *num)
{
printf("\n Before adding value inside function num= %d",*num);
*num=*num+10;
printf("\n After adding value inside function num= %d",*num);
}
void main()
{

39
int x=100;
printf("Before function call x=%d",x);
change(&x); //passing reference in the function
printf("\n After function call x=%d",x);
getch();
}

Output:

# STRINGS
- String is an array of characters that is terminated by \0
(NULL character).
- Syntax:
Char c[]=”c string”;
- There are two ways to declare strings in c:
1. By char array
Syntax:
Char ch[10]={‘j’,’a’,’v’,’a’,’\0’};

2. By string literals
Syntax:
Char ch[]=”java”;
Some functions used in strings are :

40
1. strlen(string_name)-
- Returns the length of the string.
2. Strcpy(destination,source)-
- Copies the contents of source string to the destination
string.
3. strcat(first_string,second_string)-
- Concats or joins the first and the second string.
- The result of new string is stored in first string.
4. strcmp(first_string,second_string)-
- compares the first string with second string.
- If both the string are same then it will returns 0
otherwise 1.
5. strupr(string_name)-
- Changes the lowercase letters to uppercase letters of
strings.
6. strlwr(string_name)-
- Changes the uppercase letter of the string to the lower
case letter.
34-Program to explain string.
#include <stdio.h>
void main()
{
char ch[20]={'j','a','v','a','\0'};
char ch2[20];
char a[10]={'P','r','y','e','s','h','\0'};
char b[10]={' ','z','o','p','e','\0'};
printf("\n Length of the string= %d",strlen(ch));
strcpy(ch2,ch);
printf("\n Value of second string is: %s",ch2);
strcat(a,b);

41
printf("\n String after Concating: %s",a);
printf("\n Comparing of strings gives %d",strcmp(ch,ch2));
}

# ARRAY IN C
An array is a collection of data items all of the same type,
accessed using a common name.
Syntax:
Data_type array_name[array_size];
->Array initialization
1. By index
2. array declaration with initialization
->Types of array
1. 1-D Array
2. 2-D Array
3. Multi-dimensional array

35-Program to explain array


#include <stdio.h>
void main()
{
int i,j;
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
//traversing of 2-d array
for(i=0;i<4;i++)

42
{
for(j=0;j<3;j++)
{
printf("arr[%d][%d]=%d\n",i,j,arr[i][j]);
}//end of j
}//end of i
}

Output:

36-Program to print 2-d array as matrix


#include <stdio.h>
void main()
{
int i,j;
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
//traversing of 2-d array
for(i=0;i<4;i++)

43
{
for(j=0;j<3;j++)
{
printf("%d ",arr[i][j]);
}//end of j
printf("\n");
}//end of i
}

Output:

44
Using Linux
Basic Commands in Linux
#ls (List the contents of any directory)
#ls -l (Long listing - detailed report of available files)
#ls -la (Long listing including hidden files)
#pwd (Shows your present working directory)
#cd .. (change directory - moves you to one level up)
#cd /var/tmp (change directory to the specified path)
#cd (Bring back to your home directory)
Ctrl + L (Clear Screen)
Shift + Page up Key (scroll your screen upwards)
Shift + Page down Key (Scroll your screen downwards)
#cd - (Switches u between your current & previous directory)
#touch file1 (creates an empty file)
#mkdir dir1 (Creates new directory)
#cd dir1 (change directory to dir1)
#pwd
#cat > file2 (Create new file with data)
Enter the data and press control + d to save the contents
#cat file2 (check the data inside the given file)
#cat >> file2 (Appends the new data in previously created file)
Enter the data, press enter and ctrl + d
#cat file2
--------------------------------------------------------
COPY
#cp file2 file3 (make a copy of file2 with new name file3 including the contents of file)
#cp file2 /tmp (make a copy of file2 in /tmp directory)
#cp file2 /tmp/backup_file2 (make a copy of file2 in /tmp directory with new name)
#cp -r dir1 dir2 (-r switch is used to copy a directory)

45
#cp -r dir1 /tmp/backup_dir1 (copy directory & rename)
----------------------------------------------------------
MOVE
#mv dir1 /var/tmp/ (Moves the dir1 to specified path)
#mv file1 /tmp/backup_file1 (Move and rename)
--------------------------------------------------------

RENAME
#mv old_name new_name (same mv command is used for renaming)
--------------------------------------------------------
REMOVE/DELETE
#rm file1 (delete regular file)
#rm -r dir1 (deletes the directory)
#rm -rf dir2 (deletes all data in directory forcefully, use carefully)
---------------------------------------------------------
Basic Directory Structure
Directory Architecture
Directories inside the /
/boot - (as name suggests, file under this directory are used for booting purpose)
/home - (Contains home directory of normal users)
/root - (Home directory user root)
/etc - (All sort of configurations files are stored into this directory)
/bin - (bin refers to binary files, binary files are executables similar to exe files in windows)
/sbin - (Binary related with user root are stored into this directory, normal user cannot
access the sensitive commands in linux system)
/dev - (In linux everything is file, Files related with connected hardware devices in your
system, are stored into this directory[Block special & character special files])
/lib - (Contains Library files)
/media - (Used to access CD & Pendrives)
/mnt - (It is used for temporary mounting)
/proc - (Live information about hardware i.e. RAM,CPU etc)
/usr - (Usr is treated as program files folder in windows)
/var - (Contains the information related to servers ie. web,ftp etc)

Basic VIM editor


Vi is a powerful editor in linux used to edit files.
VIM is an upgraded version of vi we use currently to edit files.

#vim filename
There are 3 modes in vim editor :
1)Command Mode
2)Insert Mode
3)Exit Mode
Command Mode :-

46
This mode is used to run commands in vim editor like copy, paste, search, delete, undo etc.
Search in Vim -
/<text> - search the <text> downwards in file
n - continue search in same direction
N - continue search in opposite direction
?<text> - search upwards in file
n - continue search in same direction
---------------------------------------------------
u - used to undo the last change's
--------------------------------------------------
yank(copy) | cut (delete)
------------------------------------------------
word - yw | dw
line - yy | dd
5line - 5yy | 5dd
25line- 25yy | 25dd
put (paste)
p - used to paste the data below cursor for line oriented data
P - used to paste the data above cursor
---------------------------------------------------------------
Insert Mode :-
It is Used to enter or edit text and for cursor movement within file
i - insert
a-?
o-?
I-?
O-?
A-?
<Esc> is used to exit from insert mode to command mode
----------------------------------------------------------
Exit Mode :-
This mode is used to save and exit the file
:q - quit
:wq - write & quit
:w - write only
:q! - exit forcefully and abandon changes
:wq! - save & exit forcefully

Find Command in Linux


--------------------------------------
Find is used to search the data anywhere in system :
#find / -name passwd {Command will search file named passwd in / , remember
this command will exactly match the case of search value, you have entered}
#find / -name *.jpg {command will search all the files in your system having
extension .jpg}
#find / -iname passwd {Command will search the value "passwd" in capital or
small letters in whole system, including all mounted partitions}
#find / -user username {command will search all the data belongs to username user
in whole system }
#find / -size +10M{Command will search all the files in system those are greater

47
then 10 MB in size in whole system, you can search in K,M,G}
#find / -size -10M {Command will search all the files in system those are smaller
then 10 MB in size, This command is practically not usable as maximum files in
system is below 10M}
#find / -size 10M {Command will search the files of exact 10 MB}
#find /home -ctime +3 {Command will search the data "created" before then last 3
days}
#find /home -atime -3 {Command will search the data "accessed" within last 3
days}
#find /home -mtime 3 {Command will search the data "modified" exactly 3 days
before}

Redirection
------------------------------------------
#ls -l / {Command will return Standard Output on Monitor}
Redirection Standard Output for any other use :-
#ls -l / > stdout [ 1> and > is same ] {This command will redirect to output of ls -l
Command to the file stdout, you will not able to see anything on screen after
command.
#cat stdout { Now this command will show the output of previous command as the
output of ls -l / command is stored permanently in stdout file}
Appending the Standard Output :-
#ifconfig > stdout
#ls -l / >> stdout {This command will append the output of ls -l command to file
stdout.
--------------------------------------------------------------------

Redirecting Standard Error


----------------------------------------------------------
Assuming we are adding the user named motorola and his primary is google, but
google group doesn't exist in machine, then useradd command will return the error,
and we will store the standard error generated by command.
#useradd -g google motorola {This command will generate the error}
#useradd -g google motorola 2> error {by this command any output generated by
useradd command is stored into file "error".
--------------------------------------------------------------------
Redirect Standard Output & Error separately in single command
$find / -iname passwd > stdout1 2> stderr1 {Command will store the output in file
stdout1 and error in stderr1 file separately}
$find / -iname passwd &> stdout_err {Command will store the output and error in
single file}
---------------------------------------------------------------------
Using Pipe Operator
| (pipe) Operator is used to send the output on one command to another command.
For example if we run

48
#ls -l /etc
Above command will generate a very long output and we are not able to see the
output in one screen, then using | operator, we will redirect the output of ls
command to more command :
#ls -l /etc/ | more
This will show the output of /etc directory in a page wise manner.
Another example :
#cat /etc/passwd {this will show the output of /etc/passwd file in small alphabets}
#cat /etc/passwd | tr 'a-z' 'A-Z' {Command will convert the small letters into capital
letters as the output of /etc/passwd is truncated into capital letters using tr command}
#cat /etc/passwd | tr 'a-z' 'A-Z' | more {Command will send the output of cat
command to tr and tr command's output will be sended to more command}
#cat /etc/passwd | tr 'a-z' 'A-Z' > capspasswd {Finally command will store the
output in caps passwd file in capital letters.
--------------------------------------------------------------------------
Using grep command :-
#cat /etc/passwd | grep -i root {Grep command is used to grep the required output
from the long files, in this command we are trying to capture the lines where word
"root" is used. -i switch is used to ignore the case sensitivity.
#cat /etc/httpd/conf/httpd | grep virtualhost
#cat /etc/httpd/conf/httpd | grep -i virtualhost { see the difference in above last
two commands}
--------------------------------------------------------------------------

diff
Create two similar files of 3 or 4 lines and check the differences between both the files.
#diff file1 file2 >> track_differences
----------------------------------------------------------------
Head & Tail
#head -n 10 /etc/passwd
#tail -n 10 /etc/passwd
# ls -lt | head -n 10 {This command will show last 10 modified files in /etc
directory}
---------------------------------------------------------------------
tee Command
#ifconfig | tee test12 {this command will store the output of ifconfig
command as well display the output of ifconfig on screen }
-----------------------------------------------------------------
Standard Input
echo "redhat" | passwd --stdin student
-----------------------------------------------------------------------
Input & Output Diagram and then 2>&1
2>&1 is used to channelize the data via pipe i.e. stderr is redirected via pipe to stdout
and then the data is stored in a file.

49
THANK YOU

50
51

You might also like