Linux System server maintenance common commands collection

Source: Internet
Author: User
Tags aliases ldap mcrypt odbc pear php mysql mx record

Change time zone to East 8, Shanghai

1 cp/usr/share/zoneinfo/asia/shanghai/etc/localtime
Modify Host Name

1 #需要改下边这两个文件:

2 vim/etc/hosts

3 Vim/etc/sysconfig/network
View the number of connections per IP for a server to detect DDoS

1 Netstat-ntu | awk ' {print $} ' | 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, kick the others out of the server.

1 W #查看谁在线

2 15:44:27 up, 7:16, 1 user, load average:0.02, 0.09, 0.10

3 USER TTY from login@ IDLE jcpu pcpu WHAT

4 root pts/0 192.161.177.103 15:40 0.00s 0.03s 0.00s W

5 pkill-kill-t pts/0 #踢了这个终端 (now is t own, ^_^)
To modify the timestamp of a file

1 touch-c-T 0801010800 filename.c

2 #将文件的时间戳设定为2008-01-01 8:00, in the form of (YYMMDDHHMM).
Batch. conf files are renamed to. Conf.bak

1 cd/etc/httpd/website/

2 for I in $ (ls *.conf);d o mv $i ${i/.conf/.conf.bak};d One

3 # due to using the LS command, note the current directory problem
One-click Installation Apache+php+mysql

1 yum-y install httpd php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-mcrypt 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, prohibit login, home directory for the site root directory, according to Pwdbuilder calculation password
View the number of first-level directories under the current directory

1 ls-l |grep "^d" |wc-l
VI Delete blank line

1:g/^s*$/d

2 # dreamweaver can replace "Rns*rn" with "RN" in regular mode
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 find

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

4 # For special reasons the user's profile name does not conform to the rule or a configuration file has multiple domain names that are not similar

5 # I: case-insensitive

6 # N: Shows the line number
To view the size of a single file (or folder)

1 du-sh/var/log/
View the size of folders and files in a folder (which folder is the largest)

1 du-h--max-depth=1/var/log/
Delete the ^m in the source code

1:%s/^m$//g #注意: ^m input mode, ctrl+v+m
Bulk removal of write permissions for include and its under files

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

2 # Remove Execute permission can read this article:/?p=697
Find all files in the current folder that contain the string "Fsockopen"
In fact, look for "udp://$" words will be accurate, of course, to see the actual situation, ^_^.


1 find./-type F | Xargs Grep-sni "Fsockopen"

2 # or (this line below helps to understand the "-sni" parameter)

3 find./-type F | Xargs grep--silent--line-number--ignore-case "Fsockopen"

4 # If you find all the files can be deleted, you can use the following command to delete:

5 find./-type F | Xargs grep-lsi "Fsockopen" | Xargs RM
See if the MX record for the domain name takes effect

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

2 upall.cn Mail is handled by mx.upall.cn.
Lists the zip files in all Web sites folders and displays their size
It is often possible to find out if the server downloads some source code packages or packs some backup files and forgets to delete them.


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

1 Userdel-r Upall
To view programs that are running on a specified port

1 # View 3428-Port running programs:

2 Lsof-i: 3428

3 # Shutdown process can (9 is terminated signal rating):

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

1 newaliases
Disabling disable lockout user, restoring Enable user

1 passwd-l upall #禁用用户upall

2 Passwd-u Upall #启用用户upall
Clear the BOM header in UTF-8

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

2 #或者直接配置vim: Set Nobomb
CentOS Yum Install Apache + PHP + MySQL + Tomcat

1 #yum-Install httpd php mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-mcrypt php-gd ph P-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-tablename the name of the table

5-fieldname Field Name

6-fromstring a string to replace

7-tostring replaced with string
Copy files to a rule-compliant directory (one file to multiple directories)

1 # Copy the file to the directory containing "Base/images" in the path:

2 Find. -type D-print | grep "/base/images" | awk ' {print $} ' | Xargs-i% CP./logo.gif%

3 # Copy files to all directories:

4 Find. -type d-exec CP./logo.gif {};

5 # Copy file to directory containing "images" (name parameter value cannot have "/", if necessary "grep to match"):

6 Find. -type d-name "Images"-exec CP./logo.gif {};
Finish >

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.