Showing posts with label Commands/Shortcuts. Show all posts
Showing posts with label Commands/Shortcuts. Show all posts

Sunday, November 6, 2011

Linux Some Basic Commands

Process
ps -auwx - Report a snapshot of the current processes
pstree - Display a tree of processes
pmap - Display/examine memory map and libraries
pidof processname - Find the process ID of a running program
pgrep processname - Look up or signal processes based on name and other attributes
ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Performance
iostat - Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions
vmstat - Report virtual memory statistics
mpstat - Report processors related statistics
netstat - Print network connections, routing tables, interface statistics, masquerade connections and multicast memberships
free - Display amount of free and used memory in the system
top - provides a dynamic real-time view of a running system
slabtop - display kernel slab cache information in real time
sar - Collect, report, or save system activity information

General Info
uname - print system information
uptime - Tell how long the system has been running
cat /proc/meminfo - Show memory size and usage
runlevel - find the current and previous system runlevel
chkconfig - updates and queries runlevel information for system services
ntsysv - simple interface for configuring runlevels
init, telinit - process control initialization
w - Displays currently logged in users and processes they are running
who - show who is logged on
whoami - Displays user id
chsh - change your login shell
login - sign on
/etc/shells is a text file which contains the full pathnames of valid login shells
set - Display all environment variables in your current environment
id - Display user and all group ids
last, lastb - Listing of most recent logins by users.command
history - Shell command to display previously entered commands
sysreport - collect some detailed information about the hardware which will be used to diagnose problems with the system

hostname - show or set the systemâs host name
domainname - show or set the systemâs NIS/YP domain name
dnsdomainname - show the systemâs DNS domain name
nisdomainname - show or set systemâs NIS/YP domain name
ypdomainname - show or set the systemâs NIS/YP domain name

Kernel
ipcs - List share queues, Shared memory, List Semaphores.
cat /proc/modules List all currently loaded kernel modules.
lsmod - List loaded modules 
insmod - Inserts a module into the active kernel  
rmmod - Remove a loaded module. Just specify the module name. No ".o" or path necessary. 
modprobe - High level handling of loadable modules. Loads module and dependencies.  
depmod - Creates dependencies file for a module (used by modprobe) 
modinfo - Display information about a kernel module
sysctl - configure kernel parameters at runtime

Network
ifconfig - configure a network interface
setting in /etc/sysconfig/network. Command will change entry in /etc/hosts
mii-tool - view, manipulate media-independent interface status 
ethtool - Display or change ethernet card settings
route - show / manipulate the IP routing table

Filesystem
proc - process information pseudo-filesystem
fstab - static information about the filesystems
fsck - check and repair a Linux file system
df - report filesystem disk space usage
du - estimate file space usage
mount - mount a file system
umount - unmount file systems
fdisk - Partition table manipulator for Linux
lsof filesystem - list open files
fuser - identify processes using files or sockets
e2label - Change the label on an ext2/ext3 filesystem
mkfs -t ext2 /dev/ram - build a Linux file system
mke2fs - create an ext2/ext3 filesystem
e2fsck - check a Linux ext2/ext3 file system
tune2fs  - adjust tunable filesystem parameters on ext2/ext3 filesystems
dumpe2fs - dump ext2/ext3 filesystem information
partprobe - inform the OS of partition table changes

mkswap - set up a Linux swap area
swapon,  swapoff  -  enable/disable  devices and files for paging and swapping

NFS
exportfs - maintain list of NFS exported file systems
showmount - show mount information for an NFS server
nfsstat - print NFS statistics

Files
ls - List directory contents. List file information 
fuser - Identify processes using files or sockets 
file - Identify file type.

File permission
chmod - Change a file's mode or permissions 
umask - Set default file permissions
chgrp - Change a file's group
chown - Change a file's owner
chroot - run command or interactive shell with special root directory

ACL
setfacl - set file access control lists
chacl  - change the access control list of a file or directory
getfacl - get file access control lists

User
useradd - Create a new user or update default new user information
usermod - Modify a user account
userdel - Delete a user account and related files
passwd - update a userâs authentication tokens(s)
finger - user information lookup program 
chfn - change your finger information
chage - change user password expiry information
users - Show all users logged in. 

Group
groupadd  - Create a new group
groupmod - Modify a group
groupdel - Delete a group
newgrp   - log in to a new group
gpasswd  - administer the /etc/group file
grpck   - verify integrity of group files
groups   - Display groups you are part of

