Operation and maintenance shell command

1. Display consumes memory / CPU 10 of the largest processes
ps aux | sort -nk +4 | tail -10
ps aux | sort -nk +3 | tail -10
2. view the number of concurrent requests to Apache and the TCP connection state
netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
3. find out the 10 most common commands and usage (or seeking access to the maximum number of IP)
sed -e ‘s/| n/g’ ~/.bash_history |cut -d ” -f 1 | sort | uniq -c | sort -nr | head
4.10th fields indicates that the connection in a log time, average 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 show processes from opening the file ABC.txt
: 22 know what port 22 is now running the program
ABC shows ABC process now open file
12 see the process process number 12 which files were opened
6. kill all processes that have a program
pkill -9 httpd
killall -9 httpd
Note as far as possible without9, on the database server is unable to easily kill or cause significant data loss would be disastrous.
7.rsync command (requires only one day of compressed files are synchronized, remote directory and conformance to the local directory)
/usr/bin/rsync -azvR –password-file=/etc/rsync.secrets ‘find . -name “*$yesterday.gz” -type f ‘ storage@192.168.2.23::logbackup/13.21/
8. renamed the *.sh files in a directory *. SH
find . -name “*.sh” | sed ‘s//(.*/)/.sh/mv /0 /1.SH/’ |sh find . -name “*.sh” | sed ‘s//(.*/)/.sh/mv & /1.SH/’|sh
(Same as above results)
Program 9.ssh remote and local display
ssh -n -l zouyunhao 192.168.2.14 “ls -al /home/zouyunhao”
10. change your password directly using the command line
echo “zouyunhaoPassword” |passwd –stdin zouyunhao ssh-keygen ssh-copy-id -i ~/.ssh/id_rsa.pub user@remoteServer
11. HTTP methods for sharing files in the current folder
python -m SimpleHTTPServer
Visit http://IP:8000/to download files in the current directory in the browser.
12.shell comments
:<<‘echo hello,world!’
13. check the Server serial number
dmidecode |grep “Serial Number”
(View a machine other hardware information available to this command)
14. see if the network card has reticle physical connection
/sbin/mii-tool
Here, I will add a few others found on the Internet that Shell command good ~ ~ ~
1, change the uppercase file names to lower case file names
for i in ‘find ./ -type f -name “[A-Z]*” | xargs -0′; do mv -f $i ‘echo $i | tr A-Z a-z'; done
2, zat view compressed files
Zcat install.log.tgz | SSH # filter must be added the-a parameter
3, killing procedures all processes, as with pkill function above
Pgrep httpd|xargs #pgrep filter out of the process, and then kill
4, fast backup of a file
cp filename{,.bak} #filename{,.bak}
This section will be expanded into a filename filename.bak then pass on CP
5, rename the file:
ls|xargs -t -i mv {} {}.bak
Size 6, tar packages don’t understand statistics:
tar tvf nrpe-2.8.1.tar.gz | awk ‘{total+=$3}END{print total}’
tar tvf nrpe-2.8.1.tar.gz | AWK ‘{total+=$3}END{print total/1024}’ #KB size
7, cross two files displayed
paste a.txt b.txt|tr “\t” “\n” paste a.txt b.txt|xargs -n1

Leave a Reply

Your email address will not be published. Required fields are marked *