skip to main | skip to sidebar

OPEN SOURCE

Linux for Better life

  • Home
  • Trik-Tips
  • Free Template
  • Blogger Hack
  • Free Ebook
Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

UNIX and LINUX part 16


The following example matches any line containing the word Apples.
nawk '/Apples/' fruits

Escape Sequences
The following sequences of characters are referred to as escape sequences. Escape sequences specify a notation for characters that are not easily produced from your keyboard and/or cause problems when displayed to your screen. The nawk and echo commands use escape sequences. Although only nawk uses the escape sequences in regular expressions.
Sequence
Description
\b Matches a backspace.
\f Matches a form feed.
\n Matches a new-line.
\r Matches a carriage return.
\t Matches a tab.
\0ddd Matches the ASCII character for the given octal ASCII code.
\c Matches the literal character c. Use \ to generate a \.
Expression Patterns
Expression patterns perform number or string comparisons. Nawk provides eight comparison operators. Six of these operators are relational operators used to perform number or string comparison. The other two are string operators used to perform string comparisons.
String Operators may be used to compare a regular expression pattern to a specific field or the entire input line. The following two operators are supported:
Operator
Function
/RE/ Matches if the current line contains the specified regular expression. Same as the $0 ~ /RE/ command.
expr ~ RE Matches if the string value of expr contains the regular expression RE. For example,
nawk '$1 ~ /[Aa]pples/' fruits

matches lines where field 1 contains "Apples" or "apples."
expr !~ RE Matches if the string value of expr does not contain the regular expression expr. For example,
nawk '$3 !~ /[Aa]pples/' fruits

matches lines where field 1 does not contain the word "Apples" or "apples."
Relational Operators Relational operators compare strings and numbers. The following six operators are used to compare values.
Operator
Function
lv > rv True if lv is greater than rv. For example,
nawk 'NF > 3' fruits

prints each line containing more than three fields.
lv >= rv True if lv is greater than or equal to rv. For example,
nawk ' $1 >= "M" ' fruits

prints each line where the first field begins with a character that has a higher ASCII code than capital M. Such as N, O, P, Q, etc.
lv < rv True if lv is less than rv.
lv <= rv True if lv is less than or equal to rv.
lv == rv True if lv is equal to rv. For instance,
nawk '$1 == "Oranges" ' fruits

prints each line where the first field equals the string "Oranges."
lv != rv True if lv is not equal to rv.
Compound Patterns
A compound pattern is an expression consisting of multiple expression patterns combined with Boolean operators. The Boolean operators are || (OR), && (AND), ! (NOT), and use of parentheses for grouping the operators. If the result of a compound pattern is true, the current input line is matched and the associated action is executed.
Boolean Operators The Boolean operators can be used to combine regular and relational expressions. The following table describes the Boolean operators.
Operator
Function
! Negation. True if expression is NOT true. For example,
nawk '! /Apples/' fruits

prints each line that does not contain the string "Apples."
|| Logical OR. True if either expression is true. For instance,
nawk '$3 > "3,000,000" || $1 == "FRUIT"' fruits

prints the header line and each line with bushel counts of more than "3,000,000." Note 3,000,000 is a string, not a number, because of the commas.
&& Logical AND. True if both expressions are true. For example,
nawk '$3 > "3,000,000" && NF == 5' fruits

prints the header line and each line containing exactly three fields.
( ) Perform comparisons enclosed together(for grouping). For instance,
nawk '( $1 == "Apples" || $1 == "Oranges" ) &&
( NR == 4 )' fruits

prints lines where the first field is either "Apples" or "Oranges" and there are exactly four fields.
Range Patterns
Range patterns contain two patterns separated by a comma (,). A range pattern matches each line from the occurrence of the first pattern to the occurrence of the second pattern. Both patterns may appear on the same line, thus only the one line is matched. If no input line matches the first pattern, no lines are selected. If no input line matches the second pattern, all lines from the first pattern to the end of the file are selected. For example, the following command selects all of the lines from one that contains Apples to one that contains Cherries.
nawk '/Apples/,/Cherries/' fruits

ACTIONS
The action part of an nawk program performs specified actions when a pattern is matched. If no action is specified the default print action is used. The default is the same as specifying { print }, which is equivalent to { print $0 }.
Comments
The nawk command ignores any characters on a line following a # sign. Thus you can document your nawk programs using the number sign.
Constants
Two types of constants are used by nawk, numeric and string. String constants are created by enclosing a sequence of characters in double or single quote marks. For example,
$1 == "FRUIT"

Posted by MALIK

Labels: BSD, code, command, program, unix

UNIX and LINUX part 15


If an example is given for syntax reasons only, the filename infile is used.
PROGRAMS
The nawk command interprets a set of commands known as the nawk program. The program can be specified as an argument on the shell command line or stored in a file. In either case the program consists of one or more pattern-action statements. The general form of the pattern-action statement is:
pattern { action }

For example,
nawk 'NF < 5 { print $1 }' fruits

prints the first field of a line if less than five fields exist on the line. Fields are space or tab separated words. The built-in variable NF contains the number of fields in the current line.
Nawk reads each line of input automatically. If the pattern matches the input line (record) in part or whole, then the following action is performed. If no pattern is specified, then the action is performed for every input record. The action may consist of multiple programming statements discussed later. The action must be enclosed by '{}' for nawk to function properly. The general format is:
{ action }

For example,
nawk '{ print }' fruits

prints every line of the file infile. Thus you wrote a very simple version of the cat command. This is the default pattern-action statement of nawk.
If no action is specified, each matching input record is displayed on the standard output. The general format is:
pattern

For example,
nawk 'NF == 4' fruits

prints each line consisting of four fields.
WRITING PROGRAMS
It is very common to write small nawk programs in-line; that is, on the command line or even spread over a couple of lines. For example,
nawk 'BEGIN { print "Annual Fruit Report" }
{ print }
END { print "More fruit to Grow" }' fruits

