Linux operation and maintenance basic problem (III.)

Source: Internet
Author: User

AWD sed Problem
add a blank line after each line
sed G file
 
insert a blank line after the line that matches the style "regex"
sed '/regex/g ' file
 
Count rows (simulate "wc-1")
wc-l File
 
Insert 5 Spaces at the beginning of each line (to move the full text 5 spaces to the right)
sed ' s/^//' file
 
Replace "foo" with "bar" and replace only if the string "Baz" does not appear in the row
sed '/baz/! s/foo/bar/g ' File
 
concatenate each of the two lines into one line (similar to "paste")
sed ' $! n;s/\n//' File
 
displays rows containing "AAA ", "BBB", "CCC" (Fixed order)
sed '/aaa.*bbb.*ccc/!d ' file
 
keep only one row in the repeating row, and the others are deleted
sed ' $! N /^\ (. *\) \n\1$/! P D '
 
Delete Multiples of 8 rows
sed ' n;n;n;n;n;n;n;d; '
 
change "Haiwao" in line 50th of the file test to "Haiwai"
sed-ie ' 50s/haiwao/haiwai/g ' test
 
use the SED command to replace all the carriage returns in the test.txt with spaces.
sed-i ' s/\r//' Test.txt

There are files File1
query File1 The line number of the empty line Grep-n "^#" file1| awk-f ":" ' {print '} '
Print File1 's 2nd to 5th line Sed-n ' 2,5p ' file1
query File1 The line that ends in Hai grep abc$ file1

look for files with the/usr/local/apache/logs directory last modified longer than 30 days and delete.
find/usr/local/apache/logs-type f-mtime +30-exec rm-f {} \;

add a route to 192.168.3.0/24 with a gateway of 192.168.1.254.
Route add-net 192.168.3.0/24 GW 192.168.1.254

within November, every 2 hours from 6 o'clock in the morning to 12 o '/usr/bin/httpd.sh how to implement
0 6-12/2 */usr/bin/httpd.sh

How to forward a local 80 port request to port 8080, the current host IP is 192.168.2.1
iptables-t nat-a prerouting-d 192.168.16.1-p tcp--dport 80-j DNAT--to 192.168.16.1:8080
iptables-t nat-a prerouting-i eth0-d 192.168.16.1-p tcp-m tcp--dport 80-j REDIRECT--to-ports 8080

allow the machine to connect to the external 80 port (this function with the external server for the)
iptables-a output-p tcp–dport 80-j ACCEPT
Open 3306 ports on this machine
iptables-a input-p tcp--dport 3306-j ACCEPT
prohibit external ping of the server
iptables-a input-p icmp-j DROP

use a command to view the ports on which the system is currently being monitored by the service being started
netstat-antl |grep "LISTEN"

please use the Linux system command to count the number of connections to the establish state.
Netstat-an |grep |grep established |wc-l

 

Linux operation and maintenance basic problem (III.)

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.