Tuesday, December 1, 2015

Linux Basic Commands

How to change Shell in Linux?


  1. cat /etc/shells (In that file you will see all shell that support by OS)
  2. To change Shell "chsh -s /bin/shell name" "chsh -s /bin/tcsh"
  3. Change Shell for user "chsh -s /bin/shell name Username" "chsh -s /bin/tcsh jiten"
What is the command to check user group name , group ID , UID ?
id username
id jiten (This command will show you UID , GID , group name)

What is the command to check user account expiry date info?
chage -l username
chage -l jiten (This command will show you user related information)

User add command options?
what is the command to create user in different directory?
useradd -d /home/directory name/ username   username
useradd -d /home/sale/jiten jiten

what is the command to user with specific user ID?
useradd -u UID number user name
useradd -u 2222 jiten

what is the command to user with specific GID?
useradd -u UID number -g GID number username
useradd -u 3323 -g 400 jiten
or 
useradd -g 391 jiten

what is the command to add user in multiple group?
useradd -G group name username
useradd -G postfix,sale,market jiten
(To separate groups we use "," sign )

what is the command  to add user without HOME directory?
useradd -M username
useradd -M jiten

what is the command to add user with  account expiry date?
useradd -e yyyy-mm-dd username 
useradd -e 2013-06-01 jiten

what is the command to set user expiry date and days?
useradd -e 2013-06-01 -f 45 (days) username
useradd -e 2013-06-01 -f 45 jiten  (user command with expiry in 45 days)

what is the command to set comment on user ?
useradd -c "Hello I am sales team" user name
useradd -c "Hello I am sales team" jiten

what is the command to change user shell?
useradd -s /sbin/nologin username
useradd -s /sbin/nologin jiten

Add user with specific Home directory , Default shell and Custom comment?
useradd -m -d /home/sales/username -s /bin/bash -c "sales person" -U username
useradd -m -d /home/sales/jiten -s /bin/bash -c "sales person" -U jiten 

Add user with home directory, custom shell , custom comment and UID/GID?
useradd -m -d /home/sales/username -s /bin/bash -c "hello" -u 6000 -g 6000 username
useradd -m -d /home/sales/jiten -s /bin/bash -c "hello" -u 6000 -g 6000 jiten

Add user with home directory , no shell , custom comment and UID?
useradd -m -d /home/sales/username -s /sbin/nologin -c "how are you team" -u 1020 username
useradd -m -d /home/sales/jiten -s /sbin/nologin -c "How are you team" -u 1020 jiten

Add user with home directory, shell,custom skell/comment and user ID?
useradd -m -d /home/sales/username -k /etc/custom.skell -s /sbin/tcsh -c "sales member" -u 3021 username
useradd -m -d /home/sales/jiten -k /etc/custom.skell -s /sbin/tcsh -c "sales member" -u 3021 jiten

Add user without home directory, No shell  and no group ?
useradd -M -N -r -s /bin/false username
useradd -M -N -r -s /bin/false jiten

What is the usermod command and it use ?

we use usermod command to modify user details
what is the command to change user home directory ?
usermod -d newdirectory name  olddirectoryname
usermod -d /home/testnet jiten (This command will not copy the content of jiten user directory to testnet directory)

what is the command to change user home directory with it content?
usermod -d newdirectory name -m olddirectory name
usermod -d /home/testnet -m jiten (When you will run this command it will copy jiten directory content to testnet directory)

what is the command to add group in user?
usermod -G group name user name
usermod -G developer jiten

what is the command to add group with exist group?
usermod -aG groupname username
usermod -aG developer jiten

what is the command to change user primary group?
usermod -g groupname username
usermod -g developer jiten
id username 
id jiten

what is the command to lock user?
usermod -L username
usermod -L jiten

what is the command to unlocking user?
usermod -U username 
usermod -U jiten

what is the command to change expiry date of user account?
usermod -e yyyy-mm-dd username
usermod -e 2016-12-30 jiten

what is the command to change login name ?
usermod -l newname username
usermod -l jitenjha jiten

what is the command to change login password?
usermod -p newpassword username
usermod -p newpassword jiten

what is the command to change user shell?
usermod -s /bin/bash username
usermod -s /bin/bash jiten


Thursday, January 23, 2014

Squid Proxy with Mysql Auth

