B.S.A Group free domainجامعه مجازی، شبکه اجتماعی، دوست یابی، دوستیابی، ثبت دامنه، ثبت دامین
The Bash, Korn, and Z shells described previously are actually types of shells. A shell, by definition, is an interpretive environment within which you execute commands. You could have many environments running at the same time, either of the same type or of different types of shells. These interpretive environments are referred to as shells. So you could have several shells running at the same time that are of the Bash shell type.
Within each shell, you could enter and execute commands. You can further enhance the capabilities of a shell using shell variables. With a shell variable, you can hold data that you could reference over and over again as you execute different commands within a given shell. For example, you could define a shell variable to hold the name of complex filename. Instead of retyping the filename in different commands, you could reference it with the shell variable.
You define variables within a shell, and such variables are known as shell variables. Many different shells exist. Some utilities, such as the Mail utility, have their own shells with their own shell variables. You can also create your own shell using what are called shell scripts. You have a user shell that becomes active as soon as you log in. This is often referred to as the login shell. Special system variables are defined within this login shell. Shell variables can also be used to define a shell's environment, as described in Chapter 9.
|
Note |
Shell variables exist as long as your shell is active—that is, until you exit the shell. For example, logging out will exit the login shell. When you log in again, any variables you may need in your login shell must be defined again. |
You define a variable in a shell when you first use the variable's name. A variable's name may be any set of alphabetic characters, including the underscore. The name may also include a number, but the number cannot be the first character in the name. A name may not have any other type of character, such as an exclamation point, an ampersand, or even a space. Such symbols are reserved by the shell for its own use. Also, a variable name may not include more than one word. The shell uses spaces on the command line to distinguish different components of a command such as options, arguments, and the name of the command.
You assign a value to a variable with the assignment operator, =. You type the variable name, the assignment operator, and then the value assigned. Do not place any spaces around the assignment operator. The assignment operation poet = Virgil, for example, will fail. (The C shell has a slightly different type of assignment operation.) You can assign any set of characters to a variable. In the next example, the variable poet is assigned the string Virgil:
$ poet=Virgil
Once you have assigned a value to a variable, you can then use the variable name to reference the value. Often you use the values of variables as arguments for a command. You can reference the value of a variable using the variable name preceded by the $ operator. The dollar sign is a special operator that uses the variable name to reference a variable's value, in effect evaluating the variable. Evaluation retrieves a variable's value, usually a set of characters. This set of characters then replaces the variable name on the command line. Wherever a $ is placed before the variable name, the variable name is replaced with the value of the variable. In the next example, the shell variable poet is evaluated and its contents, Virgil, are then used as the argument for an echo command. The echo command simply echoes or prints a set of characters to the screen.
$ echo $poet
Virgil
You must be careful to distinguish between the evaluation of a variable and its name alone. If you leave out the $ operator before the variable name, all you have is the variable name itself. In the next example, the $ operator is absent from the variable name. In this case, the echo command has as its argument the word "poet", and so prints out "poet":
$ echo poet
poet
The contents of a variable are often used as command arguments. A common command argument is a directory pathname. It can be tedious to retype a directory path that is being used over and over again. If you assign the directory pathname to a variable, you can simply use the evaluated variable in its place. The directory path you assign to the variable is retrieved when the variable is evaluated with the $ operator. The next example assigns a directory pathname to a variable and then uses the evaluated variable in a copy command. The evaluation of ldir (which is $ldir) results in the pathname /home/chris/letters. The copy command evaluates to cp myletter /home/chris/letters.
$ ldir=/home/chris/letters
$ cp myletter $ldir
You can obtain a list of all the defined variables with the set command. If you decide you do not want a certain variable, you can remove it with the unset command. The unset command undefines a variable.
The Bash, Korn, and Z shells described previously are actually types of shells. A shell, by definition, is an interpretive environment within which you execute commands. You could have many environments running at the same time, either of the same type or of different types of shells. These interpretive environments are referred to as shells. So you could have several shells running at the same time that are of the Bash shell type.
Within each shell, you could enter and execute commands. You can further enhance the capabilities of a shell using shell variables. With a shell variable, you can hold data that you could reference over and over again as you execute different commands within a given shell. For example, you could define a shell variable to hold the name of complex filename. Instead of retyping the filename in different commands, you could reference it with the shell variable.
You define variables within a shell, and such variables are known as shell variables. Many different shells exist. Some utilities, such as the Mail utility, have their own shells with their own shell variables. You can also create your own shell using what are called shell scripts. You have a user shell that becomes active as soon as you log in. This is often referred to as the login shell. Special system variables are defined within this login shell. Shell variables can also be used to define a shell's environment, as described in Chapter 9.
|
Note |
Shell variables exist as long as your shell is active—that is, until you exit the shell. For example, logging out will exit the login shell. When you log in again, any variables you may need in your login shell must be defined again. |
You define a variable in a shell when you first use the variable's name. A variable's name may be any set of alphabetic characters, including the underscore. The name may also include a number, but the number cannot be the first character in the name. A name may not have any other type of character, such as an exclamation point, an ampersand, or even a space. Such symbols are reserved by the shell for its own use. Also, a variable name may not include more than one word. The shell uses spaces on the command line to distinguish different components of a command such as options, arguments, and the name of the command.
You assign a value to a variable with the assignment operator, =. You type the variable name, the assignment operator, and then the value assigned. Do not place any spaces around the assignment operator. The assignment operation poet = Virgil, for example, will fail. (The C shell has a slightly different type of assignment operation.) You can assign any set of characters to a variable. In the next example, the variable poet is assigned the string Virgil:
$ poet=Virgil
Once you have assigned a value to a variable, you can then use the variable name to reference the value. Often you use the values of variables as arguments for a command. You can reference the value of a variable using the variable name preceded by the $ operator. The dollar sign is a special operator that uses the variable name to reference a variable's value, in effect evaluating the variable. Evaluation retrieves a variable's value, usually a set of characters. This set of characters then replaces the variable name on the command line. Wherever a $ is placed before the variable name, the variable name is replaced with the value of the variable. In the next example, the shell variable poet is evaluated and its contents, Virgil, are then used as the argument for an echo command. The echo command simply echoes or prints a set of characters to the screen.
$ echo $poet
Virgil
You must be careful to distinguish between the evaluation of a variable and its name alone. If you leave out the $ operator before the variable name, all you have is the variable name itself. In the next example, the $ operator is absent from the variable name. In this case, the echo command has as its argument the word "poet", and so prints out "poet":
$ echo poet
poet
The contents of a variable are often used as command arguments. A common command argument is a directory pathname. It can be tedious to retype a directory path that is being used over and over again. If you assign the directory pathname to a variable, you can simply use the evaluated variable in its place. The directory path you assign to the variable is retrieved when the variable is evaluated with the $ operator. The next example assigns a directory pathname to a variable and then uses the evaluated variable in a copy command. The evaluation of ldir (which is $ldir) results in the pathname /home/chris/letters. The copy command evaluates to cp myletter /home/chris/letters.
$ ldir=/home/chris/letters
$ cp myletter $ldir
You can obtain a list of all the defined variables with the set command. If you decide you do not want a certain variable, you can remove it with the unset command. The unset command undefines a variable.
You can control the execution of Linux commands in a shell script with control structures. Control structures allow you to repeat commands and to select certain commands over others. A control structure consists of two major components: a test and commands. If the test is successful, then the commands are executed. In this way, you can use control structures to make decisions as to whether commands should be executed.
There are two different kinds of control structures: loops and conditions. A loop repeats commands, whereas a condition executes a command when certain conditions are met. The BASH shell has three loop control structures: while, for, and for-in. There are two condition structures: if and case. The control structures have as their test the execution of a Linux command. All Linux commands return an exit status after they have finished executing. If a command is successful, its exit status will be 0. If the command fails for any reason, its exit status will be a positive value referencing the type of failure that occurred. The control structures check to see if the exit status of a Linux command is 0 or some other value. In the case of the if and while structures, if the exit status is a zero value, then the command was successful and the structure continues.
With the test command, you can compare integers, compare strings, and even perform logical operations. The command consists of the keyword test followed by the values being compared, separated by an option that specifies what kind of comparison is taking place. The option can be thought of as the operator, but it is written, like other options, with a minus sign and letter codes. For example, -eq is the option that represents the equality comparison. However, there are two string operations that actually use an operator instead of an option. When you compare two strings for equality you use the equal sign, =. For inequality you use !=. Table 8-6 lists some of the commonly used options and operators used by test. The syntax for the test command is shown here:
test value -option value
test string = string
|
Integer Comparisons |
Function |
|
-gt |
Greater-than |
|
-lt |
Less-than |
|
-ge |
Greater-than-or-equal-to |
|
-le |
Less-than-or-equal-to |
|
-eq |
Equal |
|
-ne |
Not-equal |
|
String Comparisons |
|
|
-z |
Tests for empty string |
|
= |
Equal strings |
|
!= |
Not-equal strings |
|
Logical Operations |
|
|
-a |
Logical AND |
|
-o |
Logical OR |
|
! |
Logical NOT |
|
File Tests |
|
|
-f |
File exists and is a regular file |
|
-s |
File is not empty |
|
-r |
File is readable |
|
-w |
File can be written to, modified |
|
-x |
File is executable |
|
-d |
Filename is a directory name |
In the next example, the user compares two integer values to see if they are equal. In this case, you need to use the equality option, -eq. The exit status of the test command is examined to find out the result of the test operation. The shell special variable $? holds the exit status of the most recently executed Linux command.
$ num=5
$ test $num -eq 10
$ echo $?
1
Instead of using the keyword test for the test command, you can use enclosing brackets. The command test $greeting = "hi" can be written as
$ [ $greeting = "hi" ]
Similarly, the test command test $num -eq 10 can be written as
$ [ $num -eq 10 ]
The brackets themselves must be surrounded by white space: a space, TAB, or ENTER. Without the spaces, it would be invalid.
The BASH shell has a set of conditional control structures that allow you to choose what Linux commands to execute. Many of these are similar to conditional control structures found in programming languages, but there are some differences. The if condition tests the success of a Linux command, not an expression. Furthermore, the end of an if-then command must be indicated with the keyword fi, and the end of a case command is indicated with the keyword esac. The condition control structures are listed in Table 8-7.
The if structure places a condition on commands. That condition is the exit status of a specific Linux command. If a command is successful, returning an exit status of 0, then the commands within the if structure are executed. If the exit status is anything other than 0, then the command has failed and the commands within the if structure are not executed. The if command begins with the keyword if and is followed by a Linux command whose exit condition will be evaluated. The keyword fi ends the command. The elsels script in the next example executes the ls command to list files with two different possible options, either by size or with all file information. If the user enters an s, files are listed by size; otherwise, all file information is listed.
|
Condition Control Structures: |
Function |
|
if command then |
if executes an action if its test command is true. |
|
if command then |
if-else executes an action if the exit status of its test command is true; if false, then the else action is executed. |
|
if command then |
elif allows you to nest if structures, enabling selection among several alternatives; at the first true if structure, its commands are executed and control leaves the entire elif structure. |
|
case string in |
case matches the string value to any of several patterns; if a pattern is matched, its associated commands are executed. |
|
command && command |
The logical AND condition returns a true 0 value if both commands return a true 0 value; if one returns a non-zero value, then the AND condition is false and also returns a non-zero value. |
|
command || command |
The logical OR condition returns a true 0 value if one or the other command returns a true 0 value; if both commands return a non-zero value, then the OR condition is false and also returns a non-zero value. |
|
! command |
The logical NOT condition inverts the return value of the command. |
|
Loop Control Structures: |
|
|
while command |
while executes an action as long as its test command is true. |
|
until command |
until executes an action as long as its test command is false. |
|
for variable in list-values |
for-in is designed for use with lists of values; the variable operand is consecutively assigned the values in the list. |
|
for variable |
for is designed for reference script arguments; the variable operand is consecutively assigned each argument value. |
|
select string in item-list |
select creates a menu based on the items in the item-list; then it executes the command; the command is usually a case. |
|
|
echo Enter s to list file sizes,
echo otherwise all file information is listed.
echo -n "Please enter option: "
read choice
if [ "$choice" = s ]
then
ls -s
else
ls -l
fi
echo Good-bye
|
|
A run of the program follows:
$ elsels
Enter s to list file sizes,
otherwise all file information is listed.
Please enter option: s
total 2
1 monday 2 today
$
The while loop repeats commands. A while loop begins with the keyword while and is followed by a Linux command. The keyword do follows on the next line. The end of the loop is specified by the keyword done. The Linux command used in while structures is often a test command indicated by enclosing brackets.
The for-in structure is designed to reference a list of values sequentially. It takes two operands—a variable and a list of values. The values in the list are assigned one by one to the variable in the for-in structure. Like the while command, the for-in structure is a loop. Each time through the loop, the next value in the list is assigned to the variable. When the end of the list is reached, the loop stops. Like the while loop, the body of a for-in loop begins with the keyword do and ends with the keyword done. The cbackup script makes a backup of each file and places it in a directory called sourcebak. Notice the use of the * special character to generate a list of all filenames with a .c extension.
|
|
for backfile in *.c
do
cp $backfile sourcebak/$backfile
echo $backfile
done
|
|
A run of the program follows:
$ cbackup
io.c
lib.c
main.c
$
The for structure without a specified list of values takes as its list of values the command line arguments. The arguments specified on the command line when the shell file is invoked become a list of values referenced by the for command. The variable used in the for command is set automatically to each argument value in sequence. The first time through the loop, the variable is set to the value of the first argument. The second time, it is set to the value of the second argument.
Filters are commands that read data, perform operations on that data, and then send the results to the standard output. Filters generate different kinds of output, depending on their task. Some filters generate information only about the input, other filters output selected parts of the input, and still other filters output an entire version of the input, but in a modified way. Some filters are limited to one of these, while others have options that specify one or the other. You can think of a filter as operating on a stream of data—receiving data and generating modified output. As data is passed through the filter, it is analyzed, screened, or modified.
The data stream input to a filter consists of a sequence of bytes that can be received from files, devices, or the output of other commands or filters. The filter operates on the data stream, but it does not modify the source of the data. If a filter receives input from a file, the file itself is not modified. Only its data is read and fed into the filter.
The output of a filter is usually sent to the standard output. It can then be redirected to another file or device, or piped as input to another utility or filter. All the features of redirection and pipes apply to filters. Often data is read by one filter and its modified output piped into another filter.
|
Note |
Data could easily undergo several modifications as it is passed from one filter to another. However, it is always important to realize the original source of the data is never changed. |
Many utilities and filters use patterns to locate and select specific text in your file. Sometimes, you may need to use patterns in a more flexible and powerful way, searching for several different variations on a given pattern. You can include a set of special characters in your pattern to enable a flexible search. A pattern that contains such special characters is called a regular expression. Regular expressions can be used in most filters and utilities that employ pattern searches such as sed, awk, grep, and egrep.
|
Tip |
Although many of the special characters used for regular expressions are similar to the shell file expansion characters, they are used in a different way. Shell file expansion characters operate on filenames. Regular expressions search text. |
You can save the output of a filter in a file or send it to a printer. To do so, you need to use redirection or pipes. To save the output of a filter to a file, you redirect it to a file using the redirection operation, >. To send output to the printer, you pipe the output to the lpr utility, which then prints it. In the next command, the cat command pipes its output to the lpr command, which then prints it.
$ cat complist | lpr
All filters accept input from the standard input. In fact, the output of one filter can be piped as the input for another filter. Many filters also accept input directly from files, however. Such filters can take filenames as their arguments and read data directly from those files.
The grep and fgrep filters search the contents of files for a pattern. They then inform you of what file the pattern was found in and print the lines in which it occurred in each file. Preceding each line is the name of the file in which the line is located. grep can search for only one pattern, whereas fgrep can search for more than one pattern at a time.
The grep filter takes two types of arguments. The first argument is the pattern to be searched for; the second argument is a list of filenames, which are the files to be searched. You enter the filenames on the command line after the pattern. You can also use special characters, such as the asterisk, to generate a file list.
$ grep pattern filenames-list
If you want to include more than one word in the pattern search, you enclose the words within single quotation marks. This is to quote the spaces between the words in the pattern. Otherwise, the shell would interpret the space as a delimiter or argument on the command line, and grep would try to interpret words in the pattern as part of the file list. In the next example, grep searches for the pattern "text file":
$ grep 'text file' preface
A text file in Unix
text files, changing or
If you use more than one file in the file list, grep will output the name of the file before the matching line. In the next example, two files, preface and intro, are searched for the pattern "data". Before each occurrence, the filename is output.
$ grep data preface intro
preface: data in the file.
intro: new data
As mentioned earlier, you can also use shell file expansion characters to generate a list of files to be searched. In the next example, the asterisk file expansion character is used to generate a list of all files in your directory. This is a simple way of searching all of a directory's files for a pattern.
$ grep data *
The special characters are often useful for searching a selected set of files. For example, if you want to search all your C program source code files for a particular pattern, you can specify the set of source code files with *.c. Suppose you have an unintended infinite loop in your program and you need to locate all instances of iterations. The next example searches only those files with a .c extension for the pattern "while" and displays the lines of code that perform iterations:
$ grep while *.c
Regular expressions enable you to match possible variations on a pattern, as well as patterns located at different points in the text. You can search for patterns in your text that have different ending or beginning letters, or you can match text at the beginning or end of a line. The regular expression special characters are the circumflex, dollar sign, asterisk, period, and brackets: ^, $, *, ., []. The circumflex and dollar sign match on the beginning and end of a line. The asterisk matches repeated characters, the period matches single characters, and the brackets match on classes of characters. See Table 8-8 for a listing of the regular expression special characters.
|
Character |
Match |
Operation |
|
^ |
Start of a line |
References the beginning of a line |
|
$ |
End of a line |
References the end of a line |
|
. |
Any character |
Matches on any one possible character in a pattern |
|
* |
Repeated characters |
Matches on repeated characters in a pattern |
|
[] |
Classes |
Matches on classes of characters (a set of characters) in the pattern |
Suppose you want to use the long-form output of ls to display just your directories. One way to do this is to generate a list of all directories in the long form and pipe this list to grep, which can then pick out the directory entries. You can do this by using the ^ special character to specify the beginning of a line. Remember, in the long-form output of ls, the first character indicates the file type. A d represents a directory, a l represents a symbolic link, and an a represents a regular file. Using the pattern '^d', grep will match only on those lines beginning with a d.
$ ls -l | grep '^d'
drwxr-x--- 2 chris 512 Feb 10 04:30 reports
drwxr-x--- 2 chris 512 Jan 6 01:20 letters
The Shell
The shell is a command interpreter that provides a line-oriented interactive and noninteractive interface between the user and the operating system. You enter commands on a command line; they are interpreted by the shell and then sent as instructions to the operating system. You can also place commands in a script file to be consecutively executed much like a program. This interpretive capability of the shell provides for many sophisticated features. For example, the shell has a set of file expansion characters that can generate filenames. The shell can redirect input and output, as well as run operations in the background, freeing you to perform other tasks.
Several different types of shells have been developed for Linux: the Bourne Again shell (BASH), the Public Domain Korn shell (PDKSH), the TCSH shell, and the Z shell. All shells are available for your use, although the BASH shell is the default. You only need one type of shell to do your work. Red Hat Linux includes all the major shells, although it installs and uses the BASH shell as the default. If you use the Red Hat Linux command line shell, you will be using the BASH shell unless you specify another. This chapter discusses the BASH shell, which shares many of the same features as other shells.
|
Note |
You can find out more about the BASH shell at www.gnu.org/software/bash. A detailed online manual is available on your Linux system using the man command with the bash keyword. |
The Linux command line interface consists of a single line into which you enter commands with any of their options and arguments. From GNOME or KDE, you can access the command line interface by opening a terminal window. Should you start Linux with the command line interface, you will be presented with a BASH shell command line when you log in.
By default, the BASH shell has a dollar sign ($) prompt, but Linux has several other types of shells, each with its own prompt. A shell prompt, such as the one shown here, marks the beginning of the command line:
$
You can enter a command along with options and arguments at the prompt. For example, with an -l option, the ls command will display a line of information about each file, listing such data as its size and the date and time it was last modified. In the next example, the user enters the ls command followed by a -l option. The dash before the -l option is required. Linux uses it to distinguish an option from an argument.
$ ls -l
If you wanted only the information displayed for a particular file, you could add that file's name as the argument, following the -l option:
$ ls -l mydata
|
Tip |
Some commands can be complex and take some time to execute. When you mistakenly execute the wrong command, you can interrupt and stop such commands with the interrupt key- CTRL-C. |
The BASH shell, which is your default shell, has special command line editing capabilities that you may find helpful as you learn Linux (see Table 8-1). You can easily modify commands you have entered before executing them, moving anywhere on the command line and inserting or deleting characters. This is particularly helpful for complex commands. You can use the CTRL-F or RIGHT ARROW key to move forward a character, or the CTRL-B or LEFT ARROW key to move back a character. CTRL-D or DEL deletes the character the cursor is on, and CTRL-H or BACKSPACE deletes the character before the cursor. To add text, you use the arrow keys to move the cursor to where you want to insert text and type the new characters. You can even cut words with the CTRL-W or CTRL-U key and then use the CTRL-Y key to paste them back in at a different position, effectively moving the words. At any time, you can press ENTER to execute the command. For example, if you make a spelling mistake when entering a command, rather than reentering the entire command, you can use the editing operations to correct the mistake.
|
Key Commands |
Operation |
|
CTRL-F, RIGHT-ARROW |
Move forward a character |
|
CTRL-B, LEFT-ARROW |
Move backward a character |
|
CTRL-A |
Move to beginning of line |
|
CTRL-E |
Move to end of line |
|
CTRL-D, DEL |
Delete character cursor is on |
|
CTRL-H, BACKSPACE |
Delete character before the cursor |
|
CTRL-K |
Cut remainder of line from cursor position |
|
CTRL-W |
Cut previous word |
|
CTRL-U |
Cut next word |
|
CTRL-C |
Cut entire line |
|
CTRL-Y |
Paste previously cut text |
|
Tip |
The editing capabilities of the BASH shell command line are provided by Readline. Readline supports numerous editing operations. You can even bind a key to a selected editing operation. You can find out more about Readline in the BASH shell reference manual at www.gnu.org/manual/bash. |
You can enter a command on several lines by typing a backslash just before you press ENTER. The backslash "escapes" the ENTER key, effectively continuing the same command line to the next line. In the next example, the cp command is entered on three lines. The first two lines end in a backslash, effectively making all three lines one command line.
$ cp -i \
mydata \
newdata
The BASH command line has a built-in feature that performs command and filename completion. If you enter an incomplete pattern as a command or filename argument, you can then press the TAB key to activate the command and filename completion feature, which completes the pattern. If more than one command or file has the same prefix, the shell simply beeps and displays a list of possible command completions and waits for you to add enough characters to select a unique command or filename. In the next example, the user issues a cat command with an incomplete filename. Upon pressing the TAB key, the system searches for a match and, when it finds one, fills in the filename. The user can then press ENTER to execute the command.
$ cat pre tab
$ cat preface
The BASH shell keeps a list, called a history list, of your previously entered commands. You can display each command, in turn, on your command line by pressing the UP ARROW key. The DOWN ARROW key moves you down the list. You can modify and execute any of these previous commands when you display them on your command line.
In the BASH shell, the history utility keeps a record of the most recent commands you have executed. The commands are numbered starting at 1, and a limit exists to the number of commands remembered—the default is 500. The history utility is a kind of short-term memory, keeping track of the most recent commands you have executed. To see the set of your most recent commands, type history on the command line and press ENTER. A list of your most recent commands is then displayed, preceded by a number.
$ history
1 cp mydata today
2 vi mydata
3 mv mydata reports
4 cd reports
5 ls
Each of these commands is technically referred to as an event. An event describes an action that has been taken—a command that has been executed. The events are numbered according to their sequence of execution. The most recent event has the highest number. Each of these events can be identified by its number or beginning characters in the command.
The history utility enables you to reference a former event, placing it on your command line and enabling you to execute it. The easiest way to do this is to use the UP ARROW and DOWN ARROW keys to place history events on your command line, one at a time. You needn't display the list first with history. Pressing the UP ARROW key once places the last history event on your command line. Pressing it again places the next history event on your command. Pressing the DOWN ARROW key places the previous event on the command line.
You can use certain control and meta keys to perform other history operations like searching the history list. A meta key is the ALT key, and the ESC key on keyboards that have no ALT key. The ALT key is used here. ALT-< will move you to the beginning of the history list; ALT-N will search it. CTRL-S and CTRL-R will perform incremental searches, display matching commands as you type in a search string. Table 8-2 lists the different commands for referencing the history list.
|
Tip |
If more than one history event matches what you have entered, you will hear a beep, and you can then enter more characters to help uniquely identify the event. |
You can also reference and execute history events using the ! history command. The ! is followed by a reference that identifies the command. The reference can be either the number of the event or a beginning set of characters in the event. In the next example, the third command in the history list is referenced first by number and then by the beginning characters:
$ !3
mv mydata reports
$ !mv
mv mydata reports
|
History Commands |
Description |
|
CTRL-N or DOWN ARROW |
Moves down to the next event in the history list |
|
CTRL-P or UP ARROW |
Moves up to the previous event in the history list |
|
ALT-< |
Moves to the beginning of the history event list |
|
ALT-> |
Moves to the end of the history event list |
|
ALT-N |
Forward Search, next matching item |
|
ALT-P |
Backward Search, previous matching item |
|
CTRL-S |
Forward Search History, forward incremental search |
|
CTRL-R |
Reverse Search History, reverse incremental search |
|
fc event-reference |
Edits an event with the standard editor and then executes it |
|
History Event References | |
|
!event num |
References an event with an event number |
|
!! |
References the previous command |
|
!characters |
References an event with beginning characters |
|
!?pattern? |
References an event with a pattern in the event |
|
!-event num |
References an event with an offset from the first event |
|
!num-num |
References a range of events |
You can also reference an event using an offset from the end of the list. A negative number will offset from the end of the list to that event, thereby referencing it. In the next example, the fourth command, cd mydata, is referenced using a negative offset, and then executed. Remember that you are offsetting from the end of the list—in this case, event 5— up toward the beginning of the list, event 1. An offset of 4 beginning from event 5 places you at event 2.
$ !-4
vi mydata
To reference the last event you use a following !, as in !!. In the next example, the command !! executes the last command the user executed—in this case, ls:
$ !!
ls
mydata today reports
You can also edit any event in the history list before you execute it. In the BASH shell, you can do this two ways. You can use the command line editor capability to reference and edit any event in the history list. You can also use a history fc command option to reference an event and edit it with the full Vi editor. Each approach involves two different editing capabilities. The first is limited to the commands in the command line editor, which edits only a single line with a subset of Emacs commands. At the same time, however, it enables you to reference events easily in the history list. The second approach invokes the standard Vi editor with all its features, but only for a specified history event.
With the command line editor, not only can you edit the current command, you can also move to a previous event in the history list to edit and execute it. The CTRL-P command then moves you up to the prior event in the list. The CTRL-N command moves you down the list. The ALT-< command moves you to the top of the list, and the ALT-> command moves you to the bottom. You can even use a pattern to search for a given event. The slash followed by a pattern searches backward in the list, and the question mark followed by a pattern searches forward in the list. The n command repeats the search.
Once you locate the event you want to edit, you use the Emacs command line editing commands to edit the line. CTRL-D deletes a character. CTRL-F or the RIGHT ARROW moves you forward a character, and CTRL-B or the LEFT ARROW moves you back a character. To add text, you position your cursor and type in the characters you want.
If you want to edit an event using a standard editor instead, you need to reference the event using the fc command and a specific event reference, such as an event number. The editor used is the one specified by the shell in the EDITOR variable. This serves as the default editor for the fc command. You can assign to the EDITOR variable a different editor if you wish, such as Emacs instead of Vi. The next example will edit the fourth event, cd reports, with the standard editor and then execute the edited event:
$ fc 4
You can select more than one command at a time to be edited and executed by referencing a range of commands. You select a range of commands by indicating an identifier for the first command followed by an identifier for the last command in the range. An identifier can be the command number or the beginning characters in the command. In the next example, the range of commands 2–4 is edited and executed, first using event numbers and then using beginning characters in those events:
$ fc 2 4
$ fc vi c
fc uses the default editor specified in the FCEDIT special variable. Usually, this is the Vi editor. If you want to use the Emacs editor instead, you use the -e option and the term emacs when you invoke fc. The next example will edit the fourth event, cd reports, with the Emacs editor and then execute the edited event:
$ fc -e emacs 4
The number of events saved by your system is kept in a special system variable called HISTSIZE. By default, this is usually set to 500. You can change this to another number by simply assigning a new value to HISTSIZE. In the next example, the user changes the number of history events saved to 10 by resetting the HISTSIZE variable:
$ HISTSIZE=10
The actual history events are saved in a file whose name is held in a special variable called HISTFILE. By default, this file is the .bash_history file. You can change the file in which history events are saved, however, by assigning its name to the HISTFILE variable. In the next example, the value of HISTFILE is displayed. Then a new filename is assigned to it, newhist. History events are then saved in the newhist file.
$ echo $HISTFILE
.bash_history
$ HISTFILE="newhist"
$ echo $HISTFILE
newhist
Filenames are the most common arguments used in a command. Often you may know only part of the filename, or you may want to reference several filenames that have the same extension or begin with the same characters. The shell provides a set of special characters that search out, match, and generate a list of filenames. These are the asterisk, the question mark, and brackets (*, ?, []). Given a partial filename, the shell uses these matching operators to search for files and expand to a list of filenames found. The shell replaces the partial filename argument with the expanded list of matched filenames. This list of filenames can then become the arguments for commands such as ls, which can operate on many files. Table 8-3 lists the shell's file expansion characters.
|
Common Shell Symbols |
Execution |
|
ENTER |
Execute a command line. |
|
; |
Separate commands on the same command line. |
|
'command' |
Execute a command. |
|
$(command) |
Execute a command. |
|
[] |
Match on a class of possible characters in filenames. |
|
\ |
Quote the following character. Used to quote special characters. |
|
| |
Pipe the standard output of one command as input for another command. |
|
& |
Execute a command in the background. |
|
! |
History command. |
|
File Expansion Symbols |
Execution |
|
* |
Match on any set of characters in filenames. |
|
? |
Match on any single character in filenames. |
|
[] |
Match on a class of characters in filenames. |
|
Redirection Symbols |
Execution |
|
> |
Redirect the standard output to a file or device, creating the file if it does not exist and overwriting the file if it does exist. |
|
>! |
The exclamation point forces the overwriting of a file if it already exists. This overrides the noclobber option. |
|
< |
Redirect the standard input from a file or device to a program. |
|
>> |
Redirect the standard output to a file or device, appending the output to the end of the file. |
|
Standard Error |
Execution |
|
2> |
Redirect the standard error to a file or device. |
|
2>> |
Redirect and append the standard error to a file or device. |
|
2>&1 |
Redirect the standard error to the standard output. |
|
>& |
Redirect the standard error to a file or device. |
|
|& |
Pipe the standard error as input to another command. |
The asterisk, *, references files beginning or ending with a specific set of characters. You place the asterisk before or after a set of characters that form a pattern to be searched for in filenames. If the asterisk is placed before the pattern, filenames that end in that pattern are searched for. If the asterisk is placed after the pattern, filenames that begin with that pattern are searched for. Any matching filename is copied into a list of filenames generated by this operation. In the next example, all filenames beginning with the pattern "doc" are searched for and a list generated. Then all filenames ending with the pattern "day" are searched for and a list is generated. The last example shows how the * can be used in any combination of characters.
$ ls
doc1 doc2 document docs mydoc monday tuesday
$ ls doc*
doc1 doc2 document docs
$ ls *day
monday tuesday
$ ls m*d*
monday
$
Filenames often include an extension specified with a period and followed by a string denoting the file type, such as .c for C files, .cpp for C++ files, or even .jpg for JPEG image files. The extension has no special status and is only part of the characters making up the filename. Using the asterisk makes it easy to select files with a given extension. In the next example, the asterisk is used to list only those files with a .c extension. The asterisk placed before the .c constitutes the argument for ls.
$ ls *.c
calc.c main.c
You can use * with the rm command to erase several files at once. The asterisk first selects a list of files with a given extension, or beginning or ending with a given set of characters, and then it presents this list of files to the rm command to be erased. In the next example, the rm command erases all files beginning with the pattern "doc":
$ rm doc*
|
Tip |
Use the * file expansion character carefully and sparingly with the rm command. The combination can be dangerous. A misplaced * in an rm command without the -i option could easily erase all the files in your current directory. |
The question mark, ?, matches only a single incomplete character in filenames. Suppose you want to match the files doc1 and docA, but not document. Whereas the asterisk will match filenames of any length, the question mark limits the match to just one extra character. The next example matches files that begin with the word "doc" followed by a single differing letter:
$ ls
doc1 docA document
$ ls doc?
doc1 docA
Whereas the * and ? file expansion characters specify incomplete portions of a filename, the brackets, [], enable you to specify a set of valid characters to search for. Any character placed within the brackets will be matched in the filename. Suppose you want to list files beginning with "doc", but only ending in 1 or A. You are not interested in filenames ending in 2 or B, or any other character. Here is how it's done:
$ ls
doc1 doc2 doc3 docA docB docD document
$ ls doc[1A]
doc1 docA
You can also specify a set of characters as a range, rather than listing them one by one. A dash placed between the upper and lower bounds of a set of characters selects all characters within that range. The range is usually determined by the character set in use. In an ASCII character set, the range "a-g" will select all lowercase alphabetic characters from a through g, inclusive. In the next example, files beginning with the pattern "doc" and ending in characters 1 through 3 are selected. Then, those ending in characters B through E are matched.
$ ls doc[1-3]
doc1 doc2 doc3
$ ls doc[B-E]
docB docD
You can combine the brackets with other file expansion characters to form flexible matching operators. Suppose you want to list only filenames ending in either a .c or .o extension, but no other extension. You can use a combination of the asterisk and brackets: * [co]. The asterisk matches all filenames, and the brackets match only filenames with extension .c or .o.
$ ls *.[co]
main.c main.o calc.c
At times, a file expansion character is actually part of a filename. In these cases, you need to quote the character by preceding it with a backslash to reference the file. In the next example, the user needs to reference a file that ends with the ? character, answers?. The ? is, however, a file expansion character and would match any filename beginning with "answers" that has one or more characters. In this case, the user quotes the ? with a preceding backslash to reference the filename.
$ ls answers\?
answers?
Though not a file expansion operation, {} is often useful for generating names that you can use to create or modify files and directories. The braces operation only generates a list of names. It does not match on existing filenames. Patterns are placed within the braces and separated with commas. Any pattern placed within the braces will be used to generate a version of the pattern, using either the preceding or following pattern, or both. Suppose you want to generate a list of names beginning with "doc", but only ending in the patterns "ument", "final", and "draft". Here is how it's done:
$ echo doc{ument,final,draft}document docfinal docdraft
Since the names generated do not have to exist, you could use the {} operation in a command to create directories, as shown here:
$ mkdir {fall,winter,spring}report$ ls
fallreport winterreport springreport
The data in input and output operations is organized like a file. Data input at the keyboard is placed in a data stream arranged as a continuous set of bytes. Data output from a command or program is also placed in a data stream and arranged as a continuous set of bytes. This input data stream is referred to in Linux as the standard input, while the output data stream is called the standard output. There is also a separate output data stream reserved solely for error messages, called the standard error (see the section on the standard error later in this chapter).
Because the standard input and standard output have the same organization as that of a file, they can easily interact with files. Linux has a redirection capability that lets you easily move data in and out of files. You can redirect the standard output so that, instead of displaying the output on a screen, you can save it in a file. You can also redirect the standard input away from the keyboard to a file, so that input is read from a file instead of from your keyboard.
When a Linux command is executed that produces output, this output is placed in the standard output data stream. The default destination for the standard output data stream is a device—in this case, the screen. Devices, such as the keyboard and screen, are treated as files. They receive and send out streams of bytes with the same organization as that of a byte-stream file. The screen is a device that displays a continuous stream of bytes. By default, the standard output will send its data to the screen device, which will then display the data.
For example, the ls command generates a list of all filenames and outputs this list to the standard output. Next, this stream of bytes in the standard output is directed to the screen device. The list of filenames is then printed on the screen. The cat command also sends output to the standard output. The contents of a file are copied to the standard output whose default destination is the screen. The contents of the file are then displayed on the screen.
Suppose that instead of displaying a list of files on the screen, you would like to save this list in a file. In other words, you would like to direct the standard output to a file rather than the screen. To do this, you place the output redirection operator, > (greater-than sign), and the name of a file on the command line after the Linux command. Table 8-4 lists the different ways you can use the redirection operators. In the next example, the output of the ls command is redirected from the screen device to a file:
|
Command |
Execution |
|
ENTER |
Execute a command line. |
|
; |
Separate commands on the same command line. |
|
command\ |
Enter backslash before carriage return to continue entering a command on the next line. |
|
'command' |
Execute a command. |
|
$(command) |
Execute a command. |
|
Special Characters |
Execution |
|
* |
Match on any set of characters. |
|
? |
Match on any single characters. |
|
[] |
Match on a class of possible characters. |
|
\ |
Quote the following character. Used to quote special characters. |
|
Redirection |
Execution |
|
command > filename |
Redirect the standard output to a file or device, creating the file if it does not exist and overwriting the file if it does exist. |
|
command < filename |
Redirect the standard input from a file or device to a program. |
|
command >> filename |
Redirect the standard output to a file or device, appending the output to the end of the file. |
|
command >! filename |
In the C shell and the Korn shell, the exclamation point forces the overwriting of a file if it already exists. This overrides the noclobber option. |
|
command 2> filename |
Redirect the standard error to a file or device in the Bourne shell. |
|
command 2>> filename |
Redirect and append the standard error to a file or device in the Bourne shell. |
|
command 2>&1 |
Redirect the standard error to the standard output in the Bourne shell. |
|
command >& filename |
Redirect the standard error to a file or device in the C shell. |
|
Pipes |
Execution |
|
command | command |
Pipe the standard output of one command as input for another command. |
|
command |& command |
Pipe the standard error as input to another command in the C shell. |
$ ls -l *.c > programlist
The redirection operation creates the new destination file. If the file already exists, it will be overwritten with the data in the standard output. You can set the noclobber feature to prevent overwriting an existing file with the redirection operation. In this case, the redirection operation on an existing file will fail. You can overcome the noclobber feature by placing an exclamation point after the redirection operator. You can place the noclobber command in a shell configuration file to make it an automatic default operation (see Chapter 10). The next example sets the noclobber feature for the BASH shell and then forces the overwriting of the oldletter file if it already exists:
$ set -o noclobber
$ cat myletter >! oldletter
Although the redirection operator and the filename are placed after the command, the redirection operation is not executed after the command. In fact, it is executed before the command. The redirection operation creates the file and sets up the redirection before it receives any data from the standard output. If the file already exists, it will be destroyed and replaced by a file of the same name. In effect, the command generating the output is executed only after the redirected file has been created.
In the next example, the output of the ls command is redirected from the screen device to a file. First the ls command lists files, and in the next command, ls redirects its file list to the listf file. Then the cat command displays the list of files saved in listf. Notice the list of files in listf includes the listf filename. The list of filenames generated by the ls command includes the name of the file created by the redirection operation—in this case, listf. The listf file is first created by the redirection operation, and then the ls command lists it along with other files. This file list output by ls is then redirected to the listf file, instead of being printed on the screen.
$ ls
mydata intro preface
$ ls > listf
$ cat listf
mydata intro listf preface
|
Tip |
Errors occur when you try to use the same filename for both an input file for the command and the redirected destination file. In this case, because the redirection operation is executed first, the input file, because it exists, is destroyed and replaced by a file of the same name. When the command is executed, it finds an input file that is empty. |
You can also append the standard output to an existing file using the >> redirection operator. Instead of overwriting the file, the data in the standard output is added at the end of the file. In the next example, the myletter and oldletter files are appended to the alletters file. The alletters file will then contain the contents of both myletter and oldletter.
$ cat myletter >> alletters
$ cat oldletter >> alletters
Many Linux commands can receive data from the standard input. The standard input itself receives data from a device or a file. The default device for the standard input is the keyboard. Characters typed on the keyboard are placed in the standard input, which is then directed to the Linux command. Just as with the standard output, you can also redirect the standard input, receiving input from a file rather than the keyboard. The operator for redirecting the standard input is the less-than sign, <. In the next example, the standard input is redirected to receive input from the myletter file, rather than the keyboard device. The contents of myletter are read into the standard input by the redirection operation. Then the cat command reads the standard input and displays the contents of myletter.
$ cat < myletter
hello Christopher
How are you today
$
You can combine the redirection operations for both standard input and standard output. In the next example, the cat command has no filename arguments. Without filename arguments, the cat command receives input from the standard input and sends output to the standard output. However, the standard input has been redirected to receive its data from a file, while the standard output has been redirected to place its data in a file.
$ cat < myletter > newletter
You may find yourself in situations in which you need to send data from one command to another. In other words, you may want to send the standard output of a command to another command, not to a destination file. Suppose you want to send a list of your filenames to the printer to be printed. You need two commands to do this: the ls command to generate a list of filenames and the lpr command to send the list to the printer. In effect, you need to take the output of the ls command and use it as input for the lpr command. You can think of the data as flowing from one command to another. To form such a connection in Linux, you use what is called a pipe. The pipe operator, |, (vertical bar character) placed between two commands forms a connection between them. The standard output of one command becomes the standard input for the other. The pipe operation receives output from the command placed before the pipe and sends this data as input to the command placed after the pipe. As shown in the next example, you can connect the ls command and the lpr command with a pipe. The list of filenames output by the ls command is piped into the lpr command.
$ ls | lpr
You can combine the pipe operation with other shell features, such as file expansion characters, to perform specialized operations. The next example prints only files with a .c extension. The ls command is used with the asterisk and ".c" to generate a list of filenames with the .c extension. Then this list is piped to the lpr command.
$ ls *.c | lpr
In the preceding example, a list of filenames was used as input, but what is important to note is pipes operate on the standard output of a command, whatever that might be. The contents of whole files or even several files can be piped from one command to another. In the next example, the cat command reads and outputs the contents of the mydata file, which are then piped to the lpr command:
$ cat mydata | lpr
Linux has many commands that generate modified output. For example, the sort command takes the contents of a file and generates a version with each line sorted in alphabetic order. The sort command works best with files that are lists of items. Commands such as sort that output a modified version of its input are referred to as filters. Filters are often used with pipes. In the next example, a sorted version of mylist is generated and piped into the more command for display on the screen. Note that the original file, mylist, has not been changed and is not itself sorted. Only the output of sort in the standard output is sorted.
$ sort mylist | more
The standard input piped into a command can be more carefully controlled with the standard input argument, -. When you use the dash as an argument for a command, it represents the standard input.
When you execute commands, an error could possibly occur. You may give the wrong number of arguments, or some kind of system error could take place. When an error occurs, the system issues an error message. Usually such error messages are displayed on the screen, along with the standard output. Linux distinguishes between standard output and error messages, however. Error messages are placed in yet another standard byte stream, called the standard error. In the next example, the cat command is given as its argument the name of a file that does not exist, myintro. In this case, the cat command simply issues an error:
$ cat myintro
cat : myintro not found
$
Because error messages are in a separate data stream from the standard output, error messages still appear on the screen for you to see even if you have redirected the standard output to a file. In the next example, the standard output of the cat command is redirected to the file mydata. However, the standard error, containing the error messages, is still directed to the screen.
$ cat myintro > mydata
cat : myintro not found
$
You can redirect the standard error, as you can the standard output. This means you can save your error messages in a file for future reference. This is helpful if you need a record of the error messages. Like the standard output, the standard error has the screen device for its default destination. However, you can redirect the standard error to any file or device you choose using special redirection operators. In this case, the error messages will not be displayed on the screen.
Redirection of the standard error relies on a special feature of shell redirection. You can reference all the standard byte streams in redirection operations with numbers. The numbers 0, 1, and 2 reference the standard input, standard output, and standard error, respectively. By default, an output redirection, >, operates on the standard output, 1. You can modify the output redirection to operate on the standard error, however, by preceding the output redirection operator with the number 2. In the next example, the cat command again will generate an error. The error message is redirected to the standard byte stream represented by the number 2, the standard error.
$ cat nodata 2> myerrors
$ cat myerrors
cat : nodata not found
$
You can also append the standard error to a file by using the number 2 and the redirection append operator, >>. In the next example, the user appends the standard error to the myerrors file, which then functions as a log of errors:
$ cat nodata 2>> myerrors
In Linux, you not only have control over a command's input and output, but also over its execution. You can run a job in the background while you execute other commands. You can also cancel commands before they have finished executing. You can even interrupt a command, starting it again later from where you left off. Background operations are particularly useful for long jobs. Instead of waiting at the terminal until a command has finished execution, you can place it in the background. You can then continue executing other Linux commands. You can, for example, edit a file while other files are printing. The background commands, as well as commands to cancel and interrupt jobs, are listed in Table 8-5.
|
Background Jobs |
Execution |
|
& |
Execute a command in the background. |
|
fg %jobnum |
Bring a command in the background to the foreground or resume an interrupted program. |
|
bg |
Place a command in the foreground into the background. |
|
CTRL-Z |
Interrupt and stop the currently running program. The program remains stopped and waiting in the background for you to resume it. |
|
notify %jobnum |
Notify you when a job ends. |
|
kill %jobnum |
Cancel and end a job running in the background. |
|
jobs |
List all background jobs. The jobs command is not available in the Bourne shell, unless it is using the jsh shell. |
|
ps |
List all currently running processes, including background jobs. |
|
at time date |
Execute commands at a specified time and date. The time can be entered with hours and minutes and qualified as A.M. or P.M. |
You execute a command in the background by placing an ampersand on the command line at the end of the command. When you do so, a user job number and a system process number are displayed. The user job number, placed in brackets, is the number by which the user references the job. The system process number is the number by which the system identifies the job. In the next example, the command to print the file mydata is placed in the background:
$ lpr mydata &
[1] 534
$
You can place more than one command in the background. Each is classified as a job and given a name and a job number. The command jobs lists the jobs being run in the background. Each entry in the list consists of the job number in brackets, whether it is stopped or running, and the name of the job. The + sign indicates the job currently being processed, and the - sign indicates the next job to be executed. In the next example, two commands have been placed in the background. The jobs command then lists those jobs, showing which one is currently being executed.
$ lpr intro &
[1] 547
$ cat *.c > myprogs &
[2] 548
$ jobs
[1] + Running lpr intro
[2] - Running cat *.c > myprogs
$
After you execute any command in Linux, the system tells you what background jobs, if you have any running, have been completed so far. The system does not interrupt any operation, such as editing, to notify you about a completed job. If you want to be notified immediately when a certain job ends, no matter what you are doing on the system, you can use the notify command to instruct the system to tell you. The notify command takes a job number as its argument. When that job is finished, the system interrupts what you are doing to notify you the job has ended. The next example tells the system to notify the user when job 2 has finished:
$ notify %2
You can bring a job out of the background with the foreground command, fg. If only one job is in the background, the fg command alone will bring it to the foreground. If more than one job is in the background, you must use the job's number with the command. You place the job number after the fg command, preceded with a percent sign. A bg command also places a job in the background. This command is usually used for interrupted jobs. In the next example, the second job is brought back into the foreground. You may not immediately receive a prompt again because the second command is now in the foreground and executing. When the command is finished executing, the prompt appears and you can execute another command.
$ fg %2
cat *.c > myprogs
$
If you want to stop a job running in the background, you can force it to end with the kill command. The kill command takes as its argument either the user job number or the system process number. The user job number must be preceded by a percent sign, %. You can find out the job number from the jobs command. In the next example, the jobs command lists the background jobs; then job 2 is canceled:
$ jobs
[1] + Running lpr intro
[2] - Running cat *.c > myprogs
$ kill %2
You can also cancel a job using the system process number, which you can obtain with the ps command. The ps command displays a great deal more information than the jobs command does. The next example lists the processes a user is running. The PID is the system process number, also known as the process ID. TTY is the terminal identifier. The time is how long the process has taken so far. COMMAND is the name of the process.
$ ps
PID TTY TIME COMMAND
523 tty24 0:05 sh
567 tty24 0:01 lpr
570 tty24 0:00 ps
You can then reference the system process number in a kill command. Use the process number without any preceding percent sign. The next example kills process 567:
$ kill 567
You can suspend a job and stop it with the CTRL-Z key. This places the job to the side until it is restarted. The job is not ended; it merely remains suspended until you want to continue. When you're ready, you can continue with the job in either the foreground or the background using the fg or bg command. The fg command restarts a suspended job in the foreground. The bg command places the suspended job in the background.
At times, you may need to place a currently running job in the foreground into the background. However, you cannot move a currently running job directly into the background. You first need to suspend it with CTRL-Z, and then place it in the background with the bg command. In the next example, the current command to list and redirect .c files is first suspended with CTRL-Z. Then that job is placed in the background.
$ cat *.c > myprogs
^Z
$ bg
مهم ترین ویروس ها و شایع ترین کدهای مخرب رایانه یی در هفته گذشته معرفی شدند. کرم رایانه یی IRCBot.CNK به نحوی طراحی شده که با اتصال به یک سرورIRC، دستورات تخریبی منتشرکننده خود را از دوردست دریافت و آن را به بهترین شکل اجرا کند. این فرمان ها می توانند شامل کنترل ترافیک اطلاعاتی سیستم، دانلود و نصب فایل از طریق اینترنت و حتی به روزرسانی ویروس و قابلیت های مخرب آنها باشد. همچنین IRCBot.CNK قادر است پردازش مخرب خود را در فهرست پردازش های امن و مورد تایید فایروال ویندوز قرار دهد و به سرعت در سرتاسر شبکه های محلی منتشر شود. بر اساس اعلام پاندا، نقص امنیتی MS04-011 در سیستم های عامل ویندوز مهم ترین راه نفوذ این کرم محسوب می شود بنابراین سیستم های آسیب پذیری که اصلاحیه های ترمیمی مایکروسافت را دریافت نمی کنند، در معرض حملات شدیدتر IRCBot قرار دارند. انتشار کرم رایانه یی Autorun.IYQ در هفته گذشته، بسیاری از کاربران اینترنت را با مشکل مواجه کرد. ایجاد تغییر در رجیستری ویندوز، جلوگیری از دسترسی کاربر به حالتSafe Mode، جلوگیری از ذخیره فایل و اطلاعات در درایوهای جانبی سیستم و غیرفعال کردن برخی از نرم افزارها و پردازش های امنیتی در سیستم، تنها بخشی از فرآیند های تخریبی این کرم به حساب می آیند. راه غیرفعال کردن این ویروس استفاده از ابزاری مانند USB Vaccine است که قابلیت اجرای خودکار فایل ها و کدها را حذف می کنند. و اما Joleee.F یکی دیگر از بدافزارهای مهم در هفته گذشته، از طریق هرزنامه های تبلیغاتی منتشر می شود. این کرم رایانه یی شما را به طور خودکار به وب سایت هایی هدایت می کند که از آنها برای ارسال هرزنامه یا انتشار بیشتر آلودگی استفاده می شود . کاهش پهنای باند اینترنت و نمایش ناخواسته پیغام ها و پنجره های پی در پی از خصوصیت های آزارنده Joleee.F محسوب می شوند. همچنین با ظهور نخستین موج از حملات اینترنتی در روزهای گذشته و با سوءاستفاده از اتفاقات بزرگ منطقه یی یا جهانی، کارشناسان امنیتی نسبت به آلودگی قریب الوقوع بسیاری از رایانه های خانگی و شبکه های محلی هشدار دادند چرا که در روزهای آینده جام جهانی فوتبال و انتخابات ریاست جمهوری ایران عناوین خبری خواهند بود که بسیاری از لینک های آلوده، فایل های مخرب و هرزنامه ها با سوءاستفاده از آن، کاربران اینترنت را هدف قرار می دهند بنابراین به کلیه کاربران اینترنت توصیه شده است از کلیک روی لینک ها و دانلود فایل های مشکوک و نیز باز کردن نامه های ناشناس خودداری کنند و سیستم عامل و نرم افزارهای امنیتی خود را به روز نگاه دارند .
پروتکل rfb 1 یک پروتکل ساده است که برای دسترسی از راه دور به واسط های گرافیکی کاربر استفاده می شود و همان طور که از نامش پیدا است، در سطح فریم بافر کار می کند. این پروتکل قابل اعمال بر همه برنامه های کاربردی و سیستم هایی است که به نوعی با پنجره ها سر و کار دارد. از میان این سیستم ها می توان به 11x ، ویندوز و مکینتاش اشاره کرد. rfb پروتکلی است که در محاسبات شبکه های مجازی ( (vnc 2 نامیده می شود و کاربرد دارد. هرچند rfb در ابتدا به عنوان یک پروتکل نسبتا ساده به وجود آمد، به مرور زمان گسترش یافت و امکانات مختلفی به آن افزوده شد. گسترش rfb امکانات انتقال فایل و فشرده سازی به روش های پیچیده را امکان پذیر ساخت و امنیت سیستم را افزایش داد. برای حفظ سازگاری این سیستم با پیاده سازی مختلفی کلاینت و سرور vnc ، کلاینت ها و سرورها باید بتوانند با استفاده از rfb با یکدیگر ارتباط برقرار کنند و اطلاعات را رد و بدل کنند. پروتکل rfb تضمین می کند که مناسب ترین انتخاب های فشرده سازی و تامین امنیت را که هر دو سیستم کلاینت و سرور قادر به پشتیبانی از آن باشند را به کار گیرد. پیدایش rfb به سال 1998 باز می گردد. rfb در ابتدا به عنوان یک فناوری ساده برای نمایش از راه دور سیستم ها به وجود آمد. در حقیقت کاربرد اولیه آن ساده کردن فناوری های موجود در آن زمان بود. به زودی با توسعه vnc ، پروتکل rfb یک کاربرد ثانویه و مهم تر پیدا کرد. vnc به عنوان یک نرم افزار کد باز منتشر شد و rfb را به عنوان پروتکل استاندارد به کار گرفت. یکی از امتیازات جالب توجه rfb این است که توسعه دهندگان کد می توانند انواع مختلفی از روش های رمزگذاری و سیستم های امنیتی را به دلخواه خود به سیستم rfb موجود اضافه کنند. تنها تغییر لازم در این حالت، رزرو کردن شماره شناسایی منحصربه فرد است تا به این ترتیب، شماره های شناسایی تداخل پیدا نکنند. تداخل شماره ها می تواند در طول فرایند معارفه3 ایجاد اشکال کند و منجر به قطع ارتباط شود. نسخه کنونی rfb به نام 3.8 rfb شناخته شده و در ماه ژوئن سال 2007 منتشر شده است. اغلب سیستم های دسترسی از راه دور که با آنها آشنایی داریم قادر به کار با برنامه های گرافیکی یا برنامه های دارای پنجره نیستند و تنها با فایل های متنی و خط دستور سر و کار دارند. rfb به سبب امکان ایجاد ارتباط با این گونه نرم افزارها از جایگاه ویژه ای برخوردار است. با این حال rfb نیز خالی از اشکال نیست و نیازمند اعمال یک سری تغییرات است. مهم ترین محدودیت کنونی rfb انتقال داده ها به حافظه موقت4 است. البته در حال حاضر هیچ راهی برای انتقال داده های متنی که به فرمتی به غیر از character set 1latin- نوشته شده باشند، وجود ندارد.
شايد امروزه باور اين موضوع كه فرهنگها و خردهفرهنگهاي جديدي توسط اينترنت، ماهواره و تكنولوژي نوين وارد تعاملات جهاني شده، سخت نباشد. تعاريف جديد از دوستي، اخلاق و رفتار، هنر، دين، ملت، تعلق خاطر، ارتباطات و در مجموع آنچه در قالب فرهنگ و تعاملات بشري گنجانده ميشود، ديگر لزوما از سوي روشنفكران و انديشمندان، آن هم توسط روزنامه و كتاب طراحي و ارائه نميشود، بلكه بيش از آن، توسط تايپ و كليك آن هم عموما به وسيله كاربران جوان اينترنت نشر و بسط داده ميشوند. |

شرکت مایکروسافت گزارشهایی را که در آن اعلام شده بود نسخه کاندید سیستمعامل Windows 7 به صورت عمومی در ماه می برای بارگذاری عرضه میشود ،را تایید کرد.
صفحه ویژه Windows 7 Release Candidate (RC) روی سایت اینترنتی TechNet مایکروسافت تاریخ “می ۲۰۰۹″ را برای عرضه این سیستمعامل اعلام کرده و جزئیات مختصری را در این مورد توضیح داده است.
در این صفحه که نرمافزار یاد شده برای بارگذاری قرار خواهد گرفت، آمده است: «برای بارگذاری Windows 7 RC نیازی به اقدامات سریع و هجومی نیست. نسخه RC این سیستمعامل حداقل تا ژوئن ۲۰۰۹ برای بارگذاری روی اینترنت باقی خواهند ماند و ما تعداد این محصول خود را برای بارگذاری محدود نمیکنیم محدودیتی برای تعداد دفعات بارگذاری ایجاد نمیکنیم. بر این اساس شما زمان زیادی برای دریافت آن خواهید داشت».
زمانی که مایکروسافت قصد عرضه نسخه بتای عمومی Windows 7 را در ماه ژانویه است، داشت، “استیو بالمر”(Steve Ballmer) مدیرعامل این شرکت اعلام کرد که این محصول برای “دوره زمانی محدود” روی اینترنت قرار خواهد گرفت و مایکروسافت خاطر نشان کرد که ۵/۲ میلیون نسخه از آن را برای بارگذاری عرضه خواهد کرد. این مسئله باعث شد تا در نخستین روز عرضه نسخه بتای Windows 7 کاربران برای بارگذاری آن هجوم بیاورند و در نهایت، سرورهای مایکروسافت توان پاسخگویی را نداشته باشند و از کار بیفتند. مایکروسافت پس از تقویت زیرساختهای خود از فردای آن روز امکان بارگذاری نسخه بتای Windows 7 را مجدد فراهم کرد.
به گفته مایکروسافت، Windows 7 RC در یک تاریخ متفاوت نسبت به نسخه بتا غیرفعال خواهد شد. در حالی که تاریخ غیرفعال شده ن نسخه بتای سیستمعامل Windows 7 اول آگوست ۲۰۰۹ اعلام شده، نسخه RC در اول ژوئن ۲۰۱۰ از کار میافتد.
شرکت مایکروسافت نسخههای ویژهای از Windows 7 RC را برای کاربران ساکن در بریتانیا، آلمان، ژاپن، فرانسه و اسپانیا عرضه کرده و امکان بارگذاری نسخههای ۳۲ و ۶۴ بیتی آن را فراهم کرده است.
استفاده از ماوس در کامپیوتراز سال ۱۹۸۴ و همزمان با معرفی مکینتاش آغاز گردید . با عرضه ماوس ، کاربران قادر به استفاده از سیستم و نرم افزارهای مورد نظر خود با سهولت بیشتری شدند. امروزه ماوس دارای جایگاه خاص خود است . ماوس قادر به تشخیص حرکت و کلیک بوده و پس از تشخیص لازم ، اطلاعات مورد نیاز برای کامپیوتر ارسال تا عملیات لازم انجام گیرد.
روند شکل گیری ماوس
درسیستم های اولیه نیازی به استفاده از ماوس احساس نمی گردید، چون کامپیوترهای آن زمان دارای اینترفیسی مشابه ماشین های تله تایپ و یا کارت پانج برای ورود اطلاعات بودند. ترمینال های متنی اولیه، چیزی بیشتر از یک تله تایپ شبیه سازی شده نبودند ( استفاده از صفحه نمایشگر در عوض کاغذ ). چندین سال طول کشید تا کلیدهای پیکانی در اغلب ترمینال ها مورد استفاده قرار گرفتند( اواخر ۱۹۶۰ و اوایل ۱۹۷۰ ) . مدادهای نوری تمام صفحه اولین چیزی بودند که از قابلیت های واقعی کلیدهای پیکانی استفاده کردند.
مداد های نوری برای سالیان زیادی بر روی ماشین های متفاوت ، بعنوان یک دستگاه اشاره ای استفاده می گردیدند. Joysticks و دستگاه هائی دیگر در این خصوص در سال ۱۹۷۰ رایج شده بودند. زمانیکه ماوس بهمراه کامپیوترهای مکینتاش ارائه گردید یک موفقیت بزرگ بدست آمده بود.عملکرد ماوس کاملا” طبیعی بود. قیمت ماوس ارزان و فضای زیادی را اشغال نمی کرد. همزمان با حمایت سیستم عامل ها از ماوس ، استفاده از ماوس رشد بیشتری پیدا کرد. زمانیکه ویندوز ۳/۱ از یک رابط گرافیکی بعنوان استاندارد استفاده کرد، ماوس بعنوان یک وسیله و اینترفیس بین انسان - کامپیوتر، جایگاه خاص خود را کسب نمود.

ورود لپ تاپ زنانه به بازار
شرکت Acer از ساخت کامپیوتر قابل حمل جدیدی خبر داده که به صورت اختصاصی برای خانم ها طراحی شده و قرار است در مرحله نخست وارد بریتانیا شود.
به گزارش بخش خبر شبکه فن آوری اطلاعات ایران،از سايت http://www.khodkar.ir ،این لپ تاپ بسیار سبک 1200 Ferrari نام گرفته است و افراد می توانند در نمایشگر 1/12 اینچی آن که از نوع LED است، تصاویر را با کیفیت بسیار بالایی مشاهده کنند.این لپ تاپ به پردازنده AMD Turion X2 Ultra مجهز شده است و می تواند از رم های بیش از چهار گیگابایتی نیز پشتیبانی کند.هارددیسک این لپ تاپ از نوع SATA است و به گفته شرکت سازنده قابلیت پشتیبانی از فناوری ارتباطی بلوتوث و شبکه بی سیم Wi-Fi را نیز دارد.برای این لپ تاپ قابلیت شناسایی اثر انگشت نیز درنظر گرفته شده و شرکت Acer روی آن یک محافظ مقاوم را نصب کرده است.هنوز قیمت این لپ تاپ زنانه مشخص نشده است و Acer طی سه ماهه دوم سال جاری میلادی آن را در دیگر کشورها نیز عرضه خواهد کرد.
دخترا برن حالشو ببرن.![]()
اولین دوره ی تخصصی لینوکس در ایران برگزار شد
اولین دوره تخصصی آموزش لینوکس به صورت در قالب یک کمپینگ 6 روزه توسط شرکت فناوران آنیسا، نماینده مورد تائید آموزشی و مدرسین رسمی بیناللملی LPI در ایران، با همکاری شرکت اراسل افزار عضو هلدینگ نفیس برگزار شد.
به گزارش بخش خبر شبکه فن آوری اطلاعات ایران،از سايت http://www.khodkar.ir ،شرکتکنندگان این کارگاه آموزشی که در محل پژوهشکده فناوری اطلاعات دانشــکده تربیت مدرس تهران در حال برگزاری است، ضمن آشنایی با مفاهیم زیر بنایی سطح اول مدارک لینوکس موسوم بهLPIC-1 بصورت کاملاً کاربردی در لابراتوار به انجام تمرینات عمـــــلی مطابق سرفصلهای رسمی دوره فوق میپردازند.
گفتنی است تدریس اولین دوره LPIC-1 توسط مهــــدی امیــــری کردستانی، دارنده مدرک استادی (LCI) و یکی از متخصصین متنباز کشــــور انجام میشود. وی از سابقه زیادی در پروژههای متعدد ملی متنباز کشور برخوزدار میباشد که از جمله آنها میتوان به مدیریت فنی پروژه پورتال ملی iran.ir اشاره کرد. او در حال حاضر مدیرعامل شرکت فناوران آنیسا میباشد.
لازم به ذکر است برای اولین بار در ایران، امکان برگزاری آزمونهای رسمی لینوکس نیز برای تمامی داوطلبین داخل کشور فراهم گردیده است که علاقهمندان میتوانند برای کسب اطلاعات تکمیلی به آدرس اینترنتی http://www.lpir.org مراجعه کنند.
نظر که تو صدره.یادتون نره.![]()
ارزش بازار جهانی آی تی به چهار ترلیون دلار می رسد.
نتايج يك بررسي جديد نشان مي دهد بازار جهاني فناوري اطلاعات و ارتباطات به سرعت در حال گسترش است و ارزش جهاني آن تا سال 2016 به 4 تريليون دلار ميرسد.
به گزارش بخش خبر شبکه فنآوری اطلاعات ایران،از سایت خبرگزاری فارس، گسترش شبكه جهاني اينترنت و اتكاي روزافزون شركت هاي تجاري به شبكه هاي اطلاع رساني از جمله عوامل اصلي اين رونق بي سابق در صنعت جهاني آي سي تي خواهد بود.
Yankee Group پيش بيني كرده كه عليرغم تداوم بحران جهاني اقتصادي در سال هاي آينده صنعت آي سي تي روند رشد خود را ادامه خواهد داد و اين روند زندگي مردم در سراسر جهان را متحول خواهد كرد.
كاهش قيمت سخت افزارها و نرم افزارهاي مختلف و ارتقاي كيفيت و سهولت استفاده از آنها، كم رونق شدن نرم افزارهاي آفلاين و امكان دسترسي به بسياري از امكانات نرم افزاري به صورت شبكه اي، افزايش تنوع و تعداد وسايل قابل اتصال به شبكه هاي رايانه اي از جمله ديگر پيش بيني هاي اين موسسه پژوهشي است.
بر اساس اين گزارش ارزش جهاني بازار ICT هم اكنون 2.2 تريليون دلار است كه دو برابر شدن اين رقم در 7 سال آينده بسيار اميدوار كننده است.
چه خبر با حالی بود.مگه نه.نظر بدین.![]()