Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, 8 March 2012

How can you check if your Linux machine on network has static or dynamically allocated IP? How can you change it from dynamic to static?


How can you check if your Linux machine on network has static or dynamically allocated IP?
How can you change it from dynamic to static?
Ans:

Network configuration file can be looked at for checking if Linux machine has static or dynamically
allocated IP. ifconfig can be used to check currently allocated IP.
In Ubuntu the configuration file is /etc/network/interfaces. For dynamically allocated IP, it should state
dhcp, e.g following entry:
iface eth0 inet dhcp
In order to change it to static IP allocation, dhcp should be changed to static and IP address, subnet
mask, network address, broadcast address and gateway need to be mentioned. E.g. :
iface eth0 inet static
address 10.1.10.54
netmask 255.255.255.0
network 10.1.10.0
broadcast 10.1.10.255
gateway 10.1.10.1
Networking service needs to be restarted after making this change.
sudo /etc/init.d/networking restart

Clear Screen & Display Today date and Time In linux


Modify your shell, such that every time you enter clear, it clears screen and on top of new
screen displays “Welcome username. You are using shel Today is date and time”. Where username
is the name of the user logged in,shel is the path to the shell you are using and date and time
is current date and time. 15 Marks


In order to display “Welcome username. You are using shell. Today is date_and_time” following
command can be used:
echo Welcome $USER. You are using $SHELL. Today is $(date)
In order to modify shell, such that every time clear is entered, this command is executed AFTER clearing
the shell, an alias can be defined as follows:
alias clear=”clear; echo Welcome $USER. You are using $SHELL. Today is $(date)”

What is difference between su and sudo? su be used instead of sudo for root privilege?


What is difference between su and sudo? How can su be used instead of sudo for getting access
to root privilege?

Ans:

su is used for logging in as any other user, including root user. After entering user password, you can
enter commands as that user unless u enter exit. In order to log in as root, just enter su and in order to
enter as a different user enter suusername. su can be used for single command as:
su user_name –c command
sudo is used for gaining root privilege for a specific command. Adding sudo at the start of a command
implies that root privilege is used for that command. In order to use sudo, the current user has to be
added in sudoers file. sudo–i can be used for starting a shell as root user, but in that case password for
the current user is required, not that of root.
Thus, su can be used to log in as any other user while sudo is used to log in as root user. Moreover, sudo
will always ask for current user password and su will prompt for the password of the user you want to
log in as.

Write a (Perl or Bash) script which takes one or more filenames as arguments. If any of the files does not exist in the current directory display prompt. For each file, remove all the comments lines in the file.


Write a (Perl or Bash) script which takes one or more filenames as arguments. If any of the files
does not exist in the current directory display prompt. For each file, remove all the comments
lines in the file.


#!/bin/bash
if [ $# -eq 0 ] #If no file is given as argument
then
echo 'Please provide name of file as argument' #Display message
else #If arguments are given
for file #For each argument
do
if [ ! -f $file ] #If file does not exist
then
echo "File $file does not exist" #Display message
else #If file exist
echo "Original contents of file $file are:" #Display message
cat $file #Display original file contents
sed -e '/^#[^!]/d' $file > temp #sed used to remove lines which start with #,
except those starting with #!. Result saved in file temp
echo "File contents after removing comments are:" #Display message
cat temp > $file #Output is written back on the file
cat $file #Display updated file
fi
done
fi

Read file in linux, check if the group exists,Check if the user exists,Add the group if it does not exists


You have a file named users. Each line in the file contains two words (space separated): a user
name and a group name. Write a (Perl or Bash) script to: 25 Marks
a. read one by one each line in the file
b. check if the group exists, add the group if it does not exists
c. check if the user exists, check the user belongs to the same group, if not change the
group. Add user to the group if user does not exists
d. Set the password of the user same as the username.
e. On each step, display appropriate prompts (e.g., user added, user already exists etc.)


Script:
#!/bin/bash
while read user group #Reading user and group from the file
do
echo CHECKING FOR USER $user and GROUP $group #Display message before checking for
each user or group
tmp_u=$(grep -w ^$user /etc/passwd) #Check if user exists.
tmp_g=$(grep -w ^$group /etc/group) #Check if group exists
pass=$(mkpasswd $user)
if [ -z $tmp_g ] #If group does not exist
then
echo Group $group does not exist, it is being added #Display message
sudo groupadd $group #Adding group
else #If Group exists
echo Group $group exists #Display message
fi
if [ -z $tmp_u ] #If user does not exists
then
echo User $user does not exist, it is being added #Display message
sudo useradd -g $group $user #Adding user to the group
else #If user exists
echo User $user exists #Display message
org_grp=$(id -gn $user) #Extract group of the user
if [ $group == $org_grp ] #If user's current group is same as desired
group
then
echo User $user already belongs to group $group #Display message
else
echo User $user belongs to $org_grp and being changed to $group
#Display message
sudo usermod -g $group $user #Change the user group
fi
fi
sudo usermod -p $pass $user #Changing password to the user name
echo "Password for $user changed to $user" #Display message
echo '**********************************************************'
done < user #Input file (user) for the while loop
Contents of file user are:
omer omer
check grp
ent nust
cse seecs

Saturday, 18 February 2012

Red Hat Enterprise Virtualization 3.0


WHY OUR CUSTOMERS LOVE RHEV

Saturday, 21 January 2012

Linux Commands, Emacs killed data recover Buffer,rm * command deletes all files


1. Write command to display following text in a shell prompt. Explain your command.

Hi $2, I’m number * (guess)! 20 Marks


The text to be displayed contains special characters, which are generally used in a shell to

perform specific functions. In this case it is required that shell interpret them as characters and

thus it is required that these characters be “escaped”, i.e., preventing shell to try executing

them. Special characters can be escaped by two ways:

i) By placing \ before the special character. In this case we can give the following

