Beruflich Dokumente
Kultur Dokumente
The shell is the command prompt within Linux where you can type
commands. If you have logged into a machine over a network (using ssh or
telnet) then the commands you entered were run by the shell. It is in fact a
program that is running on top of the operating system.
To take a basic view of how Linux is built up see the diagram below:
Name of Command
shell
name
Bourne
sh
shell
Korn
ksh / pdksh
Shell
C Shell
csh
Bash
Shell
bash
tcsh
tcsh
Description
The most basic shell available on all UNIX
systems
Based on the Bourne shell with
enhancements
Similar to the C programming language in
syntax
Bourne Again Shell combines the advantages
of the Korn Shell and the C Shell. The
default on most Linux distributions.
Similar to the C Shell
as many of the other shells. It's feature set is sufficient for most
programming needs however it does not have some of the user
conveniences that are liked on the command line. There is no option to reedit previous commands or to control background jobs. As the bourne shell
is available on all UNIX systems it is often used for programming script files
/etc/profile
~/.bash_profile
~/.bashrc
~/.bash_logout
These files are text based shell scripts that can be used to define settings for
either system wide settings (those in the /etc directory), or for an individual
user (those in the users home directory specified by ~). Different files are
called depending upon whether it is an interactive login shell or a noninteractive shell.
/etc/profile
The /etc/profile file provides the system wide default environment variables.
Typically this sets up the umask, LOGNAME, and mail directories etc. It can
also be used to change the default command search path (PATH) for all
users on the system. As most systems don't have a /etc/bashrc file aliases
are sometimes included in the /etc/profile file.
~/.bash_profile
This provides the user specific environment variables, and is often used to
add local search paths onto the PATH. This is called after the /etc/profile
script.
~/.bashrc
This file is called for non-interactive shells, and is normally called from the
~/.bash_profile for interactive shells. It is normally used for setting up
aliases and any other commands that are run during the startup.
~/.bash_logout
The ~/.bash_logout script is called when the user logs out of the interactive
shell.
The vi Editor
Introduction:
vi is a powerful editor with many features. It can handle very large files
much easier than a program like Microsoft Word. Unlike Word, vi is only a
TEXT EDITOR and you cannot include graphics or fancy fonts in your file
the vi editor typically functions in three different modes:
1. Command mode
2. Insert mode
3. colon mode
1) vi command mode
When you first start editing a file with the vi editor you will be in vi
command mode. In this mode you can issue many vi commands, including
commands like insert, append, and delete, and other search and navigation
commands that let you move around your file.
Possibly the most important thing to know is that when you're in command
mode you can't insert text immediately. You first need to issue
an insert,append, or open command to insert text.
2) vi insert mode
Once you issue a vi insert, append, or open command, you will be in vi
insert mode. If you're working with a modern vi or vim implementation, your
vi editor is typically configured to show the current mode of operation, so
when you go into insert mode, you'll see a text string like this on the last
line of your vi editor window:
-- INSERT At this point you can (a) type text into your file and (b) use the arrow keys
to navigate around your file just as you would do with any other text editor.
A very important concept to know is that when you're in vi insert mode, but
you want to switch back to vi command mode, you easily move back to
command mode by pressing the [Esc] key.
3) vi colon mode
The last vi mode is known as vi colon mode. You can only get to colon mode
from command mode, and you get into last line mode by pressing the colon
key, like this:
press {esc} and then press{ :}colon
After pressing this key, you'll see a colon character appear at the beginning
of the last line of your vi editor window, and your cursor will be moved to
that position. This indicates that vi is ready for you to type in a "last line
command".
From this vi command prompt you can do all sorts of really amazing things.
You can do simple things, like quitting your vi session, like this:
:q means quit
:q!--> means quit forcely
:wq means save and quit
Using Vi
vi is an interactive text editor which is display-oriented: the screen of
your terminal acts as a window into the file you are editing. Changes you
make to the file are reflected in what you see.
Using vi you can insert text anywhere in the file very easily. Most of
the vi commands move the cursor around in the file. You can move the
cursor forward and backward in units of characters, words, sentences, and
paragraphs.
The vi Editor
Introduction:
vi is a powerful editor with many features. It can handle very large files
much easier than a program like Microsoft Word. Unlike Word, vi is only a
TEXT EDITOR and you cannot include graphics or fancy fonts in your file
the vi editor typically functions in three different modes:
1. Command mode
2. Insert mode
3. colon mode
1) vi command mode
When you first start editing a file with the vi editor you will be in vi
command mode. In this mode you can issue many vi commands, including
commands like insert, append, and delete, and other search and navigation
commands that let you move around your file.
Possibly the most important thing to know is that when you're in command
mode you can't insert text immediately. You first need to issue
an insert,append, or open command to insert text.
2) vi insert mode
Once you issue a vi insert, append, or open command, you will be in vi
insert mode. If you're working with a modern vi or vim implementation, your
vi editor is typically configured to show the current mode of operation, so
when you go into insert mode, you'll see a text string like this on the last
line of your vi editor window:
-- INSERT At this point you can (a) type text into your file and (b) use the arrow keys
to navigate around your file just as you would do with any other text editor.
A very important concept to know is that when you're in vi insert mode, but
you want to switch back to vi command mode, you easily move back to
command mode by pressing the [Esc] key.
3) vi colon mode
The last vi mode is known as vi colon mode. You can only get to colon mode
from command mode, and you get into last line mode by pressing the colon
key, like this:
press {esc} and then press{ :}colon
After pressing this key, you'll see a colon character appear at the beginning
of the last line of your vi editor window, and your cursor will be moved to
that position. This indicates that vi is ready for you to type in a "last line
command".
From this vi command prompt you can do all sorts of really amazing things.
You can do simple things, like quitting your vi session, like this:
:q means quit
:q!--> means quit forcely
:wq means save and quit
Editing A File
The most common way to start a vi session is to tell it which file to edit. To
edit a file named filename, use the command:
Example: vi filename
The screen will clear and the text of your file will appear on the screen. If
filename doesn't exist yet, vi will start you in a new file, and when you tell it
to save your work, it will use the filename that you specified.
Arrow Keys
On most terminals, you can use the arrow keys to move the cursor around.
Left and right moves the cursor left or right one character, and up and down
move the cursor up or down one line. The other way to move the cursor is
with the h, j, k, and l keys
h
left
down
up
right
Searching
Another way to position yourself in the file is by giving the editor a string to
search for. If you type "/" followed by a string of characters and press Enter,
the editor will search for the next occurrence of this string in your file, and
place the cursor there. Pressing n will go to the next occurrence after that.
If instead of forward, you want to search backward for a string, use ?
instead of /. In a ? string search, pressing n will take you to successive
occurrences in the same (backward) direction.
Example: /abc
Output: searches and highlights occurrence of abc in text .
Other Options:
SPACE
dd
deletes a line
4dd
echo
echo displays a line of text.
Overview
echo is a fundamental command found in mostoperating systems that offer
a command line. It is frequently used in scripts, batch files, and as part of
individual commands; anywhere you may need to insert text.
Backspace.
\c
\e
\f
A form feed.
\n
A newline.
\r
A carriage return.
\t
A horizontal tab.
\v
A vertical tab.
echo examples
Here
we
have
inserted
newlines.
Example5: echo -e 'Here\twe\thave\tinserted\thorizontal\ttabs.'
Output: Here
we
have
inserted
horizontal
tabs.