prints the banner line Annual Fruit Report, every line of the fruits file, and a trailer line More fruit to Grow. This line can be typed from your terminal or placed in a shell script.
NOTE:
In-line nawk programs are limited in length to the command line buffer of your system. This buffer varies; some systems are set to 512 characters of information while others are set to 10240 characters. The general rule of thumb for the length of in-line programs is that they should never exceed 2000 characters (approximately one screenful of characters).
The same nawk program written in a file format would be invoked by the command line:
nawk -f fruitprog fruits

The fruitprog file would contain the following lines.
BEGIN { print "Annual Fruit Report" }
{ print }
END { print "More fruit to Grow" }

Notice the single quotes are removed; the nawk command itself is not needed for the input files.
PATTERNS
Patterns are used to select lines from the input. If a pattern matches a string on an input line, the associated action is performed. It is possible to write an nawk program that does not have a pattern, such as
nawk '{ print $1 }' fruits

The default pattern selects all lines from the input.
NOTE:
The BEGIN and END patterns both require an action.
The BEGIN Pattern
The BEGIN pattern does not match any input. Instead, the action associated with the BEGIN pattern is executed before any input is read by nawk. This allows for initialization of variables, the printing of headers, and other coding that needs to be done before the first line of input is read by nawk. The general format is:
nawk 'BEGIN { initialization code; headers; etc. }' infile

The following example prints a header line.
nawk 'BEGIN { print "Fruit Shipped From Primary State" }' fruits

The END pattern
The END pattern does not match any input. Instead, the action associated with the END pattern is executed after all of the input has been read by nawk. The general format is:
nawk 'END { wrap up code }' infile

The following example prints the total number of lines read by nawk.
nawk 'END { print NR }' infile

The built-in variable NR contains the Number of Records read.
Regular Expression Patterns
The following table contains each regular expression and the task that it performs when used inside a pattern. Regular Expressions are often referred to as REs in UNIX terminology. Thus we use the RE notation for uniformity and briefness.
Metacharacters
Metacharacters are the special characters used in regular expression patterns that have special meanings. Metacharacters are often referred to as special or magic characters.
Regular expression patterns must be enclosed in slashes. For example, to match any records (lines) containing the string cpu you would use /cpu/ as the pattern. The string inside the slashes may be any valid combination of the following list.
Special RE
Description
c Matches the character c if c is not a special regular expression character.
\ Escapes the meaning of a metacharacter.
^ Matches the beginning of the line.
$ Matches the end of the line.
. Matches any single character other than the new-line.
[class] A character class. Matches any one character in the class.
[c1-c2] Matches any one of the ASCII characters in the range defined within the brackets.
[^class] Does NOT match any of the ASCII characters listed within the brackets. Ranges may be specified.
| Alternation of regular expressions. Matches either one or the other of the regular expressions provided.
(!) Concatenation operation. Normally the parentheses are omitted. Allows for control of precedence in the interpretation of the regular expressions specified.
RE* Matches zero or more occurrences of the preceding regular expression.
RE+ Matches one or more occurrences of the preceding regular expression.
RE? Matches zero or one occurrence of the preceding regular expression.
// The null RE refers to the last RE defined.

Posted by MALIK

Labels: BSD, c programming, command, program, unix

UNIX and LINUX part 13


Module 5
apropos (BSD)
DESCRIPTION
The external apropos command searches for keywords in the header lines of all UNIX Reference Manual entries. There is one manual entry for each UNIX command distributed with your system. These entries are often referred to as "man pages." The header line for each command entry is a brief one-line description of the command.
If you need to use a command but do not know its name, you can use apropos to search for the command by specifying keywords. You specify keywords on the apropos command line. Each keyword is searched for separately in the header lines of all manual entries. If a keyword is located in the title (header line) of a man page, the command's title is displayed. The search ignores the case of letters.
A match occurs even if the keyword is a part of a word in the title. For example, if you specify
apropos command

all titles with the word "command" and "commands" would be displayed.
COMMAND FORMAT
Following is the general format of the apropos command.
apropos keyword [ ... ]

Arguments
The following list describes the arguments that may be passed to the apropos command.
keyword A word you want to search for in the title of all the manual sections.
FURTHER DISCUSSION
The apropos command is the same as the man -k keyword command. If apropos displays a line for a keyword that begins with name(section) ..., you can display the entire manual page by entering the command:
man section name

To display the title line of each manual page that contains the keyword "editor" you specify a apropos command like:
apropos editor

which should return the following output:
a,out (5) - assembler and link editor output format
ed, red (1) - basic line editor
ex, edit (1) - line editor
ld (1) - link editor
sed (1) - stream text editor
vi, view (1) - visual display editor based on ex(1)

The output from your system may vary depending on which utilities have been implemented and installed on your particular system.
DIAGNOSTICS AND BUGS
If apropos fails to work, it is possible the /usr/lib/whatis file has not been created. The system administrator creates this file by changing directories to /usr/lib and executing mkwhatis or makewhatis, depending on your system's command name.
RELATED COMMANDS
Refer to the man and whatis commands described in modules 87 and 155.
RELATED FILES
The apropos command looks in a file containing the titles for all of the manual documents, usually the /usr/lib/whatis.
APPLICATIONS
The apropos command provides a way for you to search for a command to perform a certain function based on keywords. For example, if you needed to display the contents of a file, you could use apropos and specify several keywords that referred to displaying contents of files. For example, you might try the command,
apropos print display show type file

The trick to making apropos work is being flexible in your choice of keywords. Flexible means you should try to remember as many synonyms for a word as you can.
There are trade-offs in how you use keywords. If you use too many or too broad of a word, such as file, you may get pages of output. On the other hand, if you use a very selective set of keywords, you may get no output. The basic advice is to try a few different keywords to get the general idea of how the titles of the man pages are written. Unfortunately, experience is still the best teacher, especially when UNIX man pages are involved.
TYPICAL OPERATION
In this activity you use the apropos command to locate commands related to text. Begin at the shell prompt.
1. Type apropos text and press Return. Depending on your system, the output should resemble the following:
cj> apropos text
nawk(1) - text pattern scanning and processing language
csplit(1) - context split
ed, red (1) - text editor
edit(1) - text editor (variant of ex for casual users)
end, etext, edata(3C) - last locations in program
ex(1) - text editor
fspec(4) - format specification in text files
lex(1) - generate programs for lexical analysis of text
neqn(1) - format mathematical text for nroff
nroff(1) - format text
plock(2) - lock process, text, or data in memory
sed(1) - stream text editor

