1. display the 10 processes that consume the most memory/CPU
Ps aux | sort-nk + 4 | tail
Ps aux | sort-nk + 3 | tail
------------------------------------------
2. view the number of concurrent Apache requests and their TCP connection status
Netstat-n | awk '/^ tcp/{++ S [$ NF]} END {for (a in S) print a, S [a]}'
------------------------------------------
3. Find the 10 most commonly used commands and the number of times (or the maximum number of ip addresses accessed)
Sed-e's/|/\ n/G '~ /. Bash_history | cut-d ''-f 1 | sort | uniq-c | sort-nr | head
------------------------------------------
4. The 10th fields in the log indicate the connection time and calculate the average connection time.
Cat access_log | grep "connect cbp" | awk 'in in {sum = 0; count = 0 ;}{ sum + = $10; count ++ ;} END {printf ("sum = % d, count = % d, avg = % f \ n", sum, count,
Sum/count )}'
------------------------------------------
5. lsof command
Lsof abc.txt displays the process of opening the abc.txt File
Lsof-I: 22. Know what programs are running on port 22.
Lsof-c abc displays the files currently opened by the abc process
Lsof-p 12: check which files are opened by the process with process number 12.
------------------------------------------
6. Kill all processes of a program
Pkill-9 httpd
Killall-9 httpd
Do not use-9 as much as possible. kill cannot be used easily on the database server. Otherwise, the consequences of important data loss will be unimaginable.
------------------------------------------
7. rsync command (only the compressed files of one day must be synchronized, and the remote directory must be consistent with the local directory)
/Usr/bin/rsync-azvR-password-file =/etc/rsync. secrets 'Find. -name "* required yesterday.gz"-type f'storage @ 192.168.2.23: logbackup/13.21/
------------------------------------------
8. Rename the *. sh file in the directory to *. SH.
Find.-name "*. sh" | sed's/\ (. * \) \. sh/mv \ 0 \ 1.SH/ '| sh
Find.-name "*. sh" | sed's/\ (. * \) \. sh/mv & \ 1.SH/ '| sh (same effect as above)
------------------------------------------
9. Run the remote program in ssh and display it locally.
Ssh-n-l zouyunhao 192.168.2.14 "ls-al/home/zouyunhao"
------------------------------------------
10. directly use the command line to change the password
Echo "zouyunhaoPassword" | passwd-stdin zouyunhao
------------------------------------------
Ssh-keygen
Ssh-copy-id-I ~ /. Ssh/id_rsa.pub user @ remoteServer
------------------------------------------
12. share files in the current folder as http
$ Python-m SimpleHTTPServer
Access http: // IP: 8000/in the browser to download the file in the current directory.
------------------------------------------
13. shell segment comment
: <'Echo hello, world! '
------------------------------------------
14. view the server serial number
Dmidecode | grep "Serial Number" (this command can be used to view other hardware information on the machine)
------------------------------------------
15. Check whether the network card has a physical connection
/Sbin/mii-tool
------------------------------------------
16. view the meaning of the linux system or mysql error code, as shown in Figure 13:
Perror 13
------------------------------------------
17. About the number of CPUs
View the number of logical CPUs: cat/proc/cpuinfo | grep "processor" | wc-l
Check the number of physical CPUs: cat/proc/cpuinfo | grep "physical id" | sort | uniq | wc-l
View the number of cores of each physical cpu. cores: cat/proc/cpuinfo | grep "cpu cores"
If the number of cores of all physical CPUs is less than the number of logical CPUs, the cpu uses hyper-Threading Technology. View the number of logical CPUs in each physical cpu: cat/proc/cpuinfo | grep "siblings"
------------------------------------------
18. Extract strings from logs with nonstandard formats
Perl-ne 'print "$1 \ n" if/servletPath = (\ S +)/G' test. log
------------------------------------------
19. Remove spaces if all file names contain spaces.
Find. /-type f | while read line; do echo $ line | grep-q "" & \ mv "$ line" $ (echo $ line | sed's // G'); done
------------------------------------------
20. Remove spaces if the names of all folders contain spaces.
Find. /-type d-name '*' | while read file; do echo $ file | grep-q "" & mv "$ file" $ (echo $ file | tr-d'); done
When the end of the file name ends with a space, it cannot be implemented using the command line. You need to use the script:
#! /Bin/bash
IFS = $ '\ N'
Find. /-type f | while read line; do echo $ line | grep-q "" & \ mv "$ line" $ (echo $ line | sed's // G'); done
-------------------------------------------
21. Generate a random string:
# Tr-dc _ A-Z-a-z # $ % ^ *-0-9 </dev/urandom | head-c8
CHSH ^ eJ
Or
# Mkpasswd-l 8-d 1-c 3-C 2-s 2
G_ze3Hto
-------------------------------------------
22. linux statistics on the number of PCI slots:
[Root @ vcdog ~] # Dmidecode | grep-1 PCI
ISA is supported
PCI is supported
PC Card (PCMCIA) is supported
--
System Slot Information
Designation: PCI Slot J11
Type: 32-bit PCI
Current Usage: In Use
--
System Slot Information
Designation: PCI Slot J12
Type: 32-bit PCI
Current Usage: In Use
--
System Slot Information
Designation: PCI Slot J13
Type: 32-bit PCI
Current Usage: In Use
--
System Slot Information
Designation: PCI Slot J14
Type: 32-bit PCI
Current Usage: Available
----------------------------------------
23. nmap:
# Nmap-A-T4 192.168.1.28 // The Host Name, domain name, or Host IP address can be used here
Starting Nmap 4.11 (http://www.insecure.org/nmap/) at CST
Interesting ports on bogon (192.168.1.29 ):
Not shown: 1677 closed ports
PORT STATE SERVICE VERSION
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn
445/tcp open microsoft-ds Microsoft Windows XP microsoft-ds
MAC Address: 70: 5A: B6: 09: 45: FA (Unknown)
Device type: general purpose
Running: Microsoft Windows NT/2 K/XP
OS details: Microsoft Widows XP SP2
Service Info: OS: Windows
------------------------------------
24. Remove ^ M hard carriage return for files in linux:
(1) # cat test.txt | tr-d '^ M'> test. new
(2). # sed-I's/^ M // G' test.txt
(3) # dos2unix test.txt
(4) In vi: % s/^ M/g
Note: Here '^ M' is generated using the CTRL-V CTRL-M instead of directly typing '^ M ".
-------------------------------------
25. Delete all blank lines in the file:
1. Use awk as follows:
[Root @ dg ~] # Cat t.txt | awk-F ''' {if ($1! = Null) print $0 }'
203.208.46.146 www.google.com
223.208.46.146 www.google.com
203.208.46.147 www.google.com.hk
203.208.46.132 clients1.google.com
203.208.46.149 mail.google.com
2. The sed method is as follows:
[Root @ dg ~] # Sed '/^ $/d' t.txt
203.208.46.146 www.google.com
223.208.46.146 www.google.com
203.208.46.147 www.google.com.hk
203.208.46.132 clients1.google.com
203.208.46.149 mail.google.com
203.208.46.161 chatenabled.mail.google.com
3. The awk method is as follows:
[Root @ dg ~] # Awk 'nf 't.txt
203.208.46.146 www.google.com
223.208.46.146 www.google.com
203.208.46.147 www.google.com.hk
203.208.46.132 clients1.google.com
203.208.46.149 mail.google.com
203.208.46.161 chatenabled.mail.google.com
4. Delete blank lines in vim as follows:
: G/^ $/d
203.208.46.146 www.google.com
223.208.46.146 www.google.com
203.208.46.147 www.google.com.hk
203.208.46.132 clients1.google.com
203.208.46.149 mail.google.com
203.208.46.161 chatenabled.mail.google.com
------------------------------------
26. Obtain the TYPE and SPEED information of the memory:
# Dmidecode | grep-A 16 "Memory Device" | grep-E "Speed | Type"
Type: DDR2 FB-DIMM
Speed: 667 MHz (1.5 ns)
Type: DDR2 FB-DIMM
Speed: 667 MHz (1.5 ns)
Type: DDR2 FB-DIMM
Speed: 667 MHz (1.5 ns)
Type: DDR2 FB-DIMM
Speed: 667 MHz (1.5 ns)
Type: DDR2 FB-DIMM
Type: DDR2 FB-DIMM
Type: DDR2 FB-DIMM
Type: DDR2 FB-DIMM
========================================================== ======================================
This article is from the "vcdog's blog" blog, please be sure to keep this source http://255361.blog.51cto.com/245361/836976