What we learned in our previous lab >> Text Processing Editor:
nano, and vim
>> How to create file in nano text editor
>> How to create multiple directories with >> How to create file in vim text editor
single command >> How to install new package / software in Linux
For Example: mkdir –p /1/2/{3,4} For Example: yum install packagename
>> How to create multiple empty files with >> How to remove package / software in Linux
single command For Example: yum remove packagename
For Example01: touch file1.txt file2.txt
For Example02: touch /1/2/3/{f1.txt,f2.txt}
>> How to read file content
For Example: cat filename
>> How to write data in file with the help
single redirector sign (>)
For Example: cat > filename
>> How to append data in file with the help of
double redirector signs (>>)
>> echo command
For Example01: echo “Text”
For Example02: echo “Text” > filename
• Introduction to Vim Text Editor
• Vim (Vi IMproved) is a powerful text editor used in Unix-based systems, enhancing the original Vi editor with features like syntax
highlighting, multi-level undo, and plugin support. Vim is known for its efficiency and customization, making it a favorite among
developers and system administrators.
• Modes in Vim
Week 07:
• Vim operates in different modes:
VIM Text Processing Tools in Linux
• Normal Mode: Default mode for navigation and text manipulation.
• Insert Mode: Used for inserting or modifying text (i, a, o).
• Visual Mode: Enables text selection (v, V, Ctrl + V).
• Command Mode: Executes commands like saving and searching (:).
• Basic Vim Commands
• vim filename – Open or create a file.
• i – Enter Insert mode.
• Esc – Return to Normal mode.
• :w – Save the file.
• :q – Quit Vim.
• :wq – Save and quit.
• :q! – Quit without saving.
• dd – Delete a line.
• yy – Copy a line.
• p – Paste text.
• /word – Search for a word.
• u – Undo last change.
Week 07 :
Installing C Language in Linux
This package is called gcc (GNU Compiler Collection)
Week 07:
Installing C Language in Linux
RUN the following command to install C language in Linux
# yum install gcc
Verify the C language installation:
# gcc –-version
Or
# gcc –v
Week 07:
Task: Write simple C language in vi text editor, compile and run it
>>> Compile Syntax I
# gcc <filename.c>
>>> RUN C language Program
# ./a.out
>>> Compile Syntax II
# gcc <filename.c> -o <outputfilename>
./outputfilename
Week 07:
System Call: is a mechanism where an OS interacts with kernel for getting resources
from hardware
User program-> (System Call : write(), read()) → OS Services (I/O, PE) → HW
OR
1. OS --> User Mode -- > Here an OS sends request and makes a system call
2. OS → Kernel Mode → Here an OS receives request and makes a system call to
execute
Week 07:
System Call: write()
write() system call is used to write to a file descriptor. In other words write() can
be used to write to any file.
Syntax:
#include<unistd.h>
write(int fd, String, size);
fd: File Descriptors are pre-defined numbers (0:stdin, 1:stdout, & 2:stderr)
Syntax:
#include<unistd.h>
write(int fd, String, size);
Week 07:
System Call: write()
#include<unistd.h>
int main()
{
write(1,"hello",5); //1 is the file descriptor,
}
Week 07:
System Call: read()
The use of read() system call is to read from a file descriptor. The working is
same as write(), the only difference is read() will read the data from file pointed
to by file descriptor.
Syntax:
#include<unistd.h>
ssize_t read(int fd, const void *buf, size_t count);
Week 07:
System Call: read()
The use of read() system call is to read from a file descriptor. The working is same as write(), the only
difference is read() will read the data from file pointed to by file descriptor.
Syntax:
#include<unistd.h>
ssize_t read(int fd, string, size_t count);
#include<unistd.h>
int main()
{
char b[10];
read(0,b,7);
write(1,b,7);
}