You are on page 1of 143

Page|1

Page|2

ORIENTAL COLLEGE Of TECHNOLOGY


BHOPAL

SUMMER INTERNSHIP REPORT


TOPIC:- C Language and LINUX
Submitted to : Prepared by :
Kuldeep Mishra Neha kumari
(Training dept. HEAD,OCT ) 0126CS191064(CS-B)
Page|3

CONTENT:
1. Introduction …………………………………………………….. 3
2. Data type……………………………………………………… .. 7
3. Conditional statement………………………………………… . 17
4. Loop…………………………………………………………… 25
5. Pointer…………………………………………………………..29
6. Function…………………………………………………………32
7. String…………………………………………………………… 38
8. Arrays……………………………………………………………41
9. Structure & union………………………………………………..44
10.Introduction to linux………………………………….......48
Page|4
Page|5
Page|6
Page|7

INTRODUCTION TO C
What is C ?
C is a general –purpose programming language that is
extremely popular, simple and flexible. It is machine
independent Structured programming language which
is used extensively in various applications.
‘C’ is a powerful programming language which is
strongly associated with UNIX operating system.

Why learn ‘C’ ?


C is the base language for many programming
languages. So , learning ‘C’ as the main language will play an
important role while studying other programming languages. It
shares the same concept such as data types, operators, control
statements and many more. C can be used widely in various
applications .It is a simple language and provides faster
execution.
Page|8

Features of C Programming
language:

procedural language fast and efficient easy to extend

modularity

Features of
modularity statically type
C middle level
language
general purpose language
language

libraries with rich functions rich set of built-in operators

• Procedural Language: In a procedural language like


C step by step predefined instructions and carried out. C program contain
more than one function to perform a particular task. Most of the commonly
used paradigm is an object oriented programming language.
• Fast and Efficient: Newer languages like python, java offer more features
than C programming language but due to additional processing in these
Page|9

languages, their performance rate gets down effectively. It’s fast because
statically typed languages are faster than dynamically typed languages.
• Modularity: The concept of storing C programming language code in the
form of libraries for further future uses known as modularity. C language has
its own library to solve common problems like in this we can use a particular
function by using header files stored in its library.
• Statically type: C programming language is a statically typed language .
meaning the type of the variable is checked at the time of compilation but not
at run time. Means each time a programmer type a program they have to
mention the type of variables used.
• General purpose language: From system programming to photo editing
software, C programming is used in various applications .some of the
common applications are
Operating system:Windows, linux, iOS , Android , OXS
Databases: PostgreSQL, Oracle, MySQL, MS SQL Server etc.
• Rich set of Built-in Operators: It is a diversified language with a set of
built-in operators which are used in writing complex or simplified C programs.
• Libraries with rich functions: Robust beginner coder to code with
ease.
• Middle-Level Language: As it a middle level language so it has
combined form of both capabilities of assembly language and features of high
level language.
P a g e | 10

• Portability: C language is a lavishly portable as programs written in C


language can run and compile on any system with either none or small
changes.
• Easy to Extend: Programs written in C language can be extend means
when a program is already written in it then some more features and operations
can be added into it.

Fundamentals of C

C character set: Character set is a set of valid characters that, a language


can recognize. A character represents any letter,digit or any other sign.
types Character set
Lowercase letters a-z
Uppercase letters A to Z

Digits 0-9

Special characters !@#$%^&*


White spaces tab or new line or space
P a g e | 11
P a g e | 12
P a g e | 13

Identifiers: Identifiers are the fundamental building blocks of a program which are
P a g e | 14

used to give the name to data items included by the programmer.


Rules for writing identifiers are:
• Only alphabets ,digits and underscore are permitted.
• Identifier name cannot start with a digit.
• Keywords cannot used as a identifier.
• Upper case and lower case letters are distinct because C is a case sensitive
language.
• Special characters are not allowed.

Keywords: keywords are predefined reserved words by the programming


language that have some special or predefined meanings. these are identifiers.
For ex- class, void, sizeof, const, double etc.