Posted by MALIK

Labels: APPLICATIO, BSD, command, DIAGNOSTIC, editor, unix

UNIX and LINUX part 12


Tracked aliases
Tracked aliases are not true aliases. A tracked alias is the actual command name and the full pathname used to access an existing command. It is called tracked alias because the path is aliased for the command name and the new alias tracks directly to the command. This keeps the shell from having to search the entire PATH for a command, thus providing faster command execution.
You can turn command tracking on by using the set command. Type
cj> set -o trackall

to inform the shell to track all commands issued to it. For example, the following sequence of commands illustrates the automatic tracking of commands.
cj> set -o trackall
cj> alias ls # list alias of ls command
ls alias not found # no alias exists for ls
cj> ls # execute the ls command
...
cj> alias ls # list alias of ls command
ls=/bin/ls # tracked alias has been set to full path

You can track individual commands by using the -t option. For example,
cj> alias -t ls

would cause the same results as the above steps. But the shell would not automatically set every command you issue to a tracked alias.
RETURN CODES
Alias returns a zero (true) unless a name is given that has not been set to a string.
APPLICATIONS
The alias command is used to create shorthand versions of longer commands. It is very useful for hard-to-remember commands and for those commands you use repeatedly throughout the day. Remember to place your aliases in your .profile or your ENV file (.kshrc) so they are set each time you log in.
The unalias command is used to remove previously set aliases.
TYPICAL OPERATION
In this activity you use the alias command to create various aliases. Begin at the shell prompt.
1. Type alias "I= -F" and press Return.
C Shell
Type alias I "Is -F" and press Return.
2. Now try your new command by typing I and pressing Return. Notice the output of your l command is a multicolumn list with the executable (*) and directory (/) files being flagged.
3. List all aliases you have set by typing alias and pressing Return.
In this activity you use the unalias command to remove the previously defined l alias command. Begin at the shell prompt.
1. Remove the l alias by typing unalias I and pressing Return.
2. Type alias I and press Return to list out your l alias. Notice the l alias is no longer defined.
3. Turn to Module 64 to continue the learning sequence.

Posted by MALIK

Labels: alias, application, code, command, linux, path, unix

UNIX and LINUX part 11


Module 4
alias/unalias (csh, ksh)
DESCRIPTION
The internal alias command provides a shorthand for one or more commands. The alias command is supported by the csh and the ksh. There are three types of aliases in the Korn shell: exported, preset, and tracked. An exported alias is passed to subshells when called by name. The preset aliases are set by the Korn shell. The tracked aliases are full pathnames for commands.
Aliases can be used to redefine the shell's built-in commands but not the keywords.
Aliases can be created, exported, and listed using the alias command. Aliases can be removed using the unalias command. Exported aliases are passed to subshells. Therefore, if you have an alias defined in your login shell and you execute a shell script, the shell script is able to access the aliases.
Aliases are established as they are read, not during execution. For an alias to work, it must be created before the command that uses the alias is executed. Basically, you have to define your aliases before you can reference them.
The internal unalias command is used to remove alias definitions. For example, if you want to do away with your l alias, you enter unalias l and press Return.
Aliases can be created, exported, and listed using the alias command. Aliases can be removed using the unalias command.
COMMAND FORMAT
Following is the general format of the alias command.
alias [ -tx ] [ name=string ... ]
alias name
unalias name

If no options or arguments are given, then all existing aliases are listed.
C Shell (csh)
alias name string
unalias name
Options
The following options may be used to control how alias functions.
-t Allows you to set and list tracked aliases. A tracked alias has a full pathname for the command used in the string. This provides less overhead in search and execute time since the location of the command is already known. If your PATH variable is reset, the string of a tracked alias is reset to NULL. If no arguments are provided on the command line, all tracked commands are listed - not really an alias, but it is how the Korn shell handles tracking commands.
-x Allows you to set or list exported aliases. An exported alias functions like an exported variable; it may be passed to subprocesses. If no arguments are provided on the command line, all exported aliases are listed.
C Shell
The csh alias does not support any options.
Arguments
The following list describes the arguments that may be passed to the alias command.
name=string Defines an alias name that runs the command string.
name The name of the alias. The name becomes a new command that is an alias for the command specified in the string part of the alias. For example,
alias lx="ls -x"
sets the name lx to the command ls -x specified in the string. Now you can use lx as a command.
If only a name is provided, then the alias string for that alias is displayed if it exists.
= The delimiter between the name and command string.
string The command you wish to have executed when you use name as a command. If any spaces or tabs are contained in the string, then you must quote the entire string. For example,
alias dir="ls -la | pg"
sets dir to be an alias for the command ls -la | pg. So when you type dir and press Return, you actually execute the ls -la | pg command, the string part of the alias.
If a space follows the string of an alias command, then the following commands are checked for being an alias.
If no names or strings are given, then the appropriate aliases are listed with their corresponding string.
If there are spaces in the string side of the alias, you must enclose it in quotes.
C Shell (csh)
The C shell uses a slightly different syntax to set up an alias. Instead of using an equal sign (=), you simply put a space between the name and the command. The string does not have to be enclosed in quotes if it contains spaces.
The C shell alias also allows you to use history substitution which is replaced by command line arguments. For example,
alias la 'echo \!*'
would expand la * into echo file1 . . ., which would be all the files in the current directory.
FURTHER DISCUSSION
If you alias a command that already exists as a true command, you can still refer to it by enclosing it in single quotes. For example, if you set the following alias
alias ls='ls -x'

you can still run the normal ls by typing
'ls'

or
/bin/ls

