An obscure shell command

Source: Internet
Author: User

1. REDIRECT Symbol

> Output redirected to a file or device overwriting the original file
>! Output redirected to a file or device forcing overwriting of the original file
>> output redirected to a file or device to append the original file
< redirect input to a program

2. Standard error redirection symbols

2> redirects a standard error output to a file or device overwriting the original file B-shell
2>> redirect a standard error output to a file or device appended to the original file
2>&1 redirect a standard error output to the standard output note: 1 could be the standard output.
>& redirect a standard error output to a file or device to overwrite the original file C-shell
|& to send a standard error pipe to another command as input

3.shell with (&&) and OR (| |)

If the first command executes successfully, the operator (&&) executes the second command
If the first command fails to execute, or the operator (| |) To execute a second command.

4. Find the file with the keyword "xxx" in the file name under the specified directory with the Find command
Find/Specify directory-name ' * keyword * '

5. Folder handling:
CP (copy) command: Cp-r/demo/em1/demo/em2/em2a
Note: Files under a folder are copied to other folders under the folder "CP File/This folder/Folder A", do not need-r, copy the folder to the other places in the computer before the folder to add/, the system can recognize the folder, otherwise it will prompt the error.
MV (move) command: mv/demo/em1/demo/em2
Note: To move a folder to a different folder, make sure that you cannot have a folder with the same folder name in the sibling directory

6.shell $1~ $n refers to the parameter values added to the shell, which is the 1th parameter, meaning to pass a parameter from the outside to $1,2 is the 2nd parameter

7.echo-e and Read-p

There is also the ability to output the specified content, but the output after read-p will all be displayed on the terminal display, and after echo-e can add other commands, such as line break and content display color, etc.

Input command: read-p "\nhello World" x

Output Result: \nhello World

Input command: ECHO-E "\nhello World"

Read X

Output command: ← This is the line break effect

Hello World

8.test! -D $dir

$dir is a path, and is a directory of false, can be combined with the summary of the 3rd use

9.ls-r/root

Recursively view all directories under Path root

Ten. 2>/dev/null

REDIRECT standard error output to an empty device

11.grep-v ' ^$ ' filter (delete) null character GREP-V reverse lookup

Grep-v-N ' ^$ ' filter (delete) blank line ^ represents line end

12.sed ' s/:.*$//g ' filter:. These content

Images quoted from https://www.zybang.com/question/6c3d3623380bd3fa47d0363c76f6e85c.html, infringement please contact the author delete

Follow up the update, please look forward to ...

An obscure shell command

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.