UNIX Shell commands

Source: Internet
Author: User

1. Output inbound Steering

In UNIX, each process has three special file descriptor standard inputs.
(Standard input), standard output, and standard
Error ). The three normally accept terminal input, which is displayed by terminal. However
UNIX provides users with the ability to replace these standard output devices with common archives or pipe. In
In the tcsh, you can use ">" and "<" to output the inbound and outbound traffic.

Output redirection:
Command> file

You can switch the output result of a command to an archive to store the command
.

However, note that if the file already exists in the system, the file will be overwritten. That is
The content of the original file will disappear.

Command> & file

Same as>, but this format indicates that the standard error is switched together. In UNIX,
Standard error is used to show the occurrence of error in programer.
When not switched, the result of standard output will be switched to file, while standard output
The error result is still displayed on terminal.

Command> file

This lattice indicates that the result of standard output is appended to file. If the file already exists
In the system, the result of standard output is added to the end of the file.
Otherwise, the file is enabled and the standard output result is saved to file.
.

Command >>& filE

Same as above. However, this format means that a standard error is appended to a file.

Input redirection
Command <file

Generally, a program needs to input data from the terminal, and you can unify the information entered by the program.
Archive, and input with the redirection.

Set ignoreeeof
As a result, the switch to the output may cause the risk of overwrite existing files. csh and tcsh provide
To avoid this problem.

After you execute set ignoreeeof, if an output is redirected to an existing file, it will
Sends an existing file message. However, if the set
Ignoreeeof, when you want to append a non-existent file, an error will appear
Messege.

However, if we want to migrate to an existing file or append one
What should I do when there is a non-existent file?

You only need to add an exclamation point after ">" "> &" ">" "> "! ", Become">! "...
Yes.

2. Pipe

As mentioned above, Pipe is also used to replace the standard output with the standard device, as shown in
In this way, the output of a program can be connected to the input of another program. The syntax is as follows:

Command1 | command2 [| command3...]
Command1 | & command2 [| & command3...] <--- pipe with standard error


3. Prospects and background

Under sh, a new process can be divided by the symbols after command; and
Do not foreground or background. See the following syntax.

Command

This indicates to generate a foreground process. You must wait until it ends before you can start another
.

Command &

This indicates that a background process is generated, and it will give you a message similar to the following:

[1] 21304

Then the next prompt is displayed for you to give the next command. Then
At the end of the process, I will give you the following message to tell you how to execute the process
The line is complete.

[1] Done command

Command1; command2; command3

This means that you require the system to execute command1 command2 command3 three commands consecutively,
Command2 has to wait for command1, command3 has to wait for command2, and you have to wait
Commands can be executed only after command3 is executed.

Command1 & command2 & command3 &

This means that you require the system to execute command1 command2 command3 three commands consecutively,
These three commands are executed in the background and do not need to wait for each other.

Fg and bg

You may ask if a processed process can be changed from the foreground to the background or from the background.
What about the future?

Yes. For a process to be executed in the foreground, you can press Ctl-Z to pause the process,
The system will send you a message:

Sushortded

Then the prompt number is displayed. In this case, you can use fg to restore the foreground, or press bg to change it
Background execution.

If there is a background process, you can use the fg command to call it to the foreground.
. First, you need the jobs command to check the current number of proesses in the background.
It displays the job id to decide to put that process into the foreground. For example

% Fg % 3 # Place the third job in foreground.

4. alias

In csh and tcsh, the alias function is provided so that users can
Commands are stored in other names, but you do not need to add a "$" in front of them as if you were storing variables ".

Alias format:
Alias aliasname string ....
Alias aliasname string! * String

In the previous format, aliasname is directly used to replace the subsequent string, and if there is any
After which the following argument will appear. For example:

% Alias la ls-Fa

In this example, la. is equivalent to ls-F.. However, if this is true, it is not enough.
A format. In the following format! * Indicates all parameters that will appear after aliasname in the future,
For example:

% Alias dir ls-Flag! * | More

In this example, dir doc is equivalent to ls-Flag doc | more, which provides a larger design for the user.
.

5. Initial tcsh settings

Tcsh has two initial files: $ HOME/. tcshrc and $ HOME/. login.

When every tcsh is enabled, it will execute all commands in. tcshrc, So you
All alias variable settings can be placed in. tcshrc. When tcsh is started
The initial settings for your environment will be automatically executed.

. Login is executed only when tcsh itself is a login shell. Most of it is used to set
Set some commands that only need to be executed during login, such as setting environment variables.
After the setting, as long as the sub-process gets its environment, it does not have to be enabled every time the shell
Re-run.

Tcsh has another end configuration file, called. logout, that ends at every login shell,
The method for editing the action to be executed by logout is exactly the same as that of. login. tcshrc.

Source command

If you want to re-execute the. tcshrc content, you can use the source command.
When all the content in the file is re-entered in the Command column. As follows:

% Source. login

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.