It is considered best not to rename an existing command using alias unless you always use the command the way you are setting up the alias. For example, if you always use ls -x, you may want to create an alias, ls="ls -x". To keep from interfering with the ls command, you might consider using l or lx for the alias name.
If you wish to have a command aliased each time you log in to the system, you must place the alias command line in your .profile or in your ENV (.kshrc) file. The ENV file is executed each time a ksh is started.
You might find the following list of aliases useful.
alias -x lf="ls -Fx"
alias -x l="ls -l"
alias -x ud="cd .."
alias -x bd="cd -"
alias -x dir="ls -l"
alias -x dir/w="ls -x"
alias -x copy="cp "
alias -x more="pg -n "
alias -x type="cat " # although type is an internal command
alias -x prt="lp -dlaser" # alias to whence using print is not advisable

Exported aliases
Exported aliases are like exported variables. They are passed to subshells. Aliases that have not been exported are not passed to subshells and, therefore, are not known by such subshells. The following aliases are automatically exported by the shell.
echo='print -'
false='let 0'
functions='typeset -f'
hash='alias -t'
history='fc -l'
integer='typeset -i'
nohup='nohup '
pwd='print - $PWD'
r='fc -e -'
true=':'
type='whence -v'

Posted by MALIK

Labels: alias, provider, unalias, unix, utility

UNIX and LINUX part 10


SYSTEM DOCUMENTATION
There are many different documents produced by AT and T and other UNIX developers. The primary documents for each UNIX System are the Reference Manuals and Guides. These documents provide you with specific details on the UNIX System you are using. One other document that most users ignore but that is extremely important is the Release Notes for UNIX and all related software. Release Notes provide insight to changes, quirks, problems, and compatibility issues relating to the new release of the software. It will be to your benefit to locate a copy and discover what your release of UNIX holds in store for you.
The User's Reference Manual and the User's Guide describe the basic utilities and software of the UNIX System. The Reference Manual describes each utility that is available on the UNIX System. The Guide provides an overview and tutorials on the more common and complex UNIX utilities.
Illustrated UNIX addresses both of these areas to provide a tutorial and a reference manual in one book. It demystifies the guru language of the standard reference manuals and organizes the tutorials into a useful sequence that can later be easily referenced.

Posted by MALIK

Labels: AT and T, documentation, linux, system, unix, utility

UNIX and LINUX part 9


Each file has one inode number that points to that file's index node, or inode for short. A file has one and only one inode, even though it may have multiple filenames. The filenames are all linked to the same inode by the directory entries. An inode contains the following information:
owner (user ID)
type (directory, ordinary, block special, character special, or pipe)
access permissions (user, group, others)
access times (last modification, last access, last inode modification)
number of links size in bytes (number of filenames stored in directories)
disk addresses (Multiple entries point to the data of which
- some entries point to data blocks
- other entries point to a single indirect block
- other entries point to a double indirect block
- other entries point to a triple indirect block)
Limitations
The current limit on a file size is over 4 gigabytes, based on 1024-byte file system blocks, usually more space than is available on the entire system's disk drives. The name of a file can only be 256 characters.
Problems
On a multiuser system with thousands of files, there is the possibility that the filename has been used previously by another user. This does not pose a large problem, because most users have their own private directories, but it must be considered in publicly used directories.
SPECIAL FILES
Special UNIX files are pieces of computer code that interface with the UNIX kernel. There are two types of special files: device drivers and fifos. Both are interfaces within the UNIX kernel, a part of the I/O subsystem.
Device drivers are used to communicate with and control peripheral devices attached to your UNIX System, such as printers, terminals, disk drives, or tape drives. Device drivers may be block or character special, referring to how the driver handles I/O to and from a device.
Fifo (Pipes) are used to join two or more UNIX processes together allowing the streaming of data. Streaming data means that data flows from one program into the next without being stored on disk. Fifo special (first-in first-out), or named pipes, allow unrelated UNIX programs to exchange information.
Device Drivers
Device drivers are block or character special files. They are low-level routines that reside in the system kernel where they interface to peripheral devices, such as terminals, printers, disk and tape drives, connected to the computer system. They perform I/O tasks to and from a specific type of device. UNIX device drivers are interfaces that make devices appear as ordinary files when performing I/O functions.
Block-type drivers read and write in blocks of data, resembling random access storage. A block is usually 512 or 1024 bytes, depending on your system's BSIZE constant stored in /usr/include /sys/param.h.
Character-type drivers read and write a single byte of data, often referred to as raw devices. Most of the device drivers on a UNIX System are character special.
Pipes
A pipe is a UNIX file that takes the output of one process and provides it as input to the next process. A more internal view of a pipe would be that data is transferred between processes in a first-in first-out sequence. The pipe also synchronizes the execution of the surrounding processes. The first process must execute and begin output before the next process can begin its execution.
The most common use of pipes is to connect multiple UNIX programs together to form a pipeline. A pipeline feeds information from one program to the next.
When executing multiple UNIX commands, pipes may be used between the commands to create what is referred to as a pipeline command. Likewise, if data is to start in an original state at the source and be manipulated by commands along the way to its destination, then pipes must be used to connect the commands together so that the data flows to the destination. For convenience, the entire command is called a pipeline.
Since the commands are changing the data along the way, they are referred to as filters. A command must be capable of being a filter for it to be used in a pipe. A filter can read from standard input and write to standard output. The pipe passes data unchanged while a filter manipulates the data as it is passed down the pipeline.
Enter the following command at your shell prompt and press Return:
cj> grep :0: /etc/passwd | nawk -F: '{ print $1 " "$5}' | sed 's/://g'
root Admin. - super user
sync File system sync
dgn Diagnostics

The output is the first and fifth fields of lines from the password file that contained the :0: string, which should be all logins with root user ID permissions.
The same results could have been accomplished using temporary files, but this is very inefficient and clumsy.
cj> grep :0: /etc/passwd > TMP1
cj> nawk -F: '{ print $1 " " $5 }' TMP1 > TMP2
cj> sed 's/://g' TMP2
root Admin. - super user
sync File system sync
dgn Diagnostics
cj> rm TMP1 TMP2