command to generate the desired output:

echoHi\$2,I\’m number\*\(gues\)\!

ii) By placing the statement within single quotes, since single quotes can escape any

enclosed character. However, single quotes can not escape itself. Since one single quote

is present in the desired statement, the whole statement can not just be enclosed in

single quotes. Therefore, we can enclose single quote in double quote or escape it using

\.

echo‘Hi$2,I’\’m number*(gues)!’ {Between I and m, first there is

a single quote to close single quote started before Hi, then \ to escape next

single quote and then an opening single quote which is closed after !}

echo‘Hi$2,I’”’”’m number*(gues)!’ {Between I and m, first there is

a single quote to close single quote started before Hi, then a opening double

quote which enclose a single quote and then a closing double quote. Then there

is an opening single quote which is closed after !}

2. In emacs, killed data is stored in a buffer and yanking is used to recover this data when required.
What is this buffer called? How can we look at all the contents of this buffer? How can we
empty this buffer? 15 Marks


The buffer is called kill-ring.

The contents of buffer can be seen by writing kill-ring in a new line in the editor and while cursor

at its right end, press C-x C-e. C-x C-e evaluates LISt Processing (LISP) expression from start of

the line to the current cursor position. The echo area displays the output of the expression.

Evaluating a buffer name in LISP outputs its contents. Hence, in this case evaluating kill-ring

displays its contents in the echo area. M-: is also used to evaluate LISP expression, which means

M-: kill-ring can be used to list its contents. Contents can also be displayed by C-h v kill-ring.

Contents of this buffer can be cleared by writing appropriate expression in LISP and evaluating

it. Expression to clear kill ring is (set ‘kill-ring ‘nil) OR (setq kill-ring ‘nil). Hence, write either one

of them in the editor and while cursor at its right end, press C-x C-e. Kill-ring can also be cleared

by M-: (set ‘kill-ring ‘nil) OR M-: (setq kill-ring ‘nil).

3. Use touch command to create a new file named –i. How different this command is from usual usage of touch to create files? How can you remove the file named –i? 15 Marks

touch command is used to create new blank files or “touch” existing files, i.e., just updating

modification time without modifying file contents. Usual format for touch is:

touch

filename

However, in this case file name has a special character -. Shell expects character(s) implying

option(s) after -. -- can be added before –i filename, since -- implies end of options and shell

expects a filename after that. Thus, command to create file named –i is given as:

touch -- -i

Similarly, this file can be removed by:

rm -- -i

4.
rm *
command deletes all files in the current directory. Does it delete directories and hidden files? If not, what changes in the command are required to delete all contents of working
directory including directories and hidden files. What happens if there are write protected files in the directory? How can we make sure that we delete all write protected files as well, without being asked for confirmation? 20 Marks


rm * does not delete directories and hidden files. In order to delete directories –r option is used

and in order to delete hidden files .* is required in addition to *. Hence command to delete all

