Appendix B Basic Linux and VI Commands
Appendix B Basic Linux and VI Commands
___________________
___________________
vi Commands
Basic Linux and
Appendix B
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
vi Commands
The Visual Interpreter/Editor (vi) is the most widely used text editor available for the UNIX
environment. While almost everybody curses its unwieldy command syntax, it is still the only
editor that is almost certain to be included with every version of the UNIX and Linux operating
system. The following is a partial list of available vi commands.
vi has two modes: Command-line (where anything typed is taken as an editing command) and
input mode (where everything typed will be treated as part of the file being edited). To enter the
input mode, type a, A, i, I, o, O, c, C, s, S, r, or R. To return to the command-line mode, use
the Esc key. To access the vi editor from SQLPlus, enter the following command:
SQL>define _editor=vi
To edit a file from the SQLPlus prompt, edit <filename> (press Enter); and from the Linux
command prompt, vi <filename> (press Enter).
Ctrl + f - Scroll forward one page Ctrl + b - Scroll backward one page
u - Will undo the most recent change U - Will undo the most recently deleted text
:e! - re-edit current file without saving any changes made since last change
A - Append text to the end of a line (jumps to end of line and begin appending)
c - Change object C - Change from current cursor position to end of the line
i - Insert text before the current cursor position I - Insert text at the beginning of a line
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
o - Insert a blank line BELOW the current cursor position
r - Replace character at current cursor position R - Replace all characters until Esc is pressed
options include: g (change all occurences on current line) c (confirm prior to each change)
x - Will delete the character directly under the current cursor location
dnd (where n is some integer) - Will delete n lines from current cursor position
J - Delete return at end of current line. Join this line and the next.
COPY, CUT, and PASTE: vi uses a single buffer where the last changed or deleted text is stored. This
text may be manipulated with the following commands:
Y - Yank a copy of the current line y <integer> - Yank a copy of next <int> lines
yw - Yank a copy of the current word yb - Yank a copy of the previous word
p - Put buffer contents after cursor P - Put buffer contents before cursor
zz - Will terminate edit mode :w filename - Will save changes to the filename specified
ZZ - Will terminate edit mode :q! - Will terminate the file without saving changes
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Basic Linux Commands
This appendix is meant to serve only as a quick reference while you are in class. For more
details on these commands, consult the man pages, your Linux documentation, or other
Linux command reference books.
Files and Linux Commands Description/Comments
Directories
Command man <command> Find the manual entry for this
manual <command>.
Show all the manual entries that
man –k <string>
contain this <string>.
man man Displays the manual page for man.
Command info <command> Show the information system entry
information for this command. Using info
info shows a tutorial of the info
documentation system.
Print to cat <file> Concatenate and print; print the
standard out named file to the terminal screen.
List users cat /etc/password
Change cd <directory> Change working directory to
working specified directory
directory cd with no parameters changes to
$HOME.
Copy a file cp <source_file> Copy a source file to a destination
<destination_file> file.
View a file less <file> View a file a page at a time. This
is a GNU version of more, or pg.
View a file more <file> View a file a page at a time. BSD
version.
List directory ls <directory> Options: –l: long listing, -R:
recursive, -a: show hidden files,
-t: sort by time, -r: reverse sort,
default directory is current working
directory.
Create a mkdir <directory> Make a directory defaults into the
directory current working directory, full path
may be specified.
Move or mv <old_file> <new_file> Move changes the name of a file
rename a file or moves it to a different directory.
Process List ps Shows the processes report
ps -ef Shows all processes on the
system with a full listing. Many
option exist see the man page for
details.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Print working pwd Print to stdout the current working
directory directory.
Remove or rm <file> Removing a file on Linux is
erase a file permanent. Options –r: recursive,
and –f: force (including
subdirectories) are very
dangerous. Often the rm
command is aliased with rm –i
The option –i asks ‘Are you
sure?’
Create an touch <file> Create a file.
empty file
Name of the hostname Returns the name of the machine.
machine
The IP address host <machine_name> Queries the Domain Name Server,
of the machine and returns the IP address of the
machine name.
Remote shell rsh <host> <command> Execute a <command> on <host>.
Rsh is not secure, use ssh
instead.
Remote shell ssh <host> Secure shell, has features to
replace rsh, rcp, ftp, and telnet.
Remote shell telnet <host> Start a terminal session on
<host>. Telnet is not secure use
ssh instead.
Search a file for grep <option> <pattern> <file> Search a <file> or stream for a
a pattern regular expression defined by
<pattern> and show the line that
contains that pattern. A common
option is –i for case insensitive.
grep can accept input from a file
or stdin through a pipe as in:
netstat –a| grep ESTABLISHED
Source a script . <script_file> In the bash shell this command ‘.’
forces the script to run in the shell.
Normal behavior is for the script to
run in a child shell.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
An interpreter awk A macro language for reformatting
or interpreting input. For each line
of input, a variety of actions can
be taken. May be referred to as
nawk – for “new awk.”
Sort a file sort Sort a file takes input from stdin or
a filename argument, many
options to sort by a particular
column, field, etc. See man page.
Command-line sed Sed is a command-line editor, with
editor many possible commands and
options that are very good for
editing from a shell script.
Visual editor vi <file> Terminal based editor available on
every UNIX system, Linux
provides vim, an improved vi, that
is a superset of vi.
Gnu editor emacs <file> This is a GPL editor with extensive
customizable features available on
most UNIX and Linux distributions.
WYSIWYG gedit <file> A full-screen editor, requiring X.
editor Available under Gnome.
WYSIWYG kate <file> A full-screen editor, requires X.
Available under KDE
Terminal output stdout Standard out (stdout) is not a
command but a concept, most
Linux commands write to stdout
by default unless redirected.
Terminal input stdin Standard in (stdin) is not a
(keyboard) command but a concept, most
Linux commands read from stdin
by default unless redirected.
Alias alias <command> <alias> Make a substitution when a user
types <command> substitute and
execute <alias>, common alias is
alias ‘rm’ ‘rm –i’. These aliases are
set in the .bashrc file.
Show shell set Prints all of the variables that are
variables currently defined in the shell.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Show printenv or env Prints all the environment
environment variables – an environment
variables variable has been ‘exported’ so
that it will be inherited by child
processes.
File Creation umask –S u=rwx,g=rx,o=rx Set the default permissions for all
mask files created by this shell or its
children. The –S option uses the
symbolic notation, the numeric
notation is obsolete.
Clock xclock An X client that shows a clock on
the screen. Often used to test the
X windows system.
X access xhost Show the current access control in
control xhost +<Xclient> place.
Add an Xclient that is allowed to
access the local DISPLAY, if no
<Xclient> is given all are allowed.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
System Linux Commands Description / Comments
Administration
Substitute user su - username Change the user that is currently
performing the work. This can be
used by any user to change who
is the effective id of the session
user. Normal users must provide a
password, root does not. The ‘-‘
parameter is optional. It runs the
new users login scripts.
Limited root sudo The root user may configure which
privileges users can execute certain
commands as root, and whether a
password is required or not.
Useful for allowing specific users
to perform certain root commands
e.g. mount and unmount
removable volumes such as
CDROMs.
Root file system / The root directory for the system
directory tree.
Home Directory /home Typically the directory where all
user home directories are placed.
For example: /home/oracle.
Tmp directory /tmp A temporary storage area. Do not
put anything here you want to
keep. SA often has a cron job to
remove everything periodically.
Boot directory /boot A small partition to hold the kernel
image(s) and boot loader
instructions.
Log directory /var/log The location of most system log
files.
Sample /etc/inittab Configuration files are located per
configuration the application. Any configuration
files file that you change after
installation should be included in
the backup.
Password files /etc/passwd The /etc/passwd file holds
/etc/shadow user information and must be
readable by others; even with
encrypted passwords this can be
a security hole. The
/etc/shadow file holds the
encrypted passwords and is only
readable by root.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Groups file /etc/group The /etc/groups file defines
the groups on a server and the
users that are members of the
group; primary group for a user is
defined in the /etc/passwd file.
X configuration /etc/X11/XF86Config The file that sets the X server
file settings for your video card,
monitor, mouse, and keyboard.
Usually set up with an OS vendor-
supplied tool.
Schedule a crontab -e Use this command to edit the
command to crontab file, to create the
run at a specification for the cron daemon
regularly to use.
scheduled time
Schedule a /etc/anacrontab Edit the file to specify a script to
script to run at run at a particular frequency (see
a particular man anacrontab for details).
frequency
Schedule a at <options> TIME Runs a job specified by <options>
command to at a specified TIME parameter.
run at a single
specified time
Schedule a batch <options> <TIME> Run a command when the load
command average drops below .8, optionally
after a set TIME.
Mount a file mount <opt> <dev> <mount_point> Mount a file system on device
system <dev> at <mount_point> with the
options specified by <dev>.
Unmount a file umount <dev> Unmount the file system or device.
system umount <mount_point>
Maximum # of 65535
user ID
Recover root {lilo} This is a procedure to recover the
password control-x root password if it is lost. This
linux S requires physical access to the
passwd root
machine and system console. You
start by rebooting the machine,
then during the LILO boot press
and hold Ctrl + X to get a prompt
{grub} and command LILO to boot linux
c to runlevel S.
kernel vmlinuz-2.4.9-13 single
ro root=/dev/hda8 The second procedure uses the
initrd /initrd-2.4.9-13.img grub boot loader.
boot
passwd root
Create new useradd The –D option alone shows the
user defaults.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
–D with other options changes the
defaults options; without –D
override, the default (e.g., –g)
sets a primary group.
Delete user userdel Remove a user and optionally all
files belonging to the user.
Modify user usermod Change /etc/password
account information.
Create new groupadd –g sets the group id; default is first
group free value above 500.
Delete group groupdel Remove a group from the system.
May not remove a group that is a
primary group for a user. Files
owned by deleted group must be
manually changed with chown.
Change run init <runlevel> The init command causes the
levels rcN.d scripts to be evaluated, for
the change in run level. init 6
forces a reboot.
Synchronize sync Forces the buffer cache and page
the disks cache to write all dirty buffers to
disk. Used just before a reboot to
prevent disk corruption.
Shut down the shutdown <mode> <delay> Do a graceful shutdown of the
Linux system system, shut down processes, run
all shutdown scripts, and sync
disks. The modes are –r(reboot)
and –h (halt). The delay is a
required parameter is a number in
seconds or ‘now’. Option
shutdown warning message may
be sent as well.
Error logs dmesg View boot messages. This log is
circular, and limited system errors
could overwrite boot information
after a time.
Network IP /etc/sysconfig/network- This directory holds scripts
configuration scripts/ executed as part of the boot up
sequence by rc.sysinit.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Hosts IP /etc/hosts A list of hosts that your machine
addresses knows about. Must at minimum
include the name of the local
machine and loopback IP.
Name service /etc/nsswitch.conf
switch
Network sysctl -a | grep net View all net parameters that are
parameters set for the kernel.
Routing routed
daemon
NIC ifconfig -a Show all the network devices
Configurations currently configured.
Secondary IP modprobe ip_alias
Address ifconfig eth0:1 IP
Login prompt /etc/issue Banner message user sees when
issued the login prompt.
YP/NIS service /sbin/ypbind Finds and attaches to a NIS
binder server for name resolution and
other services.
Module modinfo <options> <module> Display information about kernel
information modules: –l shows license, –p
parameters, –d description.
List modules lsmod Show currently loaded modules.
Load module insmod Load a loadable module.
Unload module rmmod Unload a loadable module.
Install Software rpm -ivh package Install –i, verbose –v, with
progress hash marks –h.
Uninstall rpm -e package Erase package –e; will not
software uninstall if dependencies exist.
List installed rpm -qa Query –q, All –a, lists all installed
software packages.
Verify installed rpm -V package Compares installed files with the
software rpm database information.
List all files rpm -ql package List all the files that are part of a
package.
Package owner rpm -qf file List the package when given the
full file name.
Machine model uname -m Shows CPU level (e.g., i686).
OS Level uname -r Shows kernel version.
Run Level runlevel Shows previous and current
runlevel.
Kernel sysctl -a Show settings of all settable
Parameters kernel parameters.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Max # File sysctl fs.file-max Shows the value of maximum
Descriptors number of file descriptor per
process.
Kernel /etc/sysctl.conf Compiled in kernel parameters;
parameter may be reset at bootup by setting
settings them in this file.
Change Kernel echo <value> > </proc/<file> Write the new value of a kernel
Parameter parameter into the /proc file
system.
echo 2147483648 Set the value of the maximum size
>/proc/sys/kernel/shmmax of a shared memory segment.
Shared Memory sysctl kernel.shmmax Show the shmmax parameter.
Change Kernel sysctl –w <parameter>=<value> Change a kernel parameter; the –
Parameter p option reads the setting from a
file and sets them. The default file
is /etc/sysctl.conf
Set Process ulimit <option> <value> Set limits on a shell and
limits processes started by the shell.
Users can make limits more
restrictive; generally only root can
make limit less restrictive; some
options require root privilege.
Options: –u sets number of
processes, –n number of file
handles; many others (see man
bash).
Show process ulimit Without options ulimit shows the
limits current limit settings.
Interprocess ipcs <option> Options: –m the current usage of
Communication shared memory; –s usage of
(Shared semaphores; –a shows all.
Memory and
Semaphores)
Remove a ipcrm shm <shmid> Releases the shared memory
shared memory segment identified by <shmid>.
segment This is very dangerous. You can
corrupt a database that is using
the segment that is released.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
System Linux Commands Description / Comments
Performance
Performance top View real-time OS and process
monitor statistics.
System activity sar –<options> <interval> Options: –q shows CPU queue, –
reporter <count> u CPU utilization, –d device
activity, –n DEV network device
activity, many more (see man
page). Interval is in seconds.
Virtual Memory vmstat <interval> < count> Interval is in seconds.
statistics
Virtual Memory cat /proc/meminfo Shows instantaneous virtual
statistics memory usage.
Kernel Cache cat /proc/slabinfo Kernel slab allocator statistics:
statistics frequently allocated cache objects
such as inode, dentries, and
asynchronous IO buffers.
I/O statistics iostat <option> <interval> Options: –d device activity, –c
<count> CPU activity, –x extended disk
activity statistics. The interval is in
seconds.
Multiprocessor mpstat –P <cpu> <count> Return CPU statistics for particular
Statistics <interval> processor or all CPUs in an smp
system.
Physical RAM 64 GB(Theoretical) Maximum physical RAM requires
enterprise kernel (Red Hat
Enterprise Linux AS 21 supports
only up to 16 GB).
Swap device swapon -s Shows devices currently in use for
swap. The swap device is arbitrary
designated at install. It may be
changed or added to. Multiple
swap devices may be created;
swap size should be at least as
large as physical memory.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Display swap free Show the current memory and
size swap usage.
Activate Swap swapon -a Turn on swap.
Free disk df -k Measured in KB; use –m for MB
blocks units.
Device listing cat /proc/devices List devices known to the system
by major and minor number.
Disk cat /proc/scsi/scsi0/sda/model View SCSI disk information.
information
cat /proc/ide/ide0/hda/model View IDE disk information.
Print network netstat <options> Print a wide variety of network
statistics statistics (see man netstat).
Graphical xosview An X-based display of recent OS
system statistics.
statistics viewer
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Misc System Linux Commands Description / Comments
Information
NFS exported /etc/exports Database files are not supported
on simple NFS.
NFS Client /var/lib/nfs/xtab
mounted
directories
Max File 2 TB with 4KB block size (on 32 With ext3 and ext2, others vary.
System kernel)
Max File Size 2 GB {512B block size} The Oracle database can create
files up to 64 GB with a 16 KB
File size can database block size.
not exceed file
system The 32-bit kernel limits file and
2 TB {4KB block size}
block devices to 2 TB.
File System dumpe2fs <device> Dump the file system properties to
Block size stdout.
Filesystem /etc/fstab Mounts these file systems at boot
table up.
Journal ext3
Filesystem
types reiserfs
Disk Label fdisk -l fdisk is not available on all
distributions.
Extend File resize2fs Extending a file system is
system resize_reiserfs applicable to only some file
system types.
Backup tar cvf /dev/rst0 / Create a backup of the root / file
system.
Restore tar xvf /dev/rst0 Restore the root / file system.
Prepare boot /sbin/lilo Must be run after changing
volumes /etc/lilo.conf to push
changes to boot loader.
Startup script /etc/rc.d/rc
Kernel /boot/vmlinuz
Kernel Bits getconf WORD_BIT POSIX call to get kernel
information. There are many other
variables besides WORD_BIT.
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Boot single {lilo} Use LILO facility.
user control-x
linux S
{grub}
c Use GRUB Boot Loader.
kernel vmlinuz-2.4.9-13 single
ro root=/dev/hda8
initrd /initrd-2.4.9-13.img
boot
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
LVM Linux (UnitedLinux) Description / Comments
LVM Logical Volume Manager This package is not provided by Red Hat
Enterprise Linux AS 2.1 and may not be
added without tainting the kernel. Kernel
support is provided in United Linux.
LVM Concepts logical extents A logical volume is made up of logical
extents.
logical volume A set of logical extents taken from a volume
group and presented to the OS as a disk
volume. These extents may be striped
across multiple disks.
volume group A set of physical disk partitions created by
fdisk or the like, initialized with
pvcreate, then grouped into a physical
volume with vgcreate.
Display volume vgdisplay -v
group
Modify physical pvchange
volume
Prepare pvcreate
physical disk
List physical pvdisplay
volume
Remove disk vgreduce
from volume
group
Move logical pvmove
volumes to
another physical
volumes
Create volume vgcreate
group
Remove volume vgremove
group
Volume group vgchange
availability
Restore volume vgcfgrestore
group
Oracle University and Vietpace Consultancy and Information Technology Service Company Limited use only
Exports volume vgexport
group
Imports volume vgimport
group
Volume group vgscan
listing
Change logical lvchange
volume
characteristics
List logical lvdisplay
volume
Make logical lvcreate
volume
Extend logical lvextend
volume
Reduce logical lvreduce
volume
Remove logical lvremove
volume
Create striped lvcreate -i 3 -I 64
volumes