THE UNIX SHELL
The shell (ksh) is a very powerful and dynamic UNIX utility that functions as the UNIX command interpreter. It is the primary user interface to the operating system (kernel). The shell is a command language and a programming language. As a command language it can be used to communicate interactively with the kernel. As a programming language users can write shell scripts to solve simple to complex problems.
The shell is probably the most sophisticated UNIX utility. It can read from your terminal or from a file. Thus is can be interactively programmed or programs can be stored in files.
The following is a typical sequence of events when a user interacts with the shell as the primary user interface:
1. User logs in to the system.
2. The shell prompts for input (a command).
3. User types in command and presses Return.
4. The shell searches for program; if found, executes it.
5. Program runs; user may interact with program.
6. Program exits; user may have to exit the program.
7. The shell prompts for next command; return to number 4 above.
8. User types exit, logout, or Ctrl-D to exit shell.
9. The shell logs the user off the system.

Posted by MALIK

Labels: device, driver, linux, open source, operating system, programming, unix

UNIX and LINUX part 7


PORTABILITY
One of the most sought after features UNIX possesses is portability. Portability is the ability to rewrite the operating system for a different vendor's hardware without a major rewrite effort. UNIX is highly portable and has been ported by many hardware vendors to their computer hardware. In fact, every computer vendor has a UNIX or a UNIX-like system ported to their hardware - a milestone that no other operating system can claim.
There are two main reasons UNIX is a prime system for porting from hardware to hardware. The first is that the kernel provides an interface between the hardware and most of the nonkernel UNIX software. When UNIX is ported to another hardware platform, only the kernel requires major modifications. Since most of the UNIX software interfaces with the kernel and not the hardware, the software is hardware independent and does not require much, if any, modification when it is ported to a new hardware platform.
The second reason UNIX is easy to port is that the majority of the UNIX operating system is written in the C programming language. Most operating systems are written in the hardware vendor's proprietary assembly language. This makes it very difficult, if not impossible, to port their operating systems to a different vendor's computer.
Benefits
Portability allows the customer to choose the vendor and not be locked into that vendor's hardware and software environment. It also provides the user with a broad base of application software that can be used on hardware from different application vendors.
The porting of an operating system creates a standard software environment across a broad range of computers, ranging in size from micros to supercomputers. This cuts training time dramatically and increases overall productivity. It also reduces support costs and redevelopment costs.
PORTABLE APPLICATION SOFTWARE
The UNIX System provides a standard application development environment that allows for easy porting of application software. The C programming language is a big asset to the porting of software between different UNIX machines.
The ability to port software to many systems easily provides application software vendors with a much larger market without the headaches of multiple proprietary environments. Customer training requirements are reduced and the training of internal personnel is minimized. The number of support people needed is not increased because of different knowledge base requirements, but because more software is being sold. Development can spend more time on enhancements instead of ports to unknown, proprietary architectures. Once a customer has bought a product on one UNIX machine, the customer can purchase a different vendor's UNIX machine and be able to use the same applications without having to retrain personnel. As you can understand, portability is a very important issue for many computer users.
JOB CONTROL
Job control on UNIX is the ability to control which job is executed in foreground, background, or is suspended.
* Foreground execution is considered normal interactive command execution. The command is entered from the keyboard. The shell waits until the command completes execution, then the shell prompts for another command to execute.
* Background execution is considered batch processing. A command is entered and detached from the terminal. The shell can continue interactive command processing.
* Suspended jobs (processes) are commands that have been placed in a suspended state. They are not being executed in background or foreground.
Job control allows you to suspend a foreground or background job. A suspended job can be moved to background or foreground. Background jobs can be brought to the foreground and foreground jobs can be placed in the background.
Using job control can increase the productivity of a user by allowing multiple tasks to be juggled back and forth between background, foreground, or a suspended state. For example, a user can edit a source file while executing the compiled program, thus watching the functionality of the program and making changes while suspending the program.

Posted by MALIK

Labels: code, free, linux, open source, operating system, unix

UNIX and LINUX part 6


COMMUNICATING WITH OTHER USERS
UNIX provides multiple ways to communicate with other users. There are commands to communicate interactively or by electronic mail (E-mail). The following is a brief overview of some of the more common commands used to communicate with fellow users.
WRITING TO A USER
The write command allows you to write to a user that is currently logged on to the system. The following steps show how to "talk" to a user with write.
1. First you must find out who is available for you to write. Type who and press Return. This will display who is currently on the system. Select a user to write to and continue on to the next step.
cj> who
bill tty05 Jan 11 08:41
nancy tty07 Jan 11 08:03
mylogin tty11 Jan 11 09:05
nasser tty18 Jan 11 07:49
smr tty23 Jan 11 09:11
tlp tty09 Jan 11 07:38

2. Type write bill and press Return. Now type a message you would like to send to bill. When you finish writing your message press Ctrl-D.
cj> write bill
Hi Bill,
This is Robert. I finally got my UNIX login and am trying to
annoy all other users so they will log off the system and
response time will improve. Have a great day and LOG OFF the
system now!.
^D

NOTE:
While you are typing your message you may see text intermixed with what you are typing. This is probably one line of a response message from the person you are writing.
RECEIVING MESSAGES FROM WRITE
If someone is sending you a message from write, you can perform the following steps to respond.
1. First you will receive a message and a beep when someone writes to you.
Message from bill tty5...