directories, files and hidden files is:

rm –r * .*

However, this will also try deleting . and .. entries in the directory. Since, these two can not be

deleted, shell will give error messages that they can not be deleted. Nevertheless, all other files

and directories will be deleted. In order to avoid getting these error messages, following

command can be used:

rm –r .[^.]* *

This will delete everything except . and .. entries. In case there are write protected files, shell

will ask for confirmation for each file before deleting it. In order to avoid getting this

confirmation, -f option can be used which force shell to delete write protected files without

asking for confirmation.

Including –f option, the rm command can be given as:

rm –rf .[^.]* *

5. Explain output of following commands:

echo ‘testing’ > test

grep t test > test

cat test 15 Marks


testing is saved in the file named test. grep command redirects its output to test file as well.

When output redirection is used, a file is created or overwritten before evaluating the

command. Thus, in this case first a test file is overwritten and then t is searched in its contents.

Since, it is now an empty file grep can not find t in it and hence test remains an empty file. Last

command confirms that test is empty by giving no output.

6. Explain the output of following command:

wc –m *|sort –nr|head -2|tail -1

What will be the difference if we use –r instead of –nr. 15 Marks


Multiple pipes are used in the command. First one wc –m * lists character count for each file

and total number of characters in all the files present in the working directory. sort –nr reverse

numerically sorts them, so that total number of characters in all files come at the top as total

has to be higher than any individual entry. The second line would be the file containing highest

number of characters. The combination of head and tail displays the second line, i.e., the file

containing highest number of characters.

Linux Bash Scripting ,Bash Scrip examples


Lab13: Bash Scripting
Lab Tasks:
1. Write a bash script to find out the biggest number from given three numbers. The numbers are supplied as command line argument to the script. Print an error message if sufficient arguments are not supplied.