Hardware Info
/usr/bin/lsdev  - List devices and info on system hardware. Also IRQ's.(RPM package procinfo) 
/sbin/lspci  - List all PCI devices (result of probe) Also lspci -vvx and cat /proc/pci 
cat /proc/interrupts - List IRQ's used by system and the device using the interrupt. 
cat /proc/ioports - List I/O ports used by system. 
cat /proc/dma  - List DMA channels and device used by system. 
cat /proc/cpuinfo - List info about CPU. 
hdparm -I /dev/hda - get Harddisk info

Debugging
kill - terminate a process
killall - kill processes by name
pkill - will  send  the  specified signal (by default SIGTERM) to each process instead of listing them on stdout
nice - run a program with modified scheduling priority
renice - alter priority of running processes
ulimit

Log files
closelog, openlog, setlogmask, syslog - control system log
/var/log/messages - system messages
/secure       - Logging by PAM of network access attempts
/dmesg        - Log of system boot. Also see command dmesg
/boot.log     - Log of system init process
/xferlog.1    - File transfer log
/lastlog      - Requires the use of the lastlog command to examine contents
/maillog      - log from sendmail daemon

Tuesday, May 17, 2011

100 Windows XPkeyboard shortcuts

CTRL+C (Copy)
CTRL+X (Cut)
CTRL+V (Paste)
CTRL+Z (Undo)
DELETE (Delete)
SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
CTRL while dragging an item (Copy the selected item)
CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
F2 key (Rename the selected item)
CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
CTRL+SHIFT with any of the arrow keys (Highlight a block of text)
SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
CTRL+A (Select all)
F3 key (Search for a file or a folder)
ALT+ENTER (View the properties for the selected item)
ALT+F4 (Close the active item, or quit the active program)
ALT+ENTER (Display the properties of the selected object)
ALT+SPACEBAR (Open the shortcut menu for the active window)
CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously)
ALT+TAB (Switch between the open items)
ALT+ESC (Cycle through items in the order that they had been opened)
F6 key (Cycle through the screen elements in a window or on the desktop)
F4 key (Display the Address bar list in My Computer or Windows Explorer)
SHIFT+F10 (Display the shortcut menu for the selected item)
ALT+SPACEBAR (Display the System menu for the active window)
CTRL+ESC (Display the Start menu)
ALT+Underlined letter in a menu name (Display the corresponding menu)

Underlined letter in a command name on an open menu (Perform the corresponding command)
F10 key (Activate the menu bar in the active program)
RIGHT ARROW (Open the next menu to the right, or open a submenu)
LEFT ARROW (Open the next menu to the left, or close a submenu)
F5 key (Update the active window)
BACKSPACE (View the folder one level up in My Computer or Windows Explorer)
ESC (Cancel the current task)
SHIFT when you insert a CD-ROM into the CD-ROM drive (Prevent the CD-ROM from automatically playing)

Dialog Box Keyboard Shortcuts
CTRL+TAB (Move forward through the tabs)
CTRL+SHIFT+TAB (Move backward through the tabs)
TAB (Move forward through the options)
SHIFT+TAB (Move backward through the options)
ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
ENTER (Perform the command for the active option or button)
SPACEBAR (Select or clear the check box if the active option is a check box)
Arrow keys (Select a button if the active option is a group of option buttons)
F1 key (Display Help)
F4 key (Display the items in the active list)
BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Micro$oft Natural Keyboard Shortcuts
Windows Logo (Display or hide the Start menu)
Windows Logo+BREAK (Display the System Properties dialog box)
Windows Logo+D (Display the desktop)
Windows Logo+M (Minimize all of the windows)
Windows Logo+SHIFT+M (Restore the minimized windows)
Windows Logo+E (Open My Computer)
Windows Logo+F (Search for a file or a folder)
CTRL+Windows Logo+F (Search for computers)
Windows Logo+F1 (Display Windows Help)
Windows Logo+ L (Lock the keyboard)
Windows Logo+R (Open the Run dialog box)
Windows Logo+U (Open Utility Manager)

Accessibility Keyboard Shortcuts

Right SHIFT for eight seconds (Switch FilterKeys either on or off)
Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
SHIFT five times (Switch the StickyKeys either on or off)
NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
Windows Logo +U (Open Utility Manager)

Windows Explorer Keyboard Shortcuts
END (Display the bottom of the active window)
HOME (Display the top of the active window)
NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
NUM LOCK+Plus sign (+) (Display the contents of the selected folder)
NUM LOCK+Minus sign (-) (Collapse the selected folder)
LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)
RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder)