2. Respond by typing write bill and pressing Return. From this point forward you continue your communication as if you had initiated the conversation.
SENDING MAIL
You can send mail to a user by using the mail command.
The mail command reads in a message and sends it to a mailbox for the specific user. The following steps show how to send a simple letter to a user on your local system.
1. First you must know to whom to send the letter. To retrieve a list of all users on your local UNIX System type nawk -F: '{print $1" "$5}' /etc/passwd | sort | more and press Return.
2. Select a user name and type mail nancy and press Return. Now you may type the letter you wish to send to nancy. After you finish the letter, press Ctrl-D to send the letter to nancy. Replace nancy with the name of a user on your system.
RECEIVING MAIL
To receive mail, a user must first send mail to your user name. If no one likes you and you never receive mail you can always send mail to yourself. This is very common practice; it provides an on-line reminder service. The following steps show how to read any mail that may have been sent.
1. Type mail and press Return. Notice the message you requested your system administrator to send you is displayed. If there's no mail you probably have a very busy system administrator.
2. The mail utility has a help feature that provides some insight to using it more effectively. Type ? or help and press Return. Notice a screen of information on the mail utility is displayed.
NOTE:
There are two major versions of the mail utility. One is UNIX System V and the other is Berkeley based. The Berkeley version is supplied with System V as mailx, although it is possible that it has been moved to the mail name. This book discusses the Berkeley /usr/ucb/Mail version and the System V /bin/mailx version of mail and refers to it as mail/mailx.
LOGGING OUT OF THE SYSTEM
To log out of UNIX you must exit the shell. There are multiple ways of exiting the shell; the most common is pressing Ctrl-D. You may also type exit and press Return or, on some systems, you may type logout and press Return.

Posted by MALIK

Labels: code, free, linux, open source, operating system, unix

UNIX and LINUX part 5


TEXT EDITING AND DISPLAYING
UNIX provides multiple ways to enter text into files. The most common way is to use one of the editors. The editors are ed, ex, and vi. The ed editor is the most basic editor. It is a line editor. A line editor does not display the text on the screen while you are editing. You have to display the text, then perform editing functions on a line-by-line basis.
The ex editor is an enhanced version of the ed editor. It provides much better substitution and addressing capabilities. But it is still a line editor.
The vi editor is a visual editor built on top of the ex line editor. Thus vi has the power of visually displaying the text you are working on while also having a powerful line editor to perform substitutions and other necessary functions.
The following steps show you how to create a file using the vi screen editor. It is advisable to learn the ex and vi editors because of there power and popularity.
1. Before you begin using vi you must have your environment set properly. First type env and press Return. Notice that a list of variables is displayed on your screen. Look for the TERM= variable in the list. This variable must be set before vi will perform correctly.
C Shell
Type printenv and press Return.
2. To set TERM to a desired terminal type, type TERM=VT100 and press Return. Replace VT100 with the type of terminal you are using.
C Shell
Type set term=vt100 and press Return.
3. Begin editing a file by typing vi file1 and pressing Return. Notice the screen is cleared and tildes (~) are placed along the left side. The filename is placed on the bottom line along with status information. Your screen looks like the following display.
4. To enter text, type i; this puts vi in insert mode. Now type This is a new file created by vi. and press Esc. Notice you entered a line of text and now the cursor is at the end of the line.
5. To duplicate the line, type yy to yank it to a register and type p to put it back on the screen. Notice you now have 2 lines of text that are identical.
6. To move up 1 line type k, to move down 1 line type j, to move right 1 character type l, and to move left 1 character type h.
7. To jump to the beginning of the current line type 0. Notice the cursor moves to the beginning of the line.
8. To jump to the end of the current line type $. Notice the cursor moves to the end of the line. Remain in vi to continue the following steps.
The following steps show you how to interface with ex commands while in vi.
1. Type :ver and press Return to display what version of vi/ex you are using. On some systems you will need to press Return to redisplay the vi screen.
2. Write the file to disk by typing :w and pressing Return. On some systems you will need to press Return again to redisplay the vi screen.
3. To substitute a string throughout the file (global substitute) type :%s/a new/an old/g and press Return. Notice that both lines changed from having the string "a new" to having "an old." The percent sign (%) tells ex to search lines 1 through end-of-file (EOF). The "s" tells ex to perform a substitution. The "/a new/an old/" says to search for "a new" and change it to "an old." The g tells ex to change all occurrences on a line. The default is to change the first occurrence on each line. Press Return.
4. To escape to the shell type :sh and press Return. Notice a shell prompt appears on your terminal; you have been placed in a new subshell. You may execute any normal UNIX command. To return to vi/ex press Ctrl-D and then press Return.
5. To execute a UNIX command without leaving the editor type :!cat % and press Return. The % is expanded by vi into the current buffer name (file1). The command cat file1 is executed and control is returned to vi.
6. To save the file to disk and exit vi type ZZ (capital letters).

Posted by MALIK

Labels: code, free, linux, open source, operating system, unix

UNIX and LINUX part 4


Using Redirection
The ">" symbol redirects standard output to a file.
1. Create a file by typing cat > myfile and pressing Return. Then type in the following text and press Ctrl-D. The ">" symbol informs your shell to redirect output of the cat command to a file, "myfile." The cat command reads from the standard input in this example.
cj> cat > myfile
Name:Address1:Address2:City:State:Zip
Someone:916 Hawk Street::Austin:Texas:78749
Anyone:Eagle Avenue:Suite 100:Dallas:Texas:75218
^D

2. Now type cat myfile and press Return to display the contents of the file.
3. Create a directory by typing mkdir temp and pressing Return. Then type ls and press Return. Notice that temp is now listed in your directory.
cj> mkdir temp
cj> ls
myfile
temp

4. Type ls -l and press Return to produce a long listing of your directory. Notice the temp line starts with a "d" and the myfile line starts with a "-". The "d" signifies a directory. The "-" siginifies a normal file.
5. Now set up a directory structure in your HOME directory for later use. Type mkdir letters bin tmp and press Return. This creates the "letters," "bin," and "tmp" subdirectories in your HOME directory.
Using an editor
There are three popular editors on UNIX that can be used to create files. They are ed, ex, and vi; please refer to the module that describes each of these editors (Module 39, Module 43, and Module 151).
COPYING AND COMBINING FILES
UNIX provides multiple commands to copy files. The following commands are the most commonly used.
1. Copy myfile to phone.db by typing cp myfile phone.db and pressing Return. The cp command does not display information if it was successful.
2. Combine two files using the cat command by typing cat myfile phone.db > myph and pressing Return. A new file called "myph" is created.
3. Display the contents of the myph file by typing cat myph and pressing Return.
RENAMING AND MOVING FILES AND DIRECTORIES
The following command renames files or moves them to another directory.
1. Rename the phone.db file to phone by typing mv phone.db phone and pressing Return. Again no response if mv was successful.
2. Type mv temp db and press Return to rename the temp directory to "db."
3. Type mv phone db and press Return to move the phone file to the db directory.
CHANGING DIRECTORIES
To move around from directory to directory you use the cd command.
1. Type cd and press Return to make sure you are in your HOME directory.
2. Type pwd and press Return to display your present working directory.
cj> pwd
/u1/ts/mylogin