#!/bin/bash
if(($#!=3));
then
    echo ERROR: Please specify exactly three number as argument;
    exit 1;
else
{
    if [ $1 -gt $2 ]; then
    if [ $2 -gt $3 ]; then
    echo $1 is biggest;
    elif [ $1 -gt $3 ]; then
    echo $1 is biggest;
else
echo $3 is biggest;
fi
else
    if [ $2 -gt $3 ]; then
    echo $2 is biggest;
    else
    echo $3 is biggest;
fi
fi
}
fi


2. Write a bash script to find out the volume of a pizza. Both the radius and height of the pizza should be input by the user and can be real numbers i.e numbers like 3.14259 (Hint: Use read and bc utilities).

#! /bin/bash
echo "Please Enter Height of Pizza"
read height
echo "Please Enter Radius of Pizza"
read radius
result=$(echo 3.14259*$radius*$radius*$height | bc)
echo "Volume of Pizza is =$result"


3. Write a bash script that calculates the factorial of a number given as the argument, using a while or until loop.

#! /bin/bash

if [ $# -ne 1 ]; then
echo 'Only one argument is required'
else
num=$1
fac=1
while [ $num -gt 1 ]
 do
 fac=$(( $fac*$num ))
 num=$(( $num - 1 ))
 done
echo "Factorial is $fac"
fi

4. Write a bash script that checks if the apache and cron daemons are running on your system. If apache/cron is running, the script should print a message like, "Apache/Cron is Alive!!!" (Hint: Use ps to check on processes).
SERVICE='cron'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
   echo "Cron is Alive!!!!!!!!!"
else
   echo "$SERVICE is not running"
fi
apachee='apache'

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
   echo "Apache is Alive!!!!!!!!!"
else
   echo "$SERVICE is not running"
fi



Bonus: Write a script that calculates the factorial of a number given as the argument, using a recursive function.



#!/bin/bash
factorial()
{
 if [ $# -ne 1 ];then
 echo "Error: Only one argument is required "
 exit 1
 fi
 local i=$1
 local f
 declare -i i
 declare -i f
 [ $i -le 2 ] && echo $i || { f=$(( i - 1 ));f=$(factorial $f);f=$(( f * i ));echo $f;}
}
factorial $1

Linux Software Installation,Runlevels,XPenguins 2.2,powertop version 1.1 on your Linux System


Lab12: Software Installation

Lab Tasks:


1. Runlevels

· Make Runlevel 3 your default Runlevel

If you have an /etc/inittab file, edit it. Locate the following line:

id:2:initdefault:

Change the number after the first colon to the runlevel you want to be the default.


However, most people won't have that file, in which case you should edit /etc/init/rc-sysinit.conf instead and change the following line:

env DEFAULT_RUNLEVEL=2



· Initiate the single user Runlevel from GRUB console and try to change the root password

Choose the "(recovery mode)" option from GRUB; add "-s", "S" or "single" to the kernel command-line; or from a running machine, run "telinit 1" or "shutdown now".

2. Software Installation



· Install XPenguins 2.2 on your Linux System from its RPM
Rpm -I xpenguins-2.2.rpm //alien is used for rpm packages + install rmp if not installed

xpenguins

· Install powertop version 1.1 on your Linux System from its source code
tar -zxvf powertop-1.1.tar.gz //v for gz

cd powertop-1.1

make

make install

powertop

Linux Job Scheduling Ubuntu

· Create a file test_at in your ~

o Touch test_at;

· Schedule a job that will mv this file to the /tmp directory five minutes from now and append the current date and time in it

o At now+5minutes

o At> Cat date≫~/test_at;

o At> Mv ~/test_at /tmp

o At> CTRL+D

· Create a compressed backup of your home directory on a local /backup directory, which will run at 10 am

o at 10:00am

o at> tar -Cvzf ~/baCkup/home.tar /home/nasir/

· Schedule a job as a normal user that will append the output of the uptime command to a uptime.log file in your home directory every 2 minutes on weekdays but only in the month of July

o */2 * * 6 Mon-Fri uptime >> $HOME/uptime.log

· Schedule a job as a normal user that will run a bash script called report.sh in your home directory every day exactly 23 minutes after every even hour
o 23 0/2 * * * $HOME/report.sh

Process Management,background process,kill process ,current memory usage


Lab10: Process Management
Lab Tasks:

Processes and Services:

· Start a background process, bring that process to foreground and kill that process using PID

xeyes &; // run xeyes in backgroud

fg 1; //make it in foreground

kill %1; // kill process with job id 1 i.e. xeyes

· List all the current running process owned by the current user in user oriented format

ps u U $USER // u option display in user oriented form, U selects the user and $USER is username

· List all the processes only which are in sleep mode and tell the command used for that process

ps u r -N // ‘u r’ find all running process and -N negated the result

· List only the running processes in tree mode

ps f u r // ‘f’ displays in tree mode and ‘u r’ in running process

· Reduce the running time of a running process to 5

nice -n -5 xeyes; // reduce running time of xeyes by 5

· Start xinetd service and stop that service

/etc/init.d/xinetd start; /etc/init.d/xinetd status; /etc/init.d/xinetd stop; // You can check the command also by starting and stoping ssh service.

· Figure out the current memory usage and CPU usage

Top // displays all the information about cpu, memory and processes.

Monitoring Linux


Monitoring a Linux System
·       Search the boot log to see all the section where the network interface has been mentioned
dmesg | grep eth0                  
dmesg | grep network | grep interface
·       Find out what is the cache size of your PC’s processor
vmstat     (or hwinfo)   
·       Find out the IRQ number associated with the interrupts generated by your Ethernet card
dmesg | grep irq
·       Find out the PCI Bus IDs of the USB Controllers on your PC
lspci
·       Start the ssh service on your PC and establish a local connection to it by using ssh username@localhost
o   Use netstat to find out the process ids of all TCP connections established on your machine
sudo apt-get install ssh;
sudo /etc/init.d/ssh start   or sudo service ssh start;
netstat
·       Which version of Linux kernel is currently installed on your system?
uname -mrs (-a all)
·       Show the duration of last 5 logins at your system
last -5

RAID volume group and logical volumes,Software RAID based VG,Linux RAID


1.    Create the volume group and logical volumes
·        Create a primary partition of 100 MB using fdisk and choose its mount point as /boot
·        Create 3 logical partitions of sizes 2, 4 and 6 GB and for the File system ID select Linux LVM (Do not format or create a file system on these partitions)
·        Commit these changes and reboot (or use partprobe)
·        Select LVM in the YaST Expert Partitioner
·        Create a VG named systemVG
o   Physical Extent Size: The physical extent size defines the smallest unit of a logical volume group
·        Add the 3 PVs to your systemVG volume group
·        Create 4 LVs in your systemVG volume group with following characteristics:-
·        2 GB LV called root mounted at / formatted with ReiserFS
·        1 GB LV called home mounted at /home formatted with ext2
·        3 GB LV called linuxStuff mounted at /usr formatted with xfs
·        2 GB LV called virtualMem formatted as swap
Try resizing the home LV and see what happens
2.    Create a Software RAID based VG
·        Create two partitions of exact same size (10 GB each) and for the File system ID select Linux RAID Auto
·        Use the YaST RAID Wizard to set them up as RAID 0 (Stripping mode)
·        Create a VG called fastVG and add this RAID PV to it
·        Create a LV on it formatted with JFS and mounted on /moodle

Wednesday, 11 January 2012

User & Group Management in Linux


User and Group Management
·        See the /etc/passwd and /etc/shadow files
These files contain the information about the user login and password and other variables.
·        Make a new user “tux” with default home directory and password “pakistan
sudo useradd -p pakistan tux
·        See the changes in /etc/passwd and /etc/shadow
Both of the files contain last row as tux user.
tux:x:1001:1002::/home/tux:/bin/sh
tux:pakistan:15249:0:99999:7:::
·        Create a group “BIT10” with group ID 99 and change tux’s group to “BIT10"
sudo groupadd -gid 99 BIT10A
sudo gpasswd -a tux BIT10A;    sudo usermod -g BIT10A tux
·        Move the user’s current home directory to the new directory “/studentHome”
sudo usermod -d /sohaibHome tux

·        Change this user’s password to “d!g!t@l” with following settings:-
Lock the account if it has been inactive for 5 days
Minimum 2 days must be past before the user can change hi/her/its password
sudo usermod -p 'd!g!@|' –f 5 tux;
chage –i 5 –m 2 tux;
·        See the changes in /etc/passwd and /etc/shadow and /etc/group files
Both show changes for tux
·        Delete the group “BIT10” and delete the account of “tux”
groupdel BIT10A

Sunday, 8 January 2012

Linux Partitions of Disk, fdisk for Partitions in Linux, Ubuntu partitions


1.     Manage Partitions with fdisk
·        Use fdisk to create a new partition table
o   1st primary partition (100 MB)
o   2nd primary partition (1 GB)
o   3rd primary partition (4 GB)
·        Commit these changes
·        Reboot and install Linux on the new partition table, mounting them as:-
·        1st primary partition as /boot (reiserfs)
·        3rd primary partition as / (ext3)
sudo fdisk /dev/sda
delete all partitions 1 ,2 using d then press w to write changes
Press n to create a new partition and press p for primary then 1 for partition 1 and then press enter for default starting cylinders then +100M as required for partition 1.
Press n to create a new partition and press p for primary then 2 for partition 2 and then press enter for default starting cylinders then +1G as required for partition 2.
Press n to create a new partition and press p for primary then 3 for partition 3 and then press enter for default starting cylinders then +4G as required for partition 3.
press w for write changes
mount /dev/sda1 /boot; mount /dev/sda3 /;
reboot and install new linux and use the existing file system. And make changes in sda1 as file system reiserfs and mount point /boot; sd2 as file system ext3 and mount point /
then install ubnuntu; this will load new file systems and partition table.

2.     Create Partitions with fdisk
·        Using fdisk, create a new extended partition with all the remaining space in the HDD
·        Create a new logical partitions:-
o   1st logical partition (100 MB)
o   2nd logical partition (1 GB)
·        Commit these changes
·        Load the new partition table into the kernel by using partprobe utility
fdisk /dev/sda
type n for new partition; select e for extended partition and it will create new extended partition on rest of the space.
type n for new logical partition. it will make logical partition sd5 in sda4 extended partition. press enter for default starting cylinder and +100M for 100MB partition.
type n for new logical partition. it will make logical partition sda6 in sda4 extended partition. press enter for default starting cylinder and enter for allocating rest of space for this partition.
press w for commit changes
load partition table using sudo partprobe /dev/sda

3.     Create File Systems
·        From the command line, format the new partitions as:-
o   1st logical partition as reiserfs
o   2nd logical partition as ext2
·        From the command line, mount the new partitions as:-
·        1st logical partition as /moodle
·         2nd logical partition as /moodledata
mkfs –t reiserfs /dev/sda5 ; mkfs –t ext2 /dev/sda6
sudo mkdir /moodle; sudo mkdir /moodledata;
mount /dev/sda5 /moodle; mount /dev/sda6 /moodledata;

Linux Emacs editor, emacs commands examples



·        emacs
·        Given a buffer full of English text, answer the following questions:
a.     How would you change every instance of his to hers?
press M-x . Then enter:
hers  RET his RET hers

M-x replace-string
            his 
            hers


b.     How would you make this change only in the final paragraph?

      Through “M-h” select paragraph then “M-x replace-string his  hers”


c.      Is there a way to look at every usage in context before changing it?

      ESC %

d.     d. How would you deal with the possibility that His might begin a sentence?


     Esc <

Friday, 6 January 2012

Linux Vim Editor, Vim editor commands



1. Vim 

· How can you cause vim to enter Input mode? How can you make vim revert to Command mode? 
Using “i” for input mode and “esc” for revert to command mode. 

1. To get into the input mode you press either ‘a’ or ‘i’ key. And to revert back to the command mode you press the ‘escape’ key

· What is the Work buffer? Name two ways of writing the contents of the Work buffer to the disk. 
The Work buffer is the area of memory where vim stores the text you are 

editing. A”:w” command writes the contents of the work buffer to disk but 
does not end your editing session. A ZZ command writes the contents of 
The work buffer to disk and ends your editing session. 

2. Vim stores the text being edited in the work buffer. 

:w command writes the contents of the work buffer to disk but does not end the editing. 

ZZ command writes the contents of the work buffer to disk and ends the editing. 

· While working in vim, with the cursor positioned on the first letter of a word, you give the command x followed by p. Explain what happens. 
The commands exchange the first two letters of the word. First the x 
command copies the character the cursor is on to the General-Purpose 
buffer and deletes the character, leaving the cursor on the character to the 
right of where the deleted character was. Then the p command inserts the 
contents of the General-Purpose buffer after the character the cursor is on. 

3. The position of the first two characters are swapped. X command deletes the first letter and places it on the buffer. The cursor is then moved to a new position and when the p command is given the letter from the buffer is removed and placed to a new position i.e after the first letter. 

· What are the differences between the following commands? 

a. i and I 
i=Insert before cursor. 

I=Insert to the start of the current line. 

i : insert cursor at the current position. 

I :insert cursor at the beginning of the line. 



b. a and A 

a=Append after cursor. 

A=Append to the end of the current line. 

a : append after cursor. 

A :append at the end of line. 

c. o and O 

o=Open a new line below and insert. 

O=Open a new line above and insert. 

o : Open a new line below and insert. 

O : Open a new line above and insert. 

d. r and R 
r=Overwrite one character. After overwriting the single character, go back to command mode. 

R=Enter insert mode but replace characters rather than inserting. 

r : Replace character 

R : Overwrite characters from cursor onward 



e. u and U 

u=Undo the last action. 

U=Undo all the latest changes that were made to the current line. 

u : Undo last change 

U : Undo all changes to entire line 

· Which command would you use to search backward through the Work buffer for lines that start with the word it? 
Give the command ?^itRETURN to search backward (?) for a line beginning 
with (^) it. 
5. ?^it 
· Which command substitutes all occurrences of the phrase this week with the phrase next week? 
:s/this week/next week/g 
6. :s/this week/next week 

· Consider the following scenario: You start vim to edit an existing file. You make many changes to the file and then realize that you deleted a critical section of the file early in your editing session. You want to get that section back but do not want to lose all the other changes you made. What would you do? 

This problem assumes that you have not written out the Work buffer since 
you deleted the critical section. There are a few ways to approach this 
problem. To be safe, make copies of the Work buffer and the original file 
under names other than the name of the original file. That way, if you 
make a mistake, you can easily start over. For example, give the command 
:wq changedfile to save the work buffer as changedfile, and exit from vim. 
Then use cp to copy the original file to, for example, file.orig and 
changedfile to changedfile.orig. Start vim with the following command, 
which instructs it to edit the original file first and the modified file second: 
$ vim originalfile changedfile 
Once you are editing the original file, search for and copy the part of the 
file you want to save into a Named buffer. For example, to save five lines, 
starting with the line the cursor is on, into the Named buffer a, give the 
command "a5yy. Then edit the modified file by giving the command 
:n!RETURN (edit the next file without writing out the Work buffer). Position 
the cursor where you want to insert the text, and give the command "ap or 
"aP, depending on where you want to place the copied text. 

How can you move the current line to the beginning of the file? 
We can move to the beginning of the file using “H” command. 
8. “H” command.

 
Free Host | lasik surgery new york