1. Display up to 10 processes consuming memory/cpu
PS aux | Sort-nk +4 | Tail
PS aux | Sort-nk +3 | Tail
2. View the number of concurrent requests for Apache and its TCP connection status
Netstat-n | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, s[a]} '
3. Find out your most commonly used 10 commands and the number of uses (or the maximum number of IP access)
Sed-e ' s/| /\n/g ' ~/.bash_history |cut-d '-F 1 | Sort | uniq-c | Sort-nr | Head
4. The 10th field in the log indicates the connection time, averaging the connection time
Cat Access_log |grep "connect CBP" |awk ' begin{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 shows the process of opening the file Abc.txt
Lsof-i: 22 Know what program 22 port is running now
LSOF-C ABC show ABC process now open file
Lsof-p 12 See which files are open by process number 12
6. Kill all processes of a program
Pkill-9 httpd
Killall-9 httpd
Note that as far as possible without-9, the database server can not easily use kill, otherwise the consequences of important data loss will be disastrous.
7.rsync command (requires only one day of compressed files to be synchronized, and the remote directory remains consistent with the local directory)
/usr/bin/rsync-azvr–password-file=/etc/rsync.secrets ' Find. -name "* $yesterday. Gz"-type f ' [email protected]::logbackup/13.21/
8. Rename the *.sh file in the directory to *. Sh
Find. -name "*.sh" | Sed ' s/\ (. *\) \.sh/mv \1.sh/' |sh
Find. -name "*.sh" | Sed ' s/\ (. *\) \.SH/MV & \1.sh/' |sh (same effect as above)
9.SSH executes the remote program and displays it locally
Ssh-n-L Zouyunhao 192.168.2.14 "Ls-al/home/zouyunhao"
10. Modify the password directly with the command line
echo "Zouyunhaopassword" |passwd–stdin Zouyunhao
Ssh-keygen
Ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected]
12. Share files in the current folder in HTTP mode
$ python-m Simplehttpserver
You can download the current directory file by accessing Http://IP:8000/in the browser.
13.shell paragraph Notes
:<< ' echo hello,world! '
14. View the server serial number
Dmidecode |grep "Serial number"
(This command can also be used to view other hardware information for the machine)
15. Check if the network cable is physically connected
/sbin/mii-tool
View the number of Apache processes (number of Apache concurrency in prefork mode)
Ps-ef | grep httpd | Wc–l
Identify 20 processes with a high CPU utilization
PS-E-o pcpu,pid,user,sgi_p,cmd |grep-v pid| Sort-k 1| Tail-20
View TCP link status
Netstat-n | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, s[a]} '
Time synchronization
sudo ntpdate ntp.ubuntu.com
Or
Ntpdate s1a.time.edu.cn
Get the number of lines in a text document
# awk ' {print NR} ' test|tail-n1
Get process PID
Pgrep Java
Quickly back up a file
CP Keepalived.conf{,.bak} keepalived.conf Backup to Keepalived.conf.bak
Get the total number of processes under MySQL user
Ps-ef|awk ' {print '} ' |grep ' mysql ' |grep-v ' grep ' |wc-l
View 80 Port Connections
NETSTAT-ANTP | grep 80 | grep established-c
View 8080 ports
Netstat-na | grep estab | grep 8080 | Wc-l
View the number returned is the number of Apache running processes
Ps-ef | grep httpd | Wc-l
Enumerates the file commands that have been opened in the system lsof
#-c Displays the command opened by SSH opening the file
Lsof-c SSH
#-p show files opened by a process
Lsof-p 5200
#+d displays open files under a directory +d display open files, including subdirectories, in a directory.
Lsof +d/usr/local
Lsof +d/usr/local
#-u displaying files opened by a user
Lsof-u Root
#-i shows an open file on a protocol, IP, port
lsof-i [Email protected]:22
? Quickly back up a file
CP Filename{,.bak} Quick Backup of a file, Filename{,.bak} This section will be expanded into the filename Filename.bak then passed to CP.
? Empty or create a file
> file.txt
? Resetting the terminal
Reset, if you try to accidentally cat a binary file, it is likely that the entire terminal will be silly, may not be wrapped, can not be echoed, a large heap of garbled, such as, at this time type reset return, regardless of whether the command is displayed, you can return to normal.
? Executes a command without saving it to the history
<space> command space plus commands to execute, a command is executed but not saved to the history.
? Displays the size of all subdirectories in the current directory
Du-h--max-depth=1 Displays the size of all subdirectories in the current directory, max-depth refers to the directory level.
? From a landing to B
Ssh-t host_a ssh host_b if the target machine host_b in a more complex network environment, the machine is not directly accessible, but another host_a can access to host_b, but also can be accessed by the local, the above command resolves the problem of convenient login host_b.
SSH-P 8888 [email protected]
? SCP Transfer File
Scp/root/bb/api.war [Email Protected]:/root/tools
You can also transfer multiple destinations at once.
Scp/root/bb/api.war [email protected]:/root/tools [Email protected]:/root/tools
If the SSH default port is modified in order to 8888 use the following
Scp-p 8888/root/bb/api.war [Email protected]:/root/tools
? Remove the configuration line with # in front of the MY.CNF
MORE/ETC/MY.CNF |sed-n '/^#/!p ' >my2.cnf
? SSH executes the remote program and displays it locally
Ssh-p 22-n-L root 192.168.1.128 "Ls/root/tools"
Ssh-p 22-n-L root 192.168.1.128 "rm-rf/root/tools/dovecot-1.2.16-1_114.el5.i386.rpm"
? viewing process enablement times
Ps-a-opid,stime,etime,args|grep Java
? VI Alternate text
: N, $s/vivian/sky/g replace the nth line to the last row all Vivian are sky
? Display files in the most recent order by time
Ls-lt or Ll–t
? Sort files by size display
Ll-s
Netstat-an | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, s[a]} '
View the number of connections for each state in the system TCP connection.
Netstat-an |grep |grep ESTA |awk ' {print$5 ' \ n '} ' |awk ' BEGIN {fs= ': '} {print ' \ n '} ' |sort |uniq
View all IPs with native 80 port established and status in established
Netstat-n | awk '/^tcp/{n=split ($ (NF-1), Array, ":"), if (n<=2) ++s[array[(1)]];else++s[array[(4)]];++s[$NF];++n} END {for (A in S {printf ("%-20s%s\n", A, S[a]), ++i}printf ("%-20s%s\n", "Total_ip", I); for (A in s) printf ("%-20s%s\n", A, S[a]);p rintf (" %-20s%s\n "," Total_link ", n);} '
Outputs the number of connections per IP, and the total number of connections for each state
Recommended OPS shell commands