Configure Squid Proxy server :
1. Install Squid, start it, and set it to start on boot.
     $ su -
     # yum install squid
     # service squid start
     # chkconfig squid on
2.  Now install SquidGuard.
     # yum install squidGuard
3.  Now that SquidGuard is installed, open Firefox and go to the SquidGuard website: http://squidguard.org . The SquidGuard website has links to configuration documentation and websites to download blacklists. You need to download a blacklists file. You can go to http://dsi.utcapitole.fr/blacklists/  and get the link for the blacklists.tar.gz file, then you can use wget to download            blacklists.tar.gz, by copying and pasting the link, or you can download it through the Firefox web browser. Squidguard has its own blacklists.tar.gz file, and you will eventually want to replace it with the newer blacklists.tar.gz file that you downloaded. Before you do that, you can create a test blacklists file for SquidGuard to block. To do that you need to create a blacklists directory           in the /var/squidGuard/ directory. Now, in the                           new blacklists directory use vim create and edit a text                  file called testdomains.
     # cd /var/squidGuard# mkdir blacklists
     # cd blacklists
     # mkdir testdomains
    # cd testdomains 
    # vim testdomains
4. In this testdomains file you have write or add website name those you want to block.type in three lines of text to add some test-domains to block:
    yahoo.com
    msn.com
    whatever-you-want-to-block.com
    save and exit.
5. After create testdomains file Now you have to edit squid.conf file.
6. vim /etc/squid/squid.conf
7. If you have LDAP server so add this lines :
    ## LDAP AUTH
     auth_param basic program /usr/lib64/squid/squid_ldap_auth -b              "dc=ii,dc=ac,dc=in" -f "uid=%s" -h ldap.ii.ac.in
    acl ldapauth proxy_auth REQUIRED
    http_access allow ldapauth
   (/usr/lib64/squid/squid_ldap_auth) This line represent that all 

   squid commands in /usr/lib64/squid/ directory 
8. Make sure that you have to put right path so that command will execute .


9. Squid normally listens to port 3128
    http_port 8080
    Find line listens port 3128 .
   If you want to change port no. so you can change it.

10. url_rewrite_program /usr/bin/squidGuard -c /etc/squid/squidGuard.conf
     write this 2 lines in squid.conf file .
    /usr/bin/squidGuard is a command and /etc/squid/squidGuard.conf is the             squidGuard configuration file path.

      redirect_children 20

11. save and exit squid.conf file.

12. vim /etc/squid/squidGuard.conf
      When you open squidGuard.conf file .

13. dbhome /var/squidGuard/blacklists

14. remove blacklists and line look like.
      dbhome /var/squidGuard
      search and edit 
15. dest adult {
     

domainlist blacklists/testdomains/testdomains
urllist blacklists/terstdomains/testdomains
expressionlist blacklists/porn/expressions
}


16. Add :
     default {


pass !testdomains any
     # rewrite  dmz
redirect http://10.99.100.3/blocked.html


}
    here you will see redirect option if you want you can delete it or you can         put any website name , any html page that will so some message.

17. Authenticate from MySQL database
18. yum search mysql-server
19. /etc/init.d/mysqld restart

      If you face any problem to start it. vim /etc/my.cnf file and change              "datadir=/home/mysql" path or locate , file name.


20. mysql -u root -p 

21. create database squid; 
22. grant select on squid.* to dataproxy@localhost identified by 'dataproxy';
      If you want to can allow dataproxy user permission for check or edit squid         database.or you can use root user.



23. Create table 'passwd' in 'squid' db.
      CREATE TABLE `passwd` (      `user` varchar(32) NOT NULL default '',      `password` varchar(35) NOT NULL default        '',`enabled` tinyint(1) NOT NULL default '1',       `fullname` varchar(60) default NULL,      `comment` varchar(60) default NULL,       PRIMARY KEY (`user`) );

24. Populate the table with some test data, eg
      insert into passwd values('testuser','test',1,'Test User','for testing             purpose');
      In the insert line 'testuser' is a user name and 'test' password for access         internet.
      
25. Again Edit squid.conf file.
26. vim /etc/squid/squid.conf
      auth_param basic program
     /usr/lib64/squid/squid_db_auth --user dataproxy --password dataproxy --             plaintext --persist
     auth_param basic children 5
     auth_param basic realm Web-Proxy
     auth_param basic credentialsttl 1 minute
     auth_param basic casesensitive off
     acl db-auth proxy_auth REQUIRED
     
     http_access allow db-auth
     http_access allow localhost
     http_access deny all
     