What are data types?


Data types specify how we enter data into our programs and what type of data
we enter. C language has some predefined set of data types to handle various
kind of data that we can use in program.
There are two different type of data types:
• Primary data types: these are data types namely int, char , float , void.
• Derived data types: This includes array , structure , union and pointer.
P a g e | 15
P a g e | 16

Variables: A variable is a container to hold data. To indicate the storage area,


each variable should be given a unique name(identifier).variable name are just the
symbolic representation of a memory location.
Variables based on data types are:
• Character variables: these are used to store character constants like ‘R’ , ‘b’ ,
‘‘.
• Integer variables: these are used to store whole numbers.
• Float variables: these are used to store floating point numbers.
• Double variables: these are used for handling floating point numbers, with
much larger range and precision. Operators: An operator is a symbol that
tells the compiler to perform specific mathematical or logical functions. C
language is rich in built-in operators and provides the following types of
operators.
Arithmetic operator: these operators are used to do arithmetic
operations.
These are divided into two types:-
1. Binary operator: the operators that work upon two operands are binary
operators.
These are addition, subtraction, multiplication and division operator.
2. Unary operator: operators that work on single operand to form an
expression are unary operators.
P a g e | 17

These are unary plus(+) and unary minus(-) operator.

Logical operators: these operators are used to make a decision on two


conditions.

1. Logical AND operator (&&) : it returns TRUE , if both the conditions


are true, otherwise returns FALSE.

2. Logical OR operator (||) : it returns TRUE if atleast one of the two


conditions is true.

3. Logical NOT operator : it works on single operand. It is used to reverse


the logical state of its operand. if a condition is TRUE then logical
NOT operator will make it false.
operands to one another. relational operators are ==, !=, <, >, <=, >= .

Operator precedence:
1.Postfix/prefix increment (++) : the increment operator is used to
increase some value by 1.
2.Postfix/prefix decrement(--) : the decrement
P a g e | 18
P a g e | 19
P a g e | 20
P a g e | 21
P a g e | 22
P a g e | 23

Q. Enter marks of five subjects and calculate percentage.


P a g e | 24
P a g e | 25
P a g e | 26

{
P a g e | 27
P a g e | 28
P a g e | 29
P a g e | 30
P a g e | 31

Conditional statement: such programs must contain two or more statements


that might be executed, but might have some way to select only one of the listed
options each time the program is run. This is known as conditional execution.
• if statement: here logical condition is tested which, may either true or false.
if the logical test is true the statement that immediately follows if is
executed. If the logical condition is false the control transfers to the next
executable statement.
Syntax:
If(condition)
{
statement 1;
statement 2;
___________;
}
P a g e | 32
P a g e | 33

• if – else statement: if there are two statements to be executed


P a g e | 34

alternatively, then if-else statement is used. The if-else is a two way


branching.
P a g e | 35

if(num%2==0) printf(“even
number”); else printf(“odd
number”);
}

• Nested if statement:
The ANSI standard specifies that 15 levels of nesting must be supported. In
C ,an else statement always refers to the nearest if statement in the same
block and not already associated with if. For ex:
main()
{
int num;
printf(“Enter a number:”); scanf(“%d”,&num);
if(num > 0)
{
If(num %2 ==0)
printf(“even number”); else
printf(“odd number”);
}
else

{
if(num < 0)
printf(“negative number”); else
printf(“ number is zero”);
P a g e | 36

}
}
P a g e | 37

The conditional expressions are evaluated from the top downward. As soon
P a g e | 38

as a true
Condition is found, the statement associated with it is executed, and the rest
of the ladder is bypassed, if none of the conditions is true, then the final else
statement will be executed.

Switch statement: it is used when an expression value is to be checked


against several values. If a match takes place, the appropriate action is taken.
The general form of switch case statement is:
Syntax:
switch (expression)
{
case constant1;
statement; break;

case constant2;
statement; break;
default:
statement; break;
}
FOR EXAMPLE:
Q. Create a C program to perform basic functions of an ATM using switch case.