Shortcut Keys for Character Map

After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts:
RIGHT ARROW (Move to the right or to the beginning of the next line)
LEFT ARROW (Move to the left or to the end of the previous line)
UP ARROW (Move up one row)
DOWN ARROW (Move down one row)
PAGE UP (Move up one screen at a time)
PAGE DOWN (Move down one screen at a time)
HOME (Move to the beginning of the line)
END (Move to the end of the line)
CTRL+HOME (Move to the first character)
CTRL+END (Move to the last character)
SPACEBAR (Switch between Enlarged and Normal mode when a character is selected)

Micro$oft Management Console (MMC) Main Window Keyboard Shortcuts
CTRL+O (Open a saved console)
CTRL+N (Open a new console)
CTRL+S (Save the open console)
CTRL+M (Add or remove a console item)
CTRL+W (Open a new window)
F5 key (Update the content of all console windows)
ALT+SPACEBAR (Display the MMC window menu)
ALT+F4 (Close the console)
ALT+A (Display the Action menu)
ALT+V (Display the View menu)
ALT+F (Display the File menu)
ALT+O (Display the Favorites menu)

MMC Console Window Keyboard Shortcuts
CTRL+P (Print the current page or active pane)
ALT+Minus sign (-) (Display the window menu for the active console window)
SHIFT+F10 (Display the Action shortcut menu for the selected item)
F1 key (Open the Help topic, if any, for the selected item)
F5 key (Update the content of all console windows)
CTRL+F10 (Maximize the active console window)
CTRL+F5 (Restore the active console window)
ALT+ENTER (Display the Properties dialog box, if any, for the selected item)
F2 key (Rename the selected item)
CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)


Remote Desktop Connection Navigation

CTRL+ALT+END (Open the m*cro$oft Windows NT Security dialog box)
ALT+PAGE UP (Switch between programs from left to right)
ALT+PAGE DOWN (Switch between programs from right to left)
ALT+INSERT (Cycle through the programs in most recently used order)
ALT+HOME (Display the Start menu)
CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
ALT+DELETE (Display the Windows menu)
CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
CTRL+ALT+Plus sign (+) (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer.)

