Linux system server maintenance common command set

Source: Internet
Author: User
Tags mcrypt php mysql mx record

The following is a collection of common maintenance commands for linux servers. I hope this command will be helpful to you.

 

Change the time zone to Zone 8, Shanghai

1 cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
Modify host name

1 # modify the following two files:

2 vim/etc/hosts

3 vim/etc/sysconfig/network
View the number of connections per IP address on the server to detect DDOS attacks.

1 netstat-ntu | awk '{print $5}' | cut-d:-f1 | sort | uniq-c | sort-n

2 2 199.87.229.20

3 3 120.43.25.94

4 3 218.30.103.142

5 3 61.135.169.47

6 4 110.81.18.140

7 8 59.58.136.94

8 20 192.151.148.226

9 47 219.157.16.254
T-man: kicked others out of the server.

1 w # view who is online

2 15:44:27 up 22 days, 1 user, load average: 0.02, 0.09, 0.10

3 user tty from login @ IDLE JCPU PCPU WHAT

4 root pts/0 19.01.177.103 0.00 s 0.03 s 0.00 s w

5 pkill-KILL-t pts/0 # Kick this terminal (now T itself, ^ _ ^)
Modify the file Timestamp

1 touch-c-t 0801010800 filename. c

2 # Set the file timestamp to, in the format of YYMMDDhhmm ).
Batch rename the. conf file to. conf. bak

1 cd/etc/httpd/webSite/

2 for I in $ (ls *. conf); do mv $ I $ {I/. conf/. conf. bak}; done

3 # note the current directory problem because the ls command is used
One-click installation of Apache + PHP + MySQL

1 yum-y install httpd php mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-mcrypt php-gd php-xml php-mbstring php-ldap php-pear php- xmlrpc mysql-connector-odbc mysql-devel libdbi-dbd-mysql
Add a user and set a password

1 useradd-s/bin/nologin-m-d/var/www/website/new_user_name-g newUserGroupName newUserName

2 echo 'pwdbuilder newusername' | passwd newUserName -- stdin

3 # Add a Website user to prohibit logon. The home directory is the root directory of the website, and the password is calculated based on pwdBuilder.
View the number of first-level directories in the current directory

1 ls-l | grep "^ d" | wc-l
Vi Delete empty rows

1: g/^ s * $/d

2 # Dreamweaver can replace "rns * rn" with "rn" as a regular expression"
Find the file in the directory that contains the specified string

1 find./-name '*. conf' | xargs grep-in "baidu.com.demo.upall.cn"

2 # Note: "baidu.com.demo.upall.cn" is the string to be searched.

3 # This command is used to quickly locate the name of a domain name in a large number of configuration files, because:

4 # due to special reasons, the configuration file name of the user does not comply with the rules or there are multiple different domain names in a configuration file

5 # I: case insensitive

6 # n: display the row number
View the size of a single file (or folder)

1 du-sh/var/log/
View the size of each folder and file in the folder (which folder is the largest)

1 du-h -- max-depth = 1/var/log/
Delete ^ M from source code

1: % s/^ M $/g # Note: ^ M input mode, Ctrl + V + M
Batch Remove write permissions for include and its files

1 find/var/www-type d-name "include"-print0 | xargs-0 chmod ugo-w-R

2 # read this article to remove execution permissions :/? P = 697
Find all the files in the current folder that contain the string "fsockopen"
In fact, it is more accurate to search for "udp: // $". Of course, it depends on the actual situation, ^_^.


1 find./-type f | xargs grep-sni "fsockopen"

2 # Or (the following line helps you understand the "-sni" parameter)

3 find./-type f | xargs grep -- silent -- line-number -- ignore-case "fsockopen"

4 # if all the files can be deleted, run the following command to delete them:

5 find./-type f | xargs grep-lsi "fsockopen" | xargs rm
Check whether the MX record of the domain name takes effect

1 [upall @ linux ~] $ Host-t mx upall.cn

2 upall.cn mail is handled by 10 mx.upall.cn.
List zip files in all website folders and display their size
We often download some source code packages on the server or package some backup files and forget to delete them. This command can be used to find them.


1 find/www/-type f-name "*. zip"-print0 | xargs-0 du-h
Delete users and their files (delete user logon directories and all files in the directories)

1 userdel-r upall
View programs running on the specified port

1 # view the programs running on port 3428:

2 lsof-I: 3428

3 # You can disable the process (9 indicates the termination signal level ):

4 killall-9 firefox
Update the/etc/aliases database after modifying/etc/aliases. db

1 newaliases
Disable and Disable User locking, and resume user enabling

1 passwd-l upall # Disable User upall

2 passwd-u upall # Enable User upall
Clear BOM headers in UTF-8

1 grep-r $ 'xefxbbxbf' * | grep. php

2 # or directly configure vim: set nobomb
CentOS yum install Apache + PHP + MySQL + Tomcat

1 # yum-y install httpd php mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-mcrypt php-gd php-xml php-mbstring php-ldap php-pear php -xmlrpc mysql-connector-odbc mysql-devel libdbi-dbd-mysql
Replace the string in the MySQL Field

1 UPDATE 'tablename'

2 SET 'fieldname' = replace ('fieldname', 'fromstring', 'tostring ')

3 WHERE 'fieldname' LIKE '% fromString % ';

4-name of the tableName table

5-fieldName field name

6-fromString string to be replaced

7-string to which toString is replaced
Copy the file to a compliant directory (one file to multiple directories)

1 # copy the file to a directory containing "base/images" in the path:

2 find.-type d-print | grep "/base/images" | awk '{print $1}' | xargs-I % cp./logo.gif %

3 # copy the file to all directories:

4 find.-type d-exec cp./logo.gif {};

5 # copy the file to a directory containing "images" in the path (the name parameter value cannot contain "/". If yes, use "grep "):

6 find.-type d-name "images"-exec cp./logo.gif {};
<End>

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.