27.save and exit file.


28. Now compile the SquidGuard blacklists and chown the blacklists to be                accessible by Squid.

      squidGuard -b -d -C all 
       chown -R squid /var/squidGuard/blacklists 
29. restart squid service 
       /etc/init.d/squid restart
30. At last open terminal 

      Run this command for testing 


    /usr/lib64/squid/squid_db_auth --user dataproxy --password dataproxy --              plaintext --persist        --- Press Enter



   After Press Enter you have to put username and password there like we have          created testuser test



     username and password both in same line with one space. you will see ok it          mean it is working fine.or any error so send me or you can google it.



32. OPEN your browser firefox , internet explore , chrome,

33. Proxy setting option 
34. Manual Proxy setting 

35. put there your squid server ip address or domain name if it is and port no          that you allow or open it.

Best of Luck

Friday, March 9, 2012

PostgreSQL

POSTGRESQL

aptitude search postgresql

You have to install server type & latest version of SQL server.

Run postgresql command

apt-get install postgresql name ( package name with version )
                       or
aptitude install package name

After that we check postgresql is working or not
"psql : FATAL: role "root" does not exits

# psql postgres

# su - postgres

# pwd to check path of file.
    /var/lib/postgresql

#postgres@common-...:~$ su - postgres
#createuser -U postgres -P

Connect to database or access any database

#psql postgres ( database name )
postgres =>  [ postgres is bydefault database create when we install postgresql ]

To see database "\l"
To quit to database "\q"
Create database in postgresql
#createdb data1 ( database name ) ---> This command run in user mode.

postgres => CREATE DATABASE data1;
postgres => \l
Stop any process in sql ";"

Connect to other database
psqlgres => \c [ database name ] data1

Alt + F1 : open application menu
Alt + F2 : Display run application dialog
print screen : Take a screen shot of the entire desktop
Alt + print screen : Take a screen shot of the current open windows 
Ctrl + Alt + Arrow : switch to the work space to the specified direction of
                                 the current workspace.
Ctrl + Alt + D :  Minimize all windows & give focus to the desktop
Alt + tab : Switch between windows. A list of windows that you can select is display id. Release the keys to select a windows. You can press the "shift" key to cycle through the windows in reverse order.
Ctrl + Alt + Tab : Switch the focus between the panels and the desktop. A list of                              items that you can select it display. Release the keys to select
                             on item. you can press the "shift" key to cycle through
                             the  items in reverse order.

Wednesday, March 7, 2012

PS command

ps command 

use for check which process is run or not.

#ps -ef ---> show you all process running on computer
# ps -ef | grep -i process name ----> grep any process you want to check or kill.

If you want to set any value to any file then we run .

echo [ 1 or 0 ] > /proc/sys/net/ipv4/ip_forward

echo is command
1 or 0 is value
/proc/sys/net/ipv4/ip_forward --> file path

APT ( Advanced Packaging Tool )

APT ( Advanced Packaging Tool )

apt-get   -------> APT package handling tool
apt-get install (package name) ----------> To install any software and package


apt-get install firefox


apt-get autoremove package name
apt-get remove package name --------------> To remove package

* aptitude :-> high-level interface to the package manager This command use
                      for.

                    install any software or find any software.

aptitude search ( package name ) ----> search any package
aptitude install ( package name )  -----> To install any package
aptitude remove ( package name ) ----> To remove any package


If you want to install any binary package like java in a binary formate then give package execute permission. After that [ ./java ] is command.
./java

Check java install or not :

dpkg -query -l | grep java

This command show you that the java install or not check java package install or not.

env : run a program in a modified environment
         This command run for to check environment or path is correct or not.

export JAVA_HOME = /opt/java
export = command
JAVA_HOME = variable
/opt/java = file location

export JAVA_HOME = /opt/java
export ANT_HOME = /opt/ant  ----> [ ANT is a compiler ]
echo $ JAVA_HOME
echo $ANT_HOME -----> To check variable export or not.

vim /etc/profile ----> insert line

export JAVA_HOME = /opt/java
export ANT_HOME = /opt/ant
export PATH = $PATH:${JAVA_HOME}/bin:${ANT_HOME}/bin ---> restart pc

But if you don't want to reboot pc then run
   [ source /etc/profile ]  -----> command use for execute variable .





 