Micro$oft Internet Explorer Navigation
CTRL+B (Open the Organize Favorites dialog box)
CTRL+E (Open the Search bar)
CTRL+F (Start the Find utility)
CTRL+H (Open the History bar)
CTRL+I (Open the Favorites bar)
CTRL+L (Open the Open dialog box)
CTRL+N (Start another instance of the browser with the same Web address)
CTRL+O (Open the Open dialog box, the same as CTRL+L)
CTRL+P (Open the Print dialog box)
CTRL+R (Update the current Web page)
CTRL+W (Close the current window

Friday, September 18, 2009

Disk space usage using df command.

To get a listing of free space on all mounted filesystems execute df command with no arguments.

# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 33423168 16560892 15137044 53% /
/dev/sda1 101086 14952 80915 16% /boot
tmpfs 257560 0 257560 0% /dev/shm


Use the df command with -h option to displays the space in human-readable units , the example below show the freespace available in Mb unit:

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 32G 16G 15G 53% /
/dev/sda1 99M 15M 80M 16% /boot
tmpfs 252M 0 252M 0% /dev/shm


Note: The Use% column shows what percentage of the filesystem that currently in use.

To show space on the filesystems those directories are mounted on:

# df /boot
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 101086 14952 80915 16% /boot


The df command can be use to get information on inode usage on all mounted filesystem.  To show the inode information execute df command with the ( -i  ) option:

df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/VolGroup00-LogVol00 8633856 313455 8320401 4% /
/dev/sda1 26104 37 26067 1% /boot
tmpfs 64390 1 64389 1% /dev/shm


The following are some of the flags and arguments that can be used for the df command:
-a, --all include filesystems having 0 blocks
-B, --block-size=SIZE use SIZE-byte blocks
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local filesystems
--no-sync do not invoke sync before getting usage info (default)
-P, --portability use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE limit listing to filesystems of type TYPE
-T, --print-type print filesystem type
-x, --exclude-type=TYPE limit listing to filesystems not of type TYPE
-v (ignored)
--help display this help and exit
--version output version information and exit

NAME:
df - report filesystem disk space usage
Usage: df [OPTION]... [FILE]...

for more information on df command:
# info df
# man df
# df --help

Display the size of file and directory in Linux

[root@fedora ~]# du -h
4.0K ./.rhopenoffice1.1/program/addin
108K ./.gnome2
28K ./.nautilus/metafiles
32K ./.nautilus
6.0M ./.mozilla/firefox/1wvl2gwo.default/Cache
12K ./.mozilla/firefox/1wvl2gwo.default/chrome
12M .
 
The output from above command show the size of each file, directory and with the total size used in your system in human readable size ( -h ).
 

Get the total size of current directory.

 
   The du command can be use to determine the total size of file in current directory.  The example below show the du command use with -s (summarize) and -h (human readable format) option to summaries the size of disk space taken by current directory.
 
[root@fedora ~]# du -s
768096 .
[root@fedora ~]# du -sh
751M .
[root@fedora ~]#
 
To get the size of file and directory in current directory.
 
[root@fedora ~]# du -sh *
14M 20060524-033-x86.exe
85M labu-punyer
8.0K libjmti.odt
4.0K linux-feeds.txt
4.0K mambo_conf.txt
8.0K yumex-0-1.0.1-1.0.fc5.html
408K yumex-1.0.1-1.0.fc5.noarch.rpm
8.0K yum install
11M zope-2.8.5-1.fc5.i386.rpm
[root@fedora ~]#
 

Display the size of specific file extension.

 
   The example below show du command execute with -c option to get the size of each file that have filename ending with .txt and then display grand total of all files in human readable format.
 
[root@fedora ~]# du -ch *.txt
4.0K create.drupal-2.txt
4.0K create.drupal.db.txt
4.0K drupal-pass.txt
4.0K joomla-bazz.txt
4.0K linux-feeds.txt
4.0K mambo_conf.txt
8.0K msql-bazz.txt
4.0K setup_mysql_mambo.txt
4.0K simple.txt
40K total
[root@fedora ~]#
 

Check the size of home directory.

 
   The example below show the use of du command to get the disk usage of each user home directory on the system.
 
[root@fedora home]# pwd
/home
[root@fedora home]# du -sh *
492K bazz
48K botol
44K hamirul
22M kambing
48K kayu
56K labu
80K sysuser
40K william
40K ycluckers
[root@fedora home]#
 
To produce grand total of the /home directory size.
 
[root@fedora home]# pwd
/home
[root@fedora home]# du -csh *
492K bazz
48K botol
44K hamirul
22M kambing
48K kayu
56K labu
80K sysuser
40K william
40K ycluckers
23M total
[root@fedora home]#
 
The following are some of the flags and arguments that can be used for the du command:
 
· -a, --all         write counts for all files, not just directories
· --apparent-size         print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (`sparse') files, internal fragmentation, indirect blocks, and the like
· -B, --block-size=SIZE         use SIZE-byte blocks
· -b, --bytes         equivalent to `--apparent-size --block-size=1'
· -c, --total         produce a grand total
· -D, --dereference-args         dereference FILEs that are symbolic links
· -H like --si, but also evokes a warning; will soon change to be equivalent to --dereference-args (-D)
· -h, --human-readable         print sizes in human readable format (e.g., 1K 234M 2G)
· --si like -h, but use powers of 1000 not 1024
· -k like --block-size=1K
· -l, --count-links count sizes many times if hard linked
· -L, --dereference dereference all symbolic links
· -P, --no-dereference don't follow any symbolic links (this is the default)
· -0, --null end each output line with 0 byte rather than newline
· -S, --separate-dirs do not include size of subdirectories
· -s, --summarize display only a total for each argument
· -x, --one-file-system skip directories on different filesystems
· -X FILE, --exclude-from=FILE Exclude files that match any pattern in FILE.
· --exclude=PATTERN Exclude files that match PATTERN.
· --max-depth=N print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summarize
· --help display this help and exit
· --version output version information and exit
 
NAME
du - estimate file space usage
 Usage: du [OPTION]... [FILE]...
Summarize disk usage of each FILE, recursively for directories.
 
More information on du command:
# info du
# man du
# du --help

Thursday, September 17, 2009

Burn ISO image to DVD

cdrecord -v -sao dev=/dev/hda UDF_Volume.iso

DB Dumps

MySql Dump

mysqldump --protocol tcp -P portnumber -h localhost -u root databasename > filename.sql

DB dump of all database

shell> mysqldump --all-databases > all_databases.sql

Postgresql dump

To get the database dump execute the below commands from outside the database

1. /usr/bin/pg_dump -U postgres -f - only for structure;
2. /usr/bin/pg_dump -U -d > - data + structure;

3.pg_dump dbname -U username -h hostname -p > filename.sql

4.pg_dumpall -U username -h hostname -p > filename.sql

Mysql Commands

To list the users,host in the mysql

select Host ,User ,Password from mysql.user;

To set mysql root password

mysqladmin -u root password newpassword ;


To delete the host from mysql

DELETE FROM mysql.user where host=hostname;


To drop the user

DROP USER 'desiyou'@'localhost';


To Start the multiple instance in Mysql


mysqld_multi --config-file=/etc/my2.cnf start 1
mysqld_multi --config-file=/etc/my2.cnf start 2


Mysql Case Sensitive

vim /etc/my.cnf

lower_case_table_names=1

To know the status of mysql :

SHOW STATUS;

To know the mysql process status :

SHOW FULL PROCESSLIST\G
show variables;

Tuesday, September 15, 2009

VI EDITOR

Basic Cursor Movement

    From Command Mode

k Up one line

j Down one line

h Left one character

l Right one character (or use )

w Right one word

b Left one word

Entering, Deleting, and Changing Text
From Command Mode ,

  • i Enter text entry mode
  • x Delete a character
  • dd Delete a line
  • r Replace a character
  • R Overwrite text , press to end

Displaying Line Numbers

    From Command Mode

:set nu Display line numbers

:set nonu Hide line numbers

Exiting vi
  • To exit you must be in command mode-press if you are not in command mode
  • You must press after commands that begin with a : (colon)
From Command Mode

ZZ
Write (if there were changes), then quit
:wq
Write, then quit
:q Quit (will only work if file has not been changed)
:q! Quit without saving changes to file


More On Cursor Movement

From Command Mode

e Move to end of current word

$ Move to end of current line

^ Move to beginning of current line

+ Move to beginning of next line

- Move to beginning of previous line


G Go to last line of the file

:n Go to line with this number (:10 goes to line 10)


d Scroll down one-half screen

u Scroll up one-half screen

f Scroll forward one full screen

b Scroll backward one full screen


) Move to the next sentence

( Move to the previous sentence

} Move to the next paragraph

{ Move to the previous paragraph


H Move to the top line of the screen

M Move to the middle line of the screen

L Move to the last line of the screen


% Move to matching bracket: ( { [ ] } )


Entering Text Mode

From Command Mode

i Insert text before current character

a Append text after current character

I Begin text insertion at the beginning of a line

A Append text at end of a line

o Open a new line below current line

O Open a new line above current line


Commands and Objects

Format Example

operator number object c2w

number operator object 2cw


Operators

c change

d delete

y yank


Objects and Locations

w one word forward

b one word backward

e end of word

H, M, L top, middle, or bottom line on screen

), ( next sentence, previous sentence

}, { next paragraph, previous paragraph

^, $ beginning of line, end of line

/pattern/ forward to pattern



Replacing and Changing Text

From Command Mode

r Replace only the character under the cursor.
(Note: using r you remain in command mode.)

R Beginning with the character under the cursor,
replace as many characters on this line as you
want. (You are in overtype mode until you
press

cw Beginning with the character under the cursor,
change a word to whatever you type. (You are
in insert mode until you press )

c$ Beginning with the character under the cursor,
C change a line to whatever you type. (You are
in insert mode until you press )


Deleting Text

From Command Mode

x Delete a character

dw Delete an alphabetic word and the following space
(6dw deletes six words)

dW Delete a blank-delimited word and the following space

dd Delete a line (6dd deletes six lines)

d$ Delete all characters to the end of the line.
D

d} Delete all characters to the end of the paragraph.

:5,30d Delete lines 5 through 30


Deleted text goes into a temporary buffer that is replaced each time you delete (or copy) more text. The current contents of the buffer can be put back into your file.
Copying and Pasting Text

From Command Mode

yy Copy (yank) the current line

6yy Copy (yank) six lines, beginning with the current line

yw Copy the current word

p Put the text after the cursor position

P Put the text before the cursor position


Copied text goes into a temporary buffer that is replaced each time you copy (or delete) more text. Only the current contents of the temporary buffer can be put back into your file. As a result, when you use copy (y), use the put (p) command immediately.

A yank and put procedure using colon commands:

1. :5,10y Copy lines 5-10

2. Move cursor

3. :put Put after cursor

Other Useful Commands

From Command Mode

. Repeat last command

n. Repeat last command n number of times

J Join next line to current line

u Undo last single change

U Restore current line

~ Change letter's case (capital to lower and vice versa)


Buffers

Temporary Buffer

Deleted or copied text goes into a temporary unnamed buffer. The contents of the temporary buffer may be retrieved by using the p or P commands.

p Put words from temporary buffer after cursor or
put lines from temporary buffer below current line

P Put words from temporary buffer before cursor or
put lines from temporary buffer above current line


Lettered Buffers

There are 26 lettered buffers (a-z). Contents of a lettered buffer are saved until you copy or delete more characters into it, or until you quit your current vi session.


From Command Mode

"ayy Copy (yank) a line into buffer a

"Ayy Appends to buffer a

"a10yy Copies 10 lines into buffer a

"a10dd Deletes 10 lines of text into buffer a

"ap Put contents of lettered buffer a below the current line


Both temporary and lettered buffers last only for the current vi session.

Copying, Deleting, or Moving Text Using Line Numbers
* These commands start with a colon (:) and end with a or
* g shows the line number of the current line
* The basic form of colon commands is

:beginning_line, ending_line command destination

where destination is the line after which you want the text placed.


From Command Mode

:5,10 co 105 Copy lines 5-10 to the line after 105

:5,20 m $ Move lines 5-20 to end of file

:7,300 d Delete lines 7-300 (to buffer)


Searching for Text

From Command Mode

/text Search forward (down) for text (text can include spaces
and characters with special meanings.)

?text Search backward (up) for text

n Repeat last search in the same direction

N Repeat last search in the opposite direction

fchar Search forward for a charcter on current line

Fchar Search backward for a character on current line

; Repeat last character search in the same direction

% Find matching ( ), { }, or [ ]


Substitutions

The simplest way to do substitutions over a range of lines, or throughout the file, is to use the s colon command. The basic form of this command is the following:


:n1,n2s/old/new/gc

n1 is the beginning line

n2 is the ending line number

s means to substitute text matching the pattern (old)
with text specified by (new)

g (global) is optional. It indicates you want to substitute
all occurrences on the indicated lines. If you use
g, the editor substitutes only the first occurrence
on the indicated lines.

c (confirm) is optional. It indicates you want to confirm
each substitution before vi completes it.


From Command Mode

:%s/old/new/g Substitutes old with new throughout the file

:.,$s/old/new/g Substitutes old with new from the current
cursor position to the end of the file

:^,.s/old/new/g Substitutes old with new from the beginning
of the file to the current cursor position

:& Repeats the last substitute (:s) command


ADVANCED VI

1. Writing to and Reading from Files

From Command Mode

:w file Write current file to file

:w>>file Append current file to file

:5,10w file Write lines 5 through 10 to file

:5,10w>>file Append Lines 5 through 10 to file

:r file Read a copy of file into current file

:!ls See a list of files in your current directory


More About Options

From Command Mode-within vi for the current file only

:set all Display all options

:set Display current settings of options

:set nooption Unset option

:set ai Set Auto Indentation during text entry

:set ic Set Ignore Case during searches

:set nu Show line Numbers

:set sm Show Matching ( or { when ) or } is entered

:set wm=10 Set Wrap Margin 10 spaces from right edge of screen


Customizing vi Sessions

Options can be set four ways:
1. During a vi session

:set nu



2. In a .exrc file in your home directory.

Sample contents of a .exrc file

set nu
set ai
set wm=10





TIPS AND TRICKS

1. Making vi an Editor in Pine

1. In your home directory, type: vi .pinerc

2. Find the line that reads


editor=


3. Change it to read


editor=vi


4. Write and quit the file. (ZZ or :wq)

5. Start Pine

6. In Pine in Compose mode, when you are ready to enter message text, you will see there is an option available called Alt Edit. (Alternate Editor). To evoke the Alternate Editor mode, press: _

When finished editing in vi, exit vi and you will be returned to the compose screen.

2. vi-ing More Than One File

You can edit more than one file at a time with vi.

From The Unix Shell Prompt

vi file1 file2 vi two (or more) files at the same time

From Command Mode

:n Move to file2 from file1

:rew Rewind back to file1

:e! Restore original file1 file2 (start all over)

ZZ Save and quit file. (Must be done for each file.)


Issuing Shell Commands From vi

You can issue a single shell command while in the vi editor. For example, to list the files in your directory (ls), follow these steps:

From Command Mode

:w Write changes to your file (just in case).

:!ls List contents of your current directory on the screen.

Press to return to vi.


You can issue many shell commands by temporarily leaving the vi editor.

From Command Mode

:w Write changes to your file.

:sh Return to the shell to enter a number of commands
without leaving vi.

Press d to return to vi editing.