Linux introduction and Common commands 4-linux advanced commands and skills, linux4-linux

Source: Internet
Author: User

Linux introduction and Common commands 4-linux advanced commands and skills, linux4-linux

Top

Several Disks
Fdisk-l
Disk Space df-lh
Df-al

View the process: ps-ef "grep java
Kill process: kill-9 process no.

Filter more

More xxx | grep www.makaidong.com

 

Configure the ip address after installing linux


Vim/etc/sysconfig/network-scripts/ifcfg-eth5
IPADDR = 192.168.42.142
NETMASK = 255.255.255.0
GATEWAY = 192.168.42.1
Enable and disable Nic
Ifdown eth5
Ifup eth5
Service network restart is preferred


2: Unable to configure dns for Internet access
Vim/etc/resolv. conf


Dns

Nameserver 8.8.8.8
Nameserver 114.114.114.114
Nameserver 223.5.5.5
Nameserver 223.6.6.6

Test:
Ping www.makaidong.com

Yum Installation Software
Rpm

Yum-y install mysql

Shell Basics
#! /Bin/sh

# Print hello world in the console window
A = "hello world! Hello makaidong"
Echo "Hi, $"

"Hi, hello worlds" is not output, but "Hi," is output ,". This is because Shell treats $ as a variable, while $ as is not assigned a value, and its value is null.
The correct method is:

Echo "Hi, $ {a} s"
Echo $

Ps-aux | grep 'ambari'

Tail-f-n 200 add_run_7.sh.log
Switch to root
Sudo su-

Switch to another user
Sudo su hive

Top

Df-lh
,
Find recursive search for specific file names
Find 201412/-type f-name "*. txt"
Install


Copy wildcard
Cp-r * _ result bak/

Wordcount
Wc-l statistical wildcard

Wc-l 3_net _*/*

Root@10.251.242.59:/mnt/scp-r makaidong/


#! /Bin/sh

A = 10
B = 20

If [$ a = $ B]
Then
Echo "a is equal to B"
Fi

If [$! = $ B]
Then
Echo "a is not equal to B"
Fi
[-F "$ file"] determines that $ file is a file.
[! -F "$ file"] determines that $ file is not a file.
History low great
[$ A-lt 3] determines whether the value of $ a is less than 3. Similarly,-gt and-le indicate greater than or equal
Num1-eq num2 equals to [3-eq $ mynum]
Num1-ne num2 is not equal to [3-ne $ mynum]
Num1-lt num2 less than [3-lt $ mynum]
The num1-le num2 is less than or equal to [3-le $ mynum]
Num1-gt num2 greater than [3-gt $ mynum]
Num1-ge num2 is greater than or equal to [3-ge $ mynum]

[-N "$ a"] determines whether the variable $ a has a value. Use-z to test the Null String.

File comparison operator
[-E filename] If filename exists, it is true [-e/var/log/syslog]
-D filename if filename is a directory, it is true [-d/tmp/mydir]

-R filename if filename is readable, it is true [-r/var/log/syslog] read
-W filename if filename can be written, it is true [-w/var/. txt] write
-X filename: If filename is executable
-Z string if the string length is zero, it is true [-z "$ myvar"]
-N string if the string length is not zero, it is true [-n "$ myvar"]
String1 = string2 if string1 is the same as string2, it is true ["$ myvar" = "one two three"]
String1! = String2 if string1 is different from string2, it is true ["$ myvar "! = "One two three"]

 


While [cond1] & <||} [cond2]…; Do

...

Done

For var in ...; Do

...

Done

For (cond1; cond2; cond3) do

...

Done

Until [cond1] & <||} [cond2]…; Do

...

Done

Linux shell array creation and usage tips

Shell array + for Loop
#! /Bin/bash
For I in ip1 ip2 ip3 ip4
Do
Echo ssh root @ $ I
Echo "$ I apache service restarted"
Done
Exit


Sh-x *. sh
Shell script for generating test data
Data_create.sh
Rm-rf./data.txt
Touch data.txt
For (I = 0; I <2000; I ++ ))
Do
Str = ', name ';
Name =$ {I }$ {str }$ {I}
# Echo $ name
Echo $ name> data.txt
Done

Echo 'show testdata'
More data.txt

 

Chmod u + x data_create.sh
Run scripts
Sh-x data_create.sh

Sed replaces recursive Regular Expressions
Sed-I "s/<div class = \" c_r_a c_r_13_a \ "> <script language = \" javascript \ "> c_r_13_a (); <\/script> <\/div> // g "index.shtml

Sed-I "s/10.16.60.29/cloud1.xingtu.360.cn/g "*

Find/data-name "*"-print | xargs-I sed-I's/<div class = \ "c_r_a c_r_14_a \"> <script language = \ "javascript \"> c_r_14_a (); <\/script> <\/div> //'{}


Find *-name "*"-print | xargs-I sed-I's/<div class = \ "c_r_a c_r_14_a \"> <script language = \ "javascript \"> c_r_14_a (); <\/script> <\/div> //'{}
# Regular Expression
Find *-name "*"-print | xargs-I sed-I's/<div class = \ "c_r_a c_r _. * _ a \ "> <script language = \" javascript \ "> c_r _. * _ a (); <\/script> <\/div> //'{}

Find *-name "*"-print | xargs-I sed-I's/<div class = "c_a_tb ". * id = c_a_tb. *>. * c_a_tb. * (); <\/script> <\/div> //'{}

Find *-name "*"-print | xargs-I sed-I's/<div class = "c_a_tb ". * id = c_a_tb.>. * c_a_tb. * (); <\/script> <\/div> //'{}
9id = c_a_tb9> <script type = 'text/javascript '> c_a_tb9 (); </script> </div>

Crontab scheduled shell execution
20 * sh-x/root/start. sh> start. log 2> & 1
Remote machine ping different local machines
The local machine can be pinged to a remote device, which can be obtained as follows:
First, go to your user directory:
On the target machine: cp tmpdir. SQL .gz/home/makaidong/
Then on the local machine:
Scp-r makaidong@10.115.92.82:/home/makaidong/\ *. SQL .gz.
Note: \ * escape
Nohup
Nohup hive -- service hiveserver 2> & 1 &


Dos2unix windows-linux shell format conversion
Find.-name "*. conf" | xargs dos2unix

 

Var. sh: year = 2015

Shell import source introduces other shells
#! /Bin/bash
# In other directories: source./sh/var. sh # sh or source sh/var. sh
Source var. sh
Rm-rf./data.txt
Touch data.txt
For (I = 0; I <$ year; I ++ ))
Do
Str = ', name ';
Name =$ {I }$ {str }$ {I}
# Echo $ name
Echo $ name> data.txt
Done


Awk $ (awk-F "=" '$1 ={ print $2}

 

Compression:
Zip recursive compression folder (directory)
Zip-r./201412.zip./201412/*-r
How to compress and retain source files in Linux:
Gzip-c filename> filename.gz
How to decompress and retain source files in Linux:
Gunzip-c filename.gz> filename


Well, basically, the following four commands are commonly used:
Compressed into a gzip file:
Tar-zcvf shell.tar.gz shell/
Decompress the gzip file:
Tar-zxvf shell.tar.gz
Compress the file to bz2:
Tar-jcvf shell.tar.bz2 shell/
Decompress the bz2 file:
Tar-jxvf shell.tar.bz2


Tar-zxvf makaidong.tar.gz-C/zzz/bbs
Gunzip makaidong.tar.bz2.gz
Tar-jxvf makaidong.tar.bz2


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.