3. Type cd db and press Return to change to the db directory.
4. Type pwd and press Return. Notice you are now in the db directory.
cj> pwd
/u1/ts/mylogin/db

5. Type cd ../bin and press Return to change to the "bin" directory that you created earlier.
6. Again type pwd and press Return to display your present working directory.
cj> pwd
/u1/ts/mylogin/bin

7. Type cd and press Return to change back to your HOME directory.
DELETING FILES AND DIRECTORIES
The following commands remove files or directories.
1. Remove the files myfile and myph by typing rm myfile myph and pressing Return. The rm command does not respond if it was successful.
2. Type ls -x and press Return to see that myfile was removed.
cj> ls -x
bin db letters tmp

3. Type rmdir tmp and press Return to remove the tmp directory.
4. Type ls -x and press Return to display the contents of your directory.
cj> ls -x
bin db letters

OTHER USEFUL COMMANDS
There are many other commands that make life easy on the UNIX System; the more popular ones are included in the following examples.
1. Type cd db and press Return to change directories to db.
2. Type wc phone and press Return to display how many characters, words, and lines are in the file.
cj> wc phone
3 7 131 phone

There are 3 lines, 7 words, and 131 characters in the file.
3. Select the line containing "Austin" from the file by typing grep Austin phone and pressing Return. Notice the line containing "Austin" is displayed on your terminal.
4. Sort the "phone" file by typing sort phone and pressing Return. Notice that the order of the lines are rearranged and displayed on your terminal in alphabetical order.
System V and BSD with System V extensions
5. Cut out the first field of the "phone" file by typing cut -f1 -d: phone and pressing Return. Your screen should look like the following display:
cj> cut -f1 -d: phone
Name
Someone
Anyone

6. Type cd and press Return to return to your HOME directory.

Posted by MALIK

Labels: linux, open source, operating system, unix

UNIX and LINUX part 1


CORRECTING TYPING MISTAKES
The UNIX System reads each individual character and temporarily saves or buffers them until you press Return or Line Feed. It then interprets the entire line and performs the requested operation.
The UNIX System performs full duplex input/output (I/O) with your terminal. This means you can type characters in to UNIX while UNIX is displaying information out to your terminal. This will result in a messy, hard-to-read screen, but the data will flow both directions, and the input flow will be interpreted in the correct sequence. You may also type ahead of the UNIX System's ability to read the characters, referred to as UNIX's read-ahead feature. The number of read-ahead characters you may type is limited but usually it is more than you will ever need (256 to 4096).
Default Correction Keys
The @(^U-csh), #(DEL-csh) and \ characters have special meaning to UNIX. The @(^U-csh) character deletes the current input line and is referred to as the line kill character. The #(DEL-csh) erases the last character and is referred to as the erase or backspace character. Multiple #(DEL-csh) erases back to the beginning of the current line. The \ character escapes the meaning of any special character. Therefore \# prints a # and does not perform a backspace.
Resetting Correction Keys
The @(^U-csh) and #(DEL-csh) keys can easily be reset. The standard reset values are Ctrl-X (while pressing and holding the Ctrl key, press the X key) used in place of @, and Ctrl-H (Backspace) used instead of #. Most csh users (who are usually on BSD systems) do not reset the ^U and DEL keys.
1. Display the current settings that UNIX interprets as special keys on your terminal by typing stty and pressing Return. Notice the erase and kill default settings. Depending on your system administrator, your settings may differ. The output format for stty may differ if you are on a BSD system.
cj> stty
speed 38400 baud; -parity cread
erase = #; kill = @; swtch = ^';
-inpck icrnl -ixon onlcr tab3
echo echoe echok

BSD (Berkeley)
cj> stty everything
2. Redefine the erase and kill characters by typing stty erase "^h" kill "^x" and pressing Return. The "^" (caret) is typed as Shift-6; do not type Ctrl-H. Notice stty does not display a response.
3. Display the new settings by typing stty and pressing Return.
cj> stty
speed 38400 baud; -parity cread
erase = ^h; kill = ^x; swtch = ^';
-inpck icrnl -ixon onlcr tab3
echo echoe echok

4. Type echo Ti#his is a #n example. at your shell prompt and press Return. Use the appropriate erase key (Ctrl-H/Backspace) in place of the # keys. Notice that when you press your Backspace key the cursor moves back one space.
5. Type echo Another eamxpl@echo Another example and press Return. Use the appropriate line kill key (Ctrl-X) in place of the @ key. Notice that when you press your kill key the cursor jumps to the beginning of the next line; the old line is ignored and a new line of input is read.
BSD (Berkeley)
The new BSD device driver will erase the current line and move your cursor to the beginning of the current line.
6. Type cat/etc/group and press Return. Be ready to immediately press Ctrl-S to stop the output. The Ctrl-S does not appear on your terminal. To resume scrolling of the output press Ctrl-Q.
7. If you have I/O problems with your terminal, check the setting with stty and refer to the stty command (Module 126) for valid parameters. Don't hesitate to request help from a knowledgable source about your terminal and the tty device driver. This is usually a difficult part of UNIX to get a handle on.
KNOWING WHICH UNIX YOU ARE USING
To know which type or version of UNIX you are using, use the uname command. Type uname and press Return. If the name of your system is displayed, you are probably on System V UNIX. If the shell returns a message like "uname: command not found," you are probably on a BSD system.
Another check to perform is to type ls/usr/ucb and press Return. If a listing is returned, you are probably on a BSD-type system. If a message like "/usr/ucb not found" is returned, you are probably on a System V system.
These are not guaranteed checks but they are fairly reliable. If both return info then you are on a hybrid SV and BSD system.
KNOWING WHICH SHELL YOU ARE USING
To know which shell you are using, use the ps command.
On System V type ps and press Return.
BSD (Berkeley)
On BSD type ps -u and press Return.
The right-hand column contains the names of the programs currently executing. If one is csh, you are using the C shell; sh is the Bourne shell, and ksh is the Korn shell.
Another alternative is to type echo $0 and press Return. If you are using the sh or ksh, the corresponding string is displayed on your terminal. If you are using the csh, nothing is displayed