#include <stdio.h> unsigned long amount=1000,

deposit, withdraw; int choice, pin, k;

char transaction ='y';

void main()
{
P a g e | 39

while (pin != 1520)


{
printf("ENTER YOUR SECRET PIN NUMBER:");
scanf("%d", &pin); if (pin != 1520)
printf("PLEASE ENTER VALID PASSWORD\n");
}
do
{
printf("***Welcome to ATM Service*****\n");
printf("1. Check Balance\n"); printf("2.
Withdraw Cash\n"); printf("3. Deposit Cash\n");
printf("4. Quit\n");
printf("******?*********?\n\n"); printf("Enter
your choice: "); scanf("%d", &choice);
switch (choice)
{
case 1:
printf("\n YOUR BALANCE IN Rs : %lu ", amount);
break; case 2:
printf("\n ENTER THE AMOUNT TO WITHDRAW: "); scanf("%lu",
&withdraw);
if (withdraw % 100 != 0)
{
printf("\n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100");
}
else if (withdraw >(amount - 500))
{
printf("\n INSUFFICENT BALANCE");
}
else
{
amount = amount - withdraw; printf("\n\n PLEASE COLLECT
CASH"); printf("\n YOUR CURRENT BALANCE IS%lu", amount);
P a g e | 40

}
break; case 3:
printf("\n ENTER THE AMOUNT TO DEPOSIT");
scanf("%lu", &deposit); amount = amount + deposit;
printf("YOUR BALANCE IS %lu", amount); break; case 4:
printf("\n THANK U USING ATM");
break; default:
printf("\n INVALID CHOICE");
}
printf("\n\n\n DO U WISH TO HAVE ANOTHER
TRANSCATION?(y/n):\n");
fflush(stdin);
scanf("%c", &transaction); if (transaction == 'n'||
transaction == 'N') k = 1;
} while
(!k);
printf("\n\n THANKS FOR USING OUT ATM SERVICE");
}

OUTPUT:
P a g e | 41

Q. Create C program to find the day of the given date.

#include<stdio.h>
#include<conio.h>
#include<math.h> int main(){ int dat,
mont, years; printf("Enter the year : ");
scanf("%d", &years); printf("\n Enter the
month : "); scanf("%d", &mont);
printf("\n Enter the date : "); scanf("%d",
&dat); weekday(dat, mont, years);
return 0;
}
int weekday(int date, int month, int year) {
int dayWeek, yr, yd; yr = year % 100; yd = year / 100; printf("\nThe
Date Given is : %d / %d / %d \n\n", date, month, year); dayWeek = 1.25 * yr +
findm(month, year) + date - 2 * (yd % 4); dayWeek = dayWeek % 7; switch
(dayWeek){ case 0: printf("Day of Week of the Date is : Saturday"); break;
case 1: printf("Day of Week of the Date is : Sunday"); break;
case 2: printf("Day of Week of the Date is : Monday"); break;
case 3: printf("Day of Week of the Date is : Tuesday"); break;
case 4: printf("Day of Week of the Date is : Wednesday");
break;
case 5: printf("Day of Week of the Date is : Thursday");
break;
case 6: printf("Day of Week of the Date is : Friday"); break;
default: printf("The Given input data is wrong");
}
return 0;
}
int findm(int months, int yearss){ int
findmonth, leapyr;
P a g e | 42

if ((yearss % 100 == 0) && (yearss % 400 != 0))


leapyr = 0; else if (yearss % 4 == 0) leapyr = 1;
else leapyr = 0;
findmonth = 3 + (2 - leapyr) * ((months + 2) / (2 * months))
+ (5 * months + months / 9) / 2; findmonth =
findmonth % 7; return findmonth;
}
P a g e | 43
P a g e | 44
P a g e | 45
P a g e | 46

LOOP
It executes a block of statements number of times until the condition
becomes False.
Loops are of two types:
Entry control loop Exit
control loop.
C programming provides us:
1.while
2.do-while
3.for loop

FOR LOOP:
Syntax:
for(conditions)
{
//statements
}
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to
execute a specific number of of times.

WHILE LOOP:
P a g e | 47

Syntax:
while(condition)
{

// statements
}
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 :
Syntax: do
{
//statements
}
while(conditions);

do while loop is a control flow statement that executes a block of code at least once, and then either repeatedly
executes the block, or stops executing it, depending on a given boolean condition at the end of the block.

EXAMPLE:
Q. Create a C program to to print a pyramid of alphabets by using for loop .

#include <stdio.h>

void main()
{ int i,
j;
char alph = 'A'; int
n,blk;
int ctr = 1;

printf("Input the number of Letters (less than 26) in the Pyramid :


P a g e | 48

");
scanf("%d", &n);

for (i = 1; i <= n; i++)


{
for(blk=1;blk<=n-i;blk++)

printf(" ");
for (j = 0; j <= (ctr / 2); j++) {
printf("%c ", alph++);
P a g e | 49

}
P a g e | 50
P a g e | 51
P a g e | 52

11 12 13 14 15
#include <stdio.h>
int main()
{ int i, j, k, N;

printf("Enter N: ");
scanf("%d", &N);
k = 1;

for(i=1; i<=N; i++)


{
// Logic to print numbers
for(j=1; j<=i; j++, k++)
{
printf("%3d", k);
}

printf("\n");
}

return 0;
}
P a g e | 53
P a g e | 54
P a g e | 55
P a g e | 56
P a g e | 57

POINTER
Pointer is a fundamental part of C. If you cannot use pointers properly then you
have basically lost all the power and flexibility that C allows. The secret to C is in
its use of pointers.
C uses pointers a lot because:
• It is the only way to express some computations.
• It produces compact and efficient code.
• Pointers provided an easy way to represent multidimensional arrays.
• Pointers increase the execution speed.
• Pointers reduce the length and complexity of program. C uses pointers
explicitly with arrays, structures and functions.

A pointer is a variable which contains the address in memory of another variable.


We can have a pointer to any variable type.

The unary operator & gives the “address of a variable''. The indirection or
dereference operator * gives the “contents of an
P a g e | 58

object pointed to by a pointer''.

To declare a pointer to a integer variable do:


int *pointer;

Q. Create a C program to store the address of character variable by using pointer


and increment its value by one.

#include<stdio.h>
void main()
{
char *a; char
x='C'; a=&x;
printf("%c",*a);
(*a)++;
printf("%c",*a);
}
P a g e | 59

Q. Create a C program to store the address of integer variable by using pointer and
pointer to pointer.

#include<stdio.h>
void main()
{
int *pa; int **pb; int
a=10; pa=&a;
pb=&pa; printf("%x",
pa); printf("\n%x",
pb); printf("\n%d",
*pa); printf("\n%d",
**pb);
}
P a g e | 60
P a g e | 61
P a g e | 62
P a g e | 63
P a g e | 64

FUNCTION
Functions are a group of statements that have been given a name. This allows you to break
your program down into manageable pieces and reuse your code.

The advantages of functions are:


1. Function makes the lengthy and complex program easy and in short forms. It means large
program can be sub-divided into self-contained and convenient small modules having
unique name.
2. The length of source program can be reduced by using function by using it at different
places in the program according to the user’s requirement.
3. By using function, memory space can be properly utilized. Also less
memory is required to run program if function is used.
4. They also allow more than one person to work on one program.
5. Function increases the execution speed of the program and makes the programming simple.
6. By using the function, portability of the program is very easy.
7. It removes the redundancy (occurrence of duplication of programs) i.e. avoids the repetition
and saves the time and space.
P a g e | 65

8. Debugging (removing error) becomes very easier and fast using the function sub-
programming.
9. Functions are more flexible than library functions.
10. Testing (verification and validation) is very easy by using functions. 11. User can build a
customized library of different functions used in daily routine having specific goal and link
with the main program similar to the library functions.

The functions are classified into standard functions and user-defined functions.

The standard functions are also called library functions or built in functions. All standard
functions, such as sqrt(), abs(), log(), sin(), pow() etc. are provided in the library of functions.
These are selective.

These functions must be written by the user (programmer), hence, the name userdefined
functions.

There are 3 parts for using functions:


• Calling them,
• Defining them and

• Declaring them (prototypes).


1.Calling functions:
When you wish to use a function, you can "call" it by name. Control is sent to
the block of code with that name. Any values that the function needs to perform
its job are listed in the parentheses that immediately follow the name are called
arguments. The computer will retrieve the values held by the variables and hand
them off to the function for its use. The number of arguments (or values) must
P a g e | 66

match the variables in the definition by type and number. A semicolon must be
present, when the function is called within the main() function. follows:
The general form of a ANSI method of function call is as function_name

(actual parameters

2.Defining functions:
Defining a function means writing an actual code for the function which does a
specific and identifiable task. Suppose you are defining a function which
computes the square of a given number. Then you have to write a set of
instructions to do this.
The general form of a ANSI method of function definition is as follows:

type_specifier function_name (formal parameters)


{
variable declaration; /* with in the function */ body of function;
*
*
*
return (value_computed);
}

3.Function declaration:
Function declaration means specifying the function as a variable depending on the
return value return value. It is declared in the declaration part of the main
P a g e | 67

program. The default return value from a function is always an integer. If the
function is returning a value other than an integer, it must be declared with the data
type of the value it returns.

4.Function Arguments/Parameters:
arguments and parameters are the variables used in a program and a
function.variables used in the function definition (called function) are called
parameters.

There are two methods of parameter passing:


1. Call by value
2. Call by reference

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. In this case,
changes made to the parameter inside the function have no effect on the argument.
By default, C programming uses call by value to pass arguments

For ex:
#include <stdio.h>
int sum(int a, int b)
{
int c=a+b;
return c;
}
P a g e | 68

int main()
{
int var1 =10; int
var2 = 20;
int var3 = sum(var1, var2);
printf("%d", var3);

return 0;
}

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. It means the changes made
to the parameter affects the passed argument.

For ex:
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter Two Values: ");
scanf("%d %d",&a,&b); c=add(&a,&b);
printf("The Sum is: %d",c);
}
P a g e | 69

add(int *x,int *y)


{ int z;
z=*x+*y;
return(z);
}

EXAMPLE:
Q. Create a function in C language to increment the value of integer by 100 by
using pointer.

#include<stdio.h>
void ch(int *num)
{
printf("Before adding values inside fun num= %d \n",*num);
(*num)+=100;
printf("After adding values inside functio num= %d \n",*num);
}
int main()
{
int x=100;
printf("Before function call x=%d \n",x); ch(&x);
printf("After function call x=%d \n",x); return 0;
}
P a g e | 70
P a g e | 71
P a g e | 72
P a g e | 73

STRINGS

Strings are defined as an array of characters. The difference between a character


array and a string is the string is terminated with a special character '\0'.
Declaration of strings: Declaring a string is as simple as declaring a
onedimensional array.
SYNTAX:
char str[8]={‘p’,’r’,’o’,’g’,’r’,’a’,’m’};
char a[8]=”program”;

Q. Create a Program in C language to use following function


1. strcat()
2. strcpy() 3. strcmp().
P a g e | 74

#include<stdio.h>
#include<string.h>
#include<conio.h> int
main()
{
char a[20]="programing "; char
b[10]="language"; char c[20]="programing
language";
char d[20]; strcat(a,b);
printf("%s",a); strcpy(d,c);
if(strcmp(a,d)==0)
printf("\nmatch");
getch();
return 0;
}

Q. Write a program to reverse a string.


#include<stdio.h>

#include<conio.h> void

main()

{ int i, j, k; char str[100];

char rev[100]; printf("Enter a

string:\t"); scanf("%s", str);

printf("The original string is %s\n", str); for(i = 0; str[i]

!= '\0'; i++);
P a g e | 75

{ k = i-

1;

for(j = 0; j <= i-1; j++)

rev[j] = str[k]; k--;

printf("The reverse string is %s\n", rev); getch();

}
P a g e | 76
P a g e | 77
P a g e | 78
P a g e | 79

ARRAY
An array is a collection of variables of the same type that are referenced by a common name. In
C, all arrays consists of contiguous
memory locations. The lowest address corresponds to the first element,
P a g e | 80

and the highest address to the last element. Arrays may have from one to several dimensions.
A specific element in an array is accessed by an index.

One Dimensional Array:

The general form of single-dimension array declaration is:


Type variable-name[size];
Here, type declares the base type of the array, size defines how many elements the array will
hold.

For example

long:
int sample[10];
In C, all arrays have zero as the index of their first element. This declares an integer array that
has ten elements, sample[0] through sample[9].

FOR EX.

Q. To find average of ten numbers.

# include <stdio.h> main()


{
int i, avg, sample[10];
for (i=0; i<10; i++)
{
printf (“\nEnter number: %d “, i); scanf(“%d”,
&sample[i]);
}
P a g e | 81

avg = 0; for (i=0; i<10;


i++) avg = avg + sample[i];
printf (“\nThe average is: %d\n”, avg/10)
}

Two-dimensional arrays:
To declare two-dimensional integer array num of size int num[3][4];
Left Index determines row Right index determines column

Two dimensional arrays are stored in a row-column matrix where the first index indicates
the row and the second indicates the column. This means that the right most index changes
faster than the leftmost when accessing the elements in the array in the order in which they
are actually stored in memory

Example: main ()
{
int t, I, num [3][4]; for (t=0;
t<3; t++) for (i=0; i<4; ++i)
num [t][i] = (t * 4) + I + 1; for
(t=0; t<3; t++)
{
for (i=0; i<4; ++i) printf
(“%3d”, num[t][i]); printf
(“\n”);
}
}

Q. storing element in a matrix and printing it.


P a g e | 82

#include <stdio.h>
void main ()
{ int arr[3][3],i,j;
for (i=0;i<3;i++)
{ for
(j=0;j<3;j++)
{
printf("Enter a[%d][%d]: ",i,j); scanf("%d",&arr[i][j]);

}
}
printf("\n printing the elements ....\n"); for(i=0;i<3;i++)
{ printf("\n");
for (j=0;j<3;j++)

{ printf("%d\t",arr[i][j]);

}
}
}
P a g e | 83
P a g e | 84
P a g e | 85
P a g e | 86

STRUCTURE
A structure is a user defined data type. using a structure we have the ability to
define a new type of data considerably more complex than the types we have been
using.
A structure is a collection of variables referenced under one name providing a
convenient means of keeping related information together. The variables which
make up a structure are called structure elements.
P a g e | 87

struct addr
{
char street[40];
int postalcode;
}

For example:
#include<stdio.h>
#include<string.h>

struct Student
{
char name[25];
int age; char branch[10];
char gender;
};

int main()
{
struct Student s1;
s1.age = 19;
strcpy(s1.name, "neha");

printf("Name of Student 1: %s\n", s1.name);


printf("Age of Student 1: %d\n", s1.age);
P a g e | 88
P a g e | 89

UNIONS
WITH UNION DIFFERENT TYPES OF VALUES CAN BE STORED AT
SAME LOCATION IN DIFFERENT TIMES.SP0ACE IS ALLOCATED TO
ACCOMMODATE THE LARGEST MEMBER DATA TYPE.THEY ARE
SYNTACTICALLY IDENTICAL TO STRUCTURES.

SYNTAX:

union union-tag-optional
{
member-declarations
}union-name- optional Union
name.member ptr-to-union -> member

FOR EXAMPLE:

#include <stdio.h> union

unionJob

{
P a g e | 90

char name[32];

float salary; int

workerNo;

} uJob;

struct structJob

char name[32];
P a g e | 91

float salary;
P a g e | 92
P a g e | 93

C Macros
A macro is a segment of code which is replaced by the value of macro.
Macro is defined by #define directive.
There are two types of macros:
1) Object-like Macros
2) Function-like Macros

1. Object-like Macros

The object-like macro is an identifier that is replaced by value. It is


widely used to represent numeric constants. For example:
#define PI 3.14
Here, PI is the macro name which will be replaced by the value 3.14.
2. Function-like Macros

The function-like macro looks like function call.


For example:
#define MIN(a,b) ((a)<(b)?(a):(b))
Here, MIN is the macro name.
P a g e | 94
P a g e | 95
P a g e | 96
P a g e | 97

LINUX
Linux is the best known and most used open source operating
system. As an operating system
Linux is software that sits underneath all the other software on
a computer, receiving request from those programs and relaying
these request to the computer hardware.
P a g e | 98
P a g e | 99
P a g e | 100

Advantages of Linux
The main advantage of Linux, is it is an open-source operating
system, means the source code is easily available for everyone .
In terms of security, Linux is more secure than any other operating
system. The software updates in Linux are easy and frequent.
Linux is freely available to use on the internet.
It has large community support.
It provides high stability. It rarely slows down or freezes and there is
no need to reboot it after a short time.
It maintain the privacy of the user.
It is network friendly.
P a g e | 101

It is fast and easy to install from the web. It can also install in any
hardware even in your old computer system.
It performs all tasks properly even if it has limited space on the hard
disk.

Disadvantages of Linux
It is not much user-friendly. So, it may be confusing for beginners.
It has small peripheral hardware drivers as compared to windows.

BASIC COMMANDS IN LINUX WITH USES

Directory navigation
Command Utility
pwd- Get the full path of the current working directory.

Cd - Navigate to the last directory you were working in.


cd - or just cd Navigate to the current user's home directory.
cd .. -Go to the parent directory of current directory (mind the space between
cd and ..)

Listing files inside a directory


P a g e | 102

Command Utility
ls -l List the files and directories in the current directory in long (table) format (It is
recommended to use -l with ls for better readability).

ls -ld dir-name List information about the directory dir-name instead of its contents.

ls -a List all the files including the hidden ones (File names starting with a . are
hidden files in Linux).

File/directory create, copy and remove


Command Utility
cp -p -Will copy the file from source to destination. -p stands for preservation. It
preserves the original attributes of file while copying like file owner, timestamp,
group, permissions etc.

cp -R Will copy source directory to specified destination recursively.

mv - In Linux there is no rename command as such. Hence mv moves/renames the


file1 to file2.

rm -Will remove the directory dir-name recursively.


P a g e | 103

rm -rf - Will remove the directory dir recursively, ignoring nonexistent files and
will never prompt for anything.
rmdir - Will remove the directory dir-name, if it's empty. This command can only
remove empty directories.
mkdir - Create a directory dir-name.

touch - a file filename, if it doesn't exist, otherwise change the timestamp of the file
to current time.

chmod - Change the file permissions. Specifications = u user, g group, o other, +


add permission, - remove, r read, w write,x execute.

chmod -R Change the permissions of a directory recursively. To change


permission of a directory and everything within that directory, use this command.

chown - Change ownership of a file to user owner1.


P a g e | 104
P a g e | 105
P a g e | 106
P a g e | 107
P a g e | 108
P a g e | 109
P a g e | 110
P a g e | 111
P a g e | 112
P a g e | 113
P a g e | 114
P a g e | 115
P a g e | 116
P a g e | 117
P a g e | 118
P a g e | 119
P a g e | 120
P a g e | 121
P a g e | 122
P a g e | 123
P a g e | 124
P a g e | 125
P a g e | 126
P a g e | 127
P a g e | 128
P a g e | 129
P a g e | 130
P a g e | 131
P a g e | 132
P a g e | 133
P a g e | 134
P a g e | 135
P a g e | 136
P a g e | 137
P a g e | 138
P a g e | 139
P a g e | 140
P a g e | 141
P a g e | 142
P a g e | 143

You might also like