Operating System Practical (2)
Operating System Practical (2)
To Install
sudo apt-get install vim
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• Both of the editors work in three modes as described below:
• i) Command mode: This is the default mode. Various commands can be
executed in this mode to perform various tasks.
• ii) Insert mode: Text can be inserted in this mode. This mode can be activated
by pressing ‘i’ in command mode. ‘Esc’ key ends insert mode and returns to
the command mode.
• iii) Command line mode: This mode can be activated by pressing ‘:’ in
command mode. This puts the command line entry at the bottom of the
screen. Various commands can be executed in this mode to perform various
tasks.
These editors provide a rich set of various internal commands to work with it.
Some of the basic commands with description are given besides.
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• Vi shortcuts
• $ vi <filename> — Open or edit a file.
• i — Switch to Insert mode.
• Esc — Switch to Command mode.
• :w — Save and continue editing.
• :wq or ZZ — Save and quit/exit vi.
• :q! — Quit vi and do not save changes.
• yy — Yank (copy) a line of text.
• p — Paste a line of yanked text below the current line.
• o — Open a new line under the current line.
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• O — Open a new line above the current line.
• A — Append to the end of the line.
• a — Append after the cursor’s current position.
• I — Insert text at the beginning of the current line.
• b — Go to the beginning of the word.
• e — Go to the end of the word.
• x — Delete a single character.
• dd — Delete an entire line.
• Xdd — Delete X number of lines.
• Xyy — Yank X number of lines.
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• G — Go to the last line in a file.
• XG — Go to line X in a file.
• gg — Go to the first line in a file.
• :num — Display the current line’s line number.
• h — Move left one character.
• j — Move down one line.
• k — Move up one line.
• l — Move right one character.
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• gedit:- Gedit can be launched from the command line by simply
typing 'gedit' followed by any optional parameters. If 'Gedit' is not
installed on your system, you can typically install it using your
distribution's package manager.
• sudo apt-get install gedit
Gedit editor is the default editor for the GNOME desktop environment. When
we open a file, it will open with the Gedit editor. It provides straightforward
functionalities like any basic text editor. It is a lightweight editor with a straight
forward user interface. It was publicly released in the year 2000 with a GNOME
desktop environment. It is developed using the C programming language and
supports all font family.
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• GNOME (GNU Network Object Model Environment) is a graphical user
interface (GUI) and set of computer desktop applications for Linux
operating system (OS) users. It's intended to make a Linux OS easy to
use for nonprogrammers.
• Open an existing file
• gedit fimename.txt
• Create a new document
• gedit newfile.txt
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• GCC stands for GNU Compiler Collections which is used to compile
mainly C and C++ language. It can also be used to compile Objective C
and Objective C++. The most important option required while
compiling a source code file is the name of the source program, rest
every argument is optional like a warning, debugging, linking libraries,
object file etc. The different options of gcc command allow the user to
stop the compilation process at different stages.
• Syntax:- gcc [-c|-S|-E] [-std=standard]
• Ex:- gcc source.c
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• -o opt: This will compile the source.c file but instead of giving default
name hence executed using ./opt, it will give output file as opt. -o is
for output file option.
• Ex:- gcc source.c -o opt
• -Werror: This will compile the source and show the warning if any
error is there in the program, -W is for giving warnings.
• Ex:- gcc source.c -Werror -o opt
• -Wall: This will check not only for errors but also for all kinds warning
like unused variables errors, it is good practice to use this flag while
compiling the code.
• gcc source.c -Wall -o opt
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• -ggdb3: This command give us permissions to debug the program
using gdb which will be described later, -g option is for debugging.
• Ex:- gcc -ggdb3 source.c -Wall -o opt
• -lm : This command link math.h library to our source file, -l option is
used for linking particular library, for math.h we use -lm.
• Ex:- gcc -Wall source.c -o opt -lm
5. Test commands related with File
editing with Vi, Vim, gedit, gcc.
• -std=c11 :This command will use the c11 version of standards for
compiling the source.c program, which allows to define variable
under loop initializations also using newer standards version is
preferred.
• Ex:- gcc -Wall -std=c11 source.c -o opt
• -c : This command compile the program and give the object file as
output, which is used to make libraries.
• -v : This option is used for the verbose purpose.
6. Write a shell script to generate marksheet
of a student. Take 3 subjects, calculate and
display total marks, percentage and Class
obtained by the student.
read -p "Enter marks for Subject 1: " sub1
read -p "Enter marks for Subject 2: " sub2
read -p "Enter marks for Subject 3: " sub3
total=$((sub1 + sub2 + sub3))
percentage=$((total / 3))
6. Write a shell script to generate marksheet of a
student. Take 3 subjects, calculate and display
total marks, percentage and Class obtained by
the student.
if [ $percentage -ge 60 ]; then
class="First Class"
elif [ $percentage -ge 50 ]; then
class="Second Class"
elif [ $percentage -ge 40 ]; then
class="Pass Class"
else
class="Fail"
fi
6. Write a shell script to generate marksheet of a
student. Take 3 subjects, calculate and display
total marks, percentage and Class obtained by
the student.