Shell Application Tips

Source: Internet
Author: User

Shell Application Tips

The shell is a command interpreter, a layer of interaction between the kernel and the kernel.

There are many kinds of shells, the one with the prompt that belongs to /bin/bash, and almost all Linux Systems default to this shell. , it is convenient to do some management, usually using this shell.

Bash Application Tips

command to be padded

command completion allows the user to enter the file name or the beginning of the command name after a number of letters, press <Tab> to fill in the file name, command name, if the file name or command name starting with this is not unique, click the Tab Key does not respond, Press second to list out all. If the only direct complement.

Command history

command History allows users to browse previously entered commands and invoke them again, with the historical command to display a list of commands , !+ command numbers to execute, press the arrow keys ↑ and ↓ to find previously executed commands

Clear Clear Screen ctrl+l(shortcut key)

Ctrl+u Delete all characters before the cursor

Command aliases

Command alias definition:

Example:alias COPY=CP

Alias xrm="rm-r"

command to write directly with double quotes with option parameters

View alias information:alias

Delete alias information:unalias copy

Can make the operation easier and simpler

alias lists aliases directly

Each user-defined alias can only be used on its own.

input / output redirection

same Standard Like I/O , theShell Pre-defines 3 file descriptors (0,1,2) for each process . respectively corresponds to:

0 (STDIN) standard input keyboard

1 (STDOUT) standard output display

2 (STDERR) standard error output display

Redirection indicates that input is not from the keyboard, the output is not from the monitor, the standard error output is not from the monitor

> or >> output redirection

Example:ls-l/temp>/tmp.msg redirected to the root directory under tmp.msg

Date >>/tmp.msg

Error output redirection

Example:cp-r/usr/backup/usr.bak 2>/bak.error

The so-called redirect is to output the content that was originally displayed on the monitor to a file.

Date View System Current time

> will empty the contents of the file, which may not be what we want.

so we can use >> to add

Input redirection refers to input not from the keyboard but from other places

Error output redirection

Example:cp-r/usr/backup/usr.bak 2>/bak.error

USR(UNIX system resources, very important, sometimes need to backup, this command to perform a backup, if an error writes 2 to bak.error, Succeed in doing nothing)

What the hell is 2?

In fact 0> 0>> 1< This is the input, output redirection standard notation,0,1 can be omitted.

2> at this time 2 can not be omitted, if omitted is the same as output redirection

Pipeline

Pipe: Tells the output of one command to another command, as input to another command

How to use: Command 1| Command 2| Command 3.....| Command N

Example:

Ls-l/etc | more paging Browse the result of the previous command execution, Space page, enter the line,q exit

Ls-l/etc | grep init extracts the line related to the keyword and lists it

Ls-l/etc | grep init | Wc-l How many files with init are included in the directory etc

The function of a pipe is to make a few simple commands play a big role

Wc-l file name shows how many lines this file has

Command connector

Each of the commands in the interval is executed sequentially, such as when writing a system's scheduled task, with several commands executing sequentially in the background. Compile the kernel is to knock on the several commands, a few command interval long, it is available at this time, so that they execute, and add a false judgment, the error is written into the log.

&&

Command1 && Comand2

Success Execution

failed do not execute

There is a logic and relationship between the execution of the front and back commands, and only after the && command executes successfully, the command behind it is executed .

||

Command1 | | Command2

Success do not execute

failed Execution

the execution of a front and back command has a logical or relationship, only | | after the execution of the previous command failed, the command after him was executed

Command substitutions

Command substitution: Tells the output of one command as a parameter to another command

format: Command 1 ' command 2 ' ( keypad number One left of small apostrophe )

Example:ls-l ' which touch '

Shell Application Tips

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.