Common shell commands and tips

Source: Internet
Author: User

I have been using Linux recently and have accumulated some experience and skills. I will share it with you.

1. view the number of objects

WC-l filepath

2 File Sorting

Sort-K1-K2-T ""-n-r filepath

The command above is to sort the file records in reverse order according to the first column and the second column, with the separator \ t.

Note: When sorting in Chinese, you need to specify lc_all = C for sorting. Command lc_all = C sort-K1-K2-T ""-n-r filepath

3. view the current process

PS UX

4. view the resources occupied by the Process

Top Ctrl + C Exit

5. View hard disk and memory

DF-H/free

6 ShellProgramParameters in

$ # Number of parameters

$1 first parameter, $2 second parameter

Size = 1

$ {! Size} represents the first parameter, that is, when you use a variable to replace a number, you need to use $ {! Varible} format.

You can use ''to include a script to save the return value of the entire script.

For example, if the result is 'Ls', the result will be saved with the return result of LS.

7. Use nohup sh run. Sh & submit the task

In this way, the running of the program is not affected when the network is interrupted. Otherwise, the program will fail due to network interruption.

8 program output

Generally, the program uses> redirect output, such as CAT a.txt> B.

But some programs may have outputs and error outputs. How can this problem be formulated?

Sh-x run. Sh 1> out 2> err. Note that there must be no space between 1, 2, and>. continuous input is required.

9 MPs queue usage

If you have a series of simple operations, you can use pipelines. For example

Cat input | sort | uniq> B

In this way, the result is output to B after the input is deduplicated, which is more convenient.


For the time being, I think of these commonly used ones. Many people are also very familiar with them, so I will not elaborate on them.

Welcome to shoot bricks ~~

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.