Posted by MALIK

Labels: code, command, linux, sistem, unix

A SAMPLE SESSION WITH UNIX USER COMMANDS


DESCRIPTION
This module provides basic information about getting started using UNIX. It then leads you on a "hands-on" tour of the most commonly used UNIX commands. Because this module is intended to get you familiar with UNIX, it does not provide in-depth explanations. If you wish to know more about a command while you are using it, refer to the module for the given command. The third module provides additional information about features of the UNIX operating system.
The following is a brief outline of information contained in this module. The information discussed in the first four sections is usually set by the system administrator when your login account is created.
* Terminal setup
* Communications between UNIX and your terminal
* Logging in to the UNIX System
* Correcting typing mistakes
* Setting/changing your password
* Knowing which version of UNIX you are using
* Knowing which shell you are using
* UNIX environment
* Executing commands
* Common commands
* Text editing with vi/ex
* Communicating with others
* Logging out of the UNIX System
BEFORE YOU START
Before you can begin using the UNIX operating system you must have a login account. You should request the login account from the system administrator. If you do not have a system administrator, you must create a login account yourself. Check your System Administrator's Guide or Reference Manual for instructions on how to do this.
You will also need a terminal connected to your system. There are several ways for terminals to communicate with the UNIX System: via direct wire, modem, or terminal servers. Your system administrator should connect your terminal to the system.
LOGGING IN TO THE UNIX SYSTEM
Once you have a "login:" prompt on your terminal and a login account, you can log in to the UNIX System. Throughout this book we assume /u1/ts/mylogin is your login (HOME) directory. After you log in and know your HOME directory substitute it in place of /u1/ts/mylogin. We also use the "mylogin" login name; you should replace it with your login name.
1. At the login: prompt type mylogin and press Return.
cj login: mylogin

TIP: Make sure your CAPS key is not activated. If you have a LOGIN: prompt in all capital letters, press Ctrl-D and wait for a new login: prompt to appear, then try to log in to the system.
NOTE:
Your login name must contain one lowercase character. If you do not type at least one lowercase character, UNIX assumes your terminal cannot generate lowercase ASCII characters and treats all characters as uppercase for the remainder of your login session.
2. Type iamuser2 and press Return at the passwd: prompt to log in to the system. Be patient! Depending on your system and its load factor, it could take from a few seconds to a few minutes for the system to respond.
cj login: mylogin
passwd:

NOTE:
Your password will not be printed, or "echoed," as you type it. The UNIX System disables the output so nosy people are not able to read your password.
3. If your login was successful, you should see information displayed on your screen. If your login attempt was unsuccessful, your display will resemble the following,
cj login: mylogin
passwd:
Login incorrect.
login:

NOTE:
If, after a couple of attempts, you cannot get logged in, check your login name and password with the ones your system administrator gave you. If you are still unable to gain access into the system, contact your system administrator, he/she likes to hear from frustrated users!
Messages from the system
The following list is a possible sequence of what may appear on your screen once you type the correct password. You may be required to type information to complete the login sequence. This depends on your local system.
* General information about the local UNIX System is displayed on your terminal from the message of the day file (/etc/motd).
* System displays or lists unread news items.
* System displays or informs you of mail you have received.
* You may be requested to set your terminal type.
* System displays various other information the system administrator has set up.
* A prompt from the UNIX shell (command interpreter) appears. The default prompt is a dollar sign ($).

Posted by MALIK

Labels: code, command, linux, sistem, unix

Older Posts Home

Links

  • ALJAZEERA TV
  • ANTARA
  • Bali`s Blogger
  • BBC
  • BERITANET.COM
  • CHIP ONLINE
  • CNN
  • DETIK.COM
  • E-BOOK
  • Economic
  • Friends
  • Friendster's Blog
  • Habibieafsyah
  • HARVARD UNIVERSITY
  • ILMU KOMPUTER
  • INFO LINUX
  • KICK ANDY
  • LINUX OpenSuse
  • LINUX SLAX
  • Linux Temanggung
  • LINUX UBUNTU
  • LIPUTAN 6 SCTV
  • MASTER BLOGGER
  • METROTV NEWS
  • MUSIC DOWNLOAD
  • My Class
  • Robotic AMIKOM
  • SMA N 3 TEMANGGUNG
  • SMART E-LEARNING
  • SOFTPEDIA
  • STMIK AMIKOM
  • SUPPORTED BLOGGER
  • TIPS TRICKS
  • TRIAL FILM
  • TV ONE ONLINE

Blog Archive

  • ▼ 2009 (38)
    • ▼ 05/31 - 06/07 (1)
      • Java
    • ► 02/15 - 02/22 (1)
    • ► 01/11 - 01/18 (11)
    • ► 01/04 - 01/11 (25)
  • ► 2008 (70)
    • ► 11/30 - 12/07 (22)
    • ► 11/16 - 11/23 (18)
    • ► 11/09 - 11/16 (1)
    • ► 10/26 - 11/02 (5)
    • ► 10/19 - 10/26 (16)
    • ► 10/12 - 10/19 (4)
    • ► 10/05 - 10/12 (4)



$100.00 Anda pasti untung setelah registrasi!






Search Engine Optimization and SEO Tools







Bookmark CO.CC:Free Domain