Tuesday, March 6, 2012

Proc File System

Understanding the Proc File System

  • The Linux kernel provides a mechanism to access its underlying internal data-structure and also to change its kernel setting at run-time through /proc file system. We will be discussing the /proc file system here targeted to the Intel x86 architecture; though the basic concepts will remain the same for linux on any plarform.

/proc - a Virtual File System:

The /proc file system is a mechanism that is used for the kernel and kernel modules to send information to processes ( hence the name /proc ). This pseudo file system allows you to interact with the internal data-structure of the kernel,bet useful information about the processes, and to change settings ( by modifying the kernel parameters ) on the fly. /proc is stored in memory, unlike other file-systems, which are stored on disk. If you look at the file /proc/mount ( which lists all the mounted file systems, like "mount command), you should see a line in it like:

gerp proc /proc/mounts
/proc /proc proc rw 0 0

/proc  is controlled by the kernel and does not have an underlying device. Because it contains mainly state information controlled by the kernel, the most logical place to store the information is in memory controlled by the kernel. Doing a 'ls -l'
on /proc reveals that most of the files are 0 bytes in size; yet when the file is viewed, quite a bit of information is seen. How is this possible ? This happens because the /proc file-system like any other regular file-system registers itself to the Virtual File System layer ( VFS ). However when VFS make calls to it requesting i-nodes for files/directories the /proc file system creates those files/directories from information within the kernel.

Mounting the proc file system:

If already not mounted on your system, proc file system can be mounted on your system by running the following command -

mount -t proc proc /proc

The above command should successfully mount your proc file system. Please read the mount man page for more details.

Viewing the /proc files:

/proc files can be used to access information about the state of the kernel, the attributes of the machine the state of the running processes etc. Most of the files in the /proc directory provide the latest glimpse of a system's physical environment. Although these /proc files are virtual yet they can be viewed using file the file is created on  the fly from information within the kernel. Here are some interesting results which i got on my system.

$ ls -l /proc/cpuinfo   
-r--r--r--  1 root root 0 2012-03-06 11:47 /proc/cpuinfo

$ file /proc/cpuinfo
/proc/cpuinfo: empty

processor    : 0
vendor_id    : GenuineIntel
cpu family    : 15
model        : 4
model name    :                   Intel(R) Xeon(TM) CPU 3.40GHz
stepping    : 1
cpu MHz        : 3391.625
cache size    : 1024 KB
physical id    : 0
siblings    : 2
core id        : 0
cpu cores    : 1
fpu        : yes
fpu_exception    : yes
cpuid level    : 5
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall lm constant_tsc pni monitor ds_cpl est cid cx16 xtpr
bogomips    : 6792.84
clflush size    : 64
cache_alignment    : 128
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 1
vendor_id    : GenuineIntel
cpu family    : 15
model        : 4
model name    :                   Intel(R) Xeon(TM) CPU 3.40GHz
stepping    : 1
cpu MHz        : 3391.625


ETC..

This is the result for a five-CPU machine. Most of the information above is self-explanatory and gives useful hardware information about the system. Some of the information in /proc files is encoded and various utilities are built that interpret this encoded information and output it in a human readable format. Some of these utilities are: 'top', 'ps', 'apm' etc.

Getting Useful system/kernel information:

The Proc File System can be used to gather useful information about the system and the running kernel. Some of the important files are listed below:

  • /proc/cpuinfo - information about the CPU ( model, family, cache size etc.)
  • /proc/meminfo - information about the physical RAM, Swap space etc.
  • /proc/mounts - list of mounted file system.
  • /proc/devices - list of available devices
  • /proc/filesystem - supported file system
  • /proc/modules -  list of loaded modules
  • /proc/version - Kernel version
  • /proc/cmdline - Parameters passed to the kernel at the time of starting 

There are much more files in /proc than listed above. An alert reader is expected to do a 'more' on every file in /proc directory or read [1]1 for more information about the files present in /proc directory. I suggest to use 'more' and not 'cat' until you know the filesystem a bit because some files (e.g. kcore) can be very large.

Information about running processes:

The /proc file system can be used to retrieve information about any running process. There are couple of numbered sub-directories inside /proc. Each numbered corresponds to a process id (PID). Thus for each running process, there is a sub-directory inside /proc named by its PID. Inside these sub-directories are files that provide important details about the state and environment of a process. Lets try to search for a running process.


$ps -aux | grep mozilla

The above command shows that there is a running process of mozilla with PID ***.

The file  "cmdline" contains the command invoked to start the process. The "environ" file contains the environment variables for the process. "status" has status information on the process, including the user (UID) and group (GID) identification for the user executing the process the parent process ID (PPID) that instantiated the PID and the current state of the process such as "Sleeping" or "Running". Each process directory also has a couple of symbolic links. "cwd" is a link to the current working directory for the process ,"exe" to the executable program of the running process, "root" is a link to the directory, which the process, sees as its root directory (usually "/"). The directory "fd" contains links to the file description that the process is using. "cpu" entry appears only on SMP linux kernels. It contains a breakdown of process time by CPU.

/proc/self is an interesting sub-directory that makes it easy for a program to use /proc to find information about its own process. The entry /proc/self is a symbolic link to the /proc directory corresponding to the process accessing the /proc directory.

Interacting with kernel via /proc:

Most of the files in /proc discussed above are read-only. However the /proc file system provides provision of interact with kernel via read-write files inside. Writing to these files can change the state of the kernel and therefore changes to these files should be made with caution. The /proc/sys directory is the one that hosts all the read-write files and thus can be used to change the kernel behaviour.


/porc /sys/kernel - This directory contains information that reflects general kernel behaviour. /proc/sys/kernel/{domainname,hostname} hold the domain-name and hostname for the machine/network. These files can be configured to modify these names.

$hostname
$cat /proc/sys/kernel/domainname
$cat /proc/sys/kernel/hostname
$echo "new-machinename" > /proc/sys/kernel/hostname
$hostname

Thus by modifying the file inside /proc file system. we are able to modify the hostname. Lots of other configurable files exists inside /proc/sys/kernel. Again its impossible to list down every file here so readers are expected to go through this directory in detail.
Another configurable directory is /proc/sys/net. Files inside this directory can be modified to change the networking properties of the machine/network. E.g. By simply modifying a file, you can hide your machine in the network.


$echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

This will hide your machine in the network as it disables answers to icmp_echos. The host will not respond to ping queries from other hosts.

$ ping machiname.domainname.com


To trun it back to default behaviour, do
$echo 0> /proc/sys/net/ipv4/icmp_echo_ignore_all

There are lots of other sub-directories in /proc/sys which can be configured to change the kernel properties. See [1],[2] for detailed information.

Conclusion:

The /proc File System provides a file-based interface to the linux internals. It assists in determining the state and configuration of various devices and processes on system. Understanding and applied knowledge of this file-system is therefore the key to making the most out of your linux system.


vi editor

VI Editor

What is vi?

The default editor that comes with the UNIX operating system is called vi ( visual editor ). [Alternate editors for UNIX environments include pico and emacs, a product of GNU.]
 The UNIX vi editor is a full screen editor and has two modes of operation:
  • command mode commands which cause action to be taken on the file, and 
  • Insert mode in which entered text is inserted into the file.

In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the (Escape) key turns off the Insert mode.

While there are a number of vi commands just a handful of these is usually sufficient for beginning vi users. To assist such users, this web page contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice these commands should become automatic.
NOTE: bot UNIX and vi are case-sensitive. Be suer not to use capital letter in place of a lower-case letter; the results will not be what you expect.

To get into and out of vi :

To start vi
To use vi on the type in vi filename. If the file named filename exists, then the first page ( or screen ) of the file will be displayed; if the does not exist, then an empty file and screen are created into which you may enter text.


*
Vi filename
Edit filename starrting at line 1


Vi -r filename
Recover filename that was being edited when system crashed
 
To Exit vi
Usually the new or modified file is saved when you leave vi. However it is also possible to quit vi without saving the file.
NOTE: The course moves to bottom of screen whenever a colon(:) is typed. This type of command is completed by hitting the (or ) key.

*
:x
Quit vi, writing out modified file to file named in original invocation
A common occurrence in text editing is to replace one word or phase by another. To locate instances of particular sets of characters ( or strings ) use the following commands.

/string
Search forward for occurrence of string in text
?string
Search backward for occurrence of string in text
n
Move to next occurrence of search string
N
Move to next occurrence of search string on opposite direction
Determining Line Number:
Being able to determine the line number of the current line or the total number of lines in the file being edited is sometimes useful.

: .=
Returns line number of current line at bottom of screen
:=
Returns the total number of lines at bottom of screen
^g
Provides the current line number, along with the total number of lines, in the file at the bottom of the screen
Saving and Reading Files:
These commands permit you to input and output files other than the named file with which you are currently working.

:r filename
Read file named filename and insert after current line ( the line with cursor)
:w
Write current contents to file named in original vi call
:w newfile
Write current contents to a new file named newfile
:12, 35w smallfile
Write the contents of the lines numbered 12 through 35 to a new file named smallfile
:w! prevfile
Write current contents over a pre-existing file named prevfile

^f
Move forward one screen
^b
Move backward one screen
^d
Move down (forward) one half screen
^u
Move up (back) one half screen
^l
Redraws the screen
^r
Redraws the screen, removing deleted lines
Adding, Changing and Deleting Text :
Unlike PC editors you cannot replace or delete text by highlighting it with the mouse. Instead use the commands in the following tables.
Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately this command acts like a toggle undoing and redoing your most recent action. You cannot go back more than one step.

*
u
Undo whatever you just did; a simple toggle
The main purpose of an editor is to create, add, or modify text for a file.
Inserting or Adding Text:
The following commands allow you to insert and add text. Each of these commands puts the vi editor into insert mode; thus the key must be pressed to terminate the entry of text and to put the vi editor back into command mode.

*
i
Insert text before cursor, until hit


I
Insert text at beginning of current line, until hit
*
a
Append text after curson, until hit


A
Append text to end of current line, until hit
*
o
Open and put text in a new line below current line until hit
*
O
Open and put text in a new line above current line, until hit
Changing Text:
The following commands allow you to modify text.

*
r
Replace single character under cursor (no needed)


R
Replace characters, starting with current cursor position, until hit


cw
Change the current word with new text, starting with the character under cursor, until hit


cNw
Change N words beginning with character under cursor, until ,ESC> hit; e.g. C5w changes 5 word


C
Change (replace) the characters in the current line, until hit


cc
Change (replace) the entire current line, stopping when is hit


Ncc OR cNc
Change (replace) the next N lines, starting with the current line, stopping when is hit
Deleting Text:
The following commands allow you to delete text.

*
x
Delete single character under cursor


Nx
Delete N character, starting with character under cursor


dw
Delete the single word beginning with character under cursor


dNw
Delete N words beginning with character under cursor; e.g. d%w delete 5 words


D
Delete the remainder of the line starting with current cursor position
*
dd
Delete entrie current line


Ndd or dNd
Delete N lines, beginning with the current line; e.g. 5Dd delete 5 lines
   Cutting and Pasting Text:
The following commands allow you to copy and paste text.

yy
Copy (yank, cut) the current line into the buffer
Nyy or yNy
Copy (yank,cut) the next N lines, including the current line, into the buffer
p
Put (paste) the line(s) in the buffer into the text after the current line

Other Commands:
Searching Text:



:wq
Quit vi, writing out modified file to file named in original invocation


:q
Quit (or exit) vi
*
:q!
Quit vi even though latest changes have not been saved for this vi call

Moving the cursor:
Unlike many of the PC and MacIntosh editors, the mouse does not move the cursor within the vi editor screen (or window). You must use the key commands listed below. On some UNIX platforms, the arrow keys may be used as well; however since vi was designed with the Qwerty keyboard ( containing no arrow keys) in mind, the arrow keys sometimes produce strange effects in vi and should be avoided.
If you go back and forth between a PC environment and a UNIX environment, you may find that this dissimilarity in methods for cursor movement is the most frustrating difference between the two.
In the table below the symbol ^ before a letter means that the key should be held down while the letter key is pressed.

*
J or [or down-arrow]
Move cursor down one line
*
K [or up-arrow]
Move cursor up one line
*
H or [ or left-arrow]
Move cursor left one character
*
L or [ or right-arrow]
Move cursor right one character
*
0 (zero)
Move cursor to start of current line ( the one with the cursor)
*
$
Move cursor to end of current line


w
Move cursor to beginning of next word


b
Move cursor back to beginning of preceding word


:0 or lG
Move cursor to first line in file


:n or nG
Move cursor to line n


:$ or G
Move cursor to last line in file

Screen Manipulation:
The following commands allow the vi editor screen ( or windows ) to move up or down several lines and to be refreshed.