Common shell command instance analysis-continuous update

Source: Internet
Author: User

Common Programming and example of Shell on: http://blog.csdn.net/larrylgq/article/details/7333632

 

1: ls * | while read FN; do grep-V ', 11,1108, 1133,110816, 110816' $ FN>/data1/hadoop/back_up/tmp/$ {fn} _ 08171819; done

 

Ls * output

| Media transcoding queue. The preceding output is used as the input.

Grep Filtering

-V reverse lookup

-> The meaning of the first command is to traverse all the files in the current folder and use while for a loop. Execute the following command for each file: reverse lookup the files whose names are not ', 11,1108, 1133,110816, 110816, output the file to/data1/hadoop/back_up/tmp/with the current file name + _ 08171819/

2: ls * _ 110816 *. GZ | while read FN; do gunzip-C $ FN> multiple bytes fn1_.gz}. log; done

Put * _ 110816 *. GZ-matching compressed file-zcvf (forcibly extract all information and create a package),-C (create)-VF (vebose, force)-x decompress -z(.gz) to package

-> The second command indicates that each file name (FN) is read cyclically. The loop body do splits the file into a gunzid file and then outputs the file FN + Gz. log.

 

3: ls/datacenter/hadoop/back_up/20110920/View/10096 | while read FN; do cut-d', '-F7 $ FN; done | grep '000000' | WC-l

Cut-d', ', used as the separator-F7 to find the 7th Columns

Cut-B 1-10 bytes

Count the number of rows (-l)

-> The third command indicates a loop/datacenter/hadoop/back_up/20110920/View/10096 file, which splits each entry of each file and outputs 7th columns, in this column, find the 110919

4: Kill 'ps aux | grep Java | grep-V grep | awk {'print $2 '}'

Kill and kill Processes

Kill the process to be killed. A process number is returned when the anti-code is used.

Awk

{''} Inside the loop

Print $2 print the second one

-> The fourth command indicates to find a Java Process without grep and return the process number.

5: For (I = 3; I <11; I ++); Do echo $ I; SSH 10.10.10. $ I 'Find/datacenter/infobright/panel/{view, click}-type F-exec WC {}\; '; done

Log on to 10.10.10.3-11 using SSH.

Find search operation

-Type F: Find all files. D is the directory.

-Exec: execute shell commands

{} \; Returns and returns

-> The Fifth command means to log on to the 8 machines 3-11 to search for all the files under/datacenter/infobright/panel/{view, click} and execute WC (wordcount)

Find ~ /Desktop/log-type F-exec WC-l {}\;

6: delete files 7 days ago by file name

#! /Bin/bash
# Deleting files 7 days ago
Pathadx =./ADX
Del_date = 'date + % Y % m % d-d "7 days ago "'
For N in 'Find $ {pathadx}-name' *-r-* ''; do
File_dt = 'echo $ n | awk-F/'{print $5}' | cut-B 1-8'
If [[$ file_dt <$ del_date]; then
# Echo $ N;
# Echo $ del_date;
# Echo $ file_dt;
Rm-RF $ n
Fi
Done

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.