Professional Documents
Culture Documents
Linux Commands and C Programming
Linux Commands and C Programming
PIPE OPERATOR
FILE PERMISSIONS
MOVE
1D ARRAY
DO WHILE LOOP
$ ls -l | more
PIPE OPERATOR
The pipe operator (|) takes output from one command and uses it as input for another.
Syntax :
command_1 | command_2 | command_3 | ….. | command_n
Example :
1. Listing all files and directories and give it as input to more command.
$ ls –l | more
Output:
We can use use multiple pipe operator in single command
Example:
$ cat file3.txt | grep “yasin” | tee file4.txt | wc –l
We can also fetch the particular data types using pipe operator
Example:
$ cat file3.txt | grep h
FILE PERMISSIONS
There are 3 owners(owner, group, others) in the linux system have 3 types of file permissions.
They are,
1.Read(r): allows you to open and read the content of file. But can’t do any modifications in the
file.(Ex: cat, ls)
2.Write(w): allows you to modify the content of the file.(Ex: vi, touch)
3.Execute(x): allows you to execute the programs. We can’t execute a program unless execute
permission is set.
Permission:
We can set the permissions with chmod command.
Chmod <groupname> + <permissioname> <filename> ex: u+x jyothi.Txt
We can also use the octal permissions. For example, to set r octal will be 4, for w is 2 and for x is
1.
Ex: 675 : rw-rwxr-x
The default file permission for the file is 644(rw-r--r--) and for the directory is 755(rwxr-xr-x).
MV COMMAND
Mv stands for move.
It has two distinct functions:
I. It renames a file or folder.
II. It moves a group of files to a different directory.
Syntax:
Mv [option] source destination
Eg:- mv -i c.Txt b.Txt
ARRAY
Array :
an array is defined as the collection of similar type of data items stored at contiguous
memory locations.
Array in c are of two types;
Single dimensional arrays and
Multidimensional arrays.
1D ARRAY
One-dimensional arrays in C can be initialized statically (during compile-time) or dynamically
(during runtime). All the elements of an array are stored at contiguous memory locations.
The declaration must have a data type(int, float, char, double, etc.), Variable name, and subscript.
The subscript represents the size of the array. If the size is declared as 10, programmers can store
10 elements.
An array index always starts from 0. For example, if an array variable is declared as s[10], then it
ranges from 0 to 9.
Each array element is stored in a separate memory location.
DO WHILE LOOP
Definition :
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.
In case the condition is true, the control goes back to the beginning of the loop.
If the condition is false, the control breaks out of the loop.
Ex: #include <stdio.H> output: value of a: 5
Int main() { value of a: 6
Int a=5; value of a: 7
Do{ value of a: 8
Printf(“value of a:%d\n”,a); value of a: 9
A=a+1;
}
While(a<10);{
Return 0;
}