Linux classic skills

Source: Internet
Author: User
1. process by memory in ascending order: ps-eo & quot; % C: % p: % z: % a & quot; | sort-k5-nr2. view which processes are currently available; view the files opened by the process: ps-A; lsof-pPID3. obtain the current IP address (learn the role of grep, awk, cut) ifconfigeth0 | grep & quot; inetaddr: & quot; | awk & #39; {print $2 }&

1. process sorting by memory from large to small:
Ps-eo "% C: % p: % z: % a" | sort-k5-nr

2. check which processes are currently running; view the files opened by the process:
Ps-A; lsof-p PID

3. get the current IP address (learn the role of grep, awk, and cut)
Ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut-c 6-

4. count the frequency of each word and sort it.
Awk '{arr [$1] + = 1} END {for (I in arr) {print arr "\ t" I}' file name | sort-rn

5. display 10 of the most common commands
Sed-e "s/|/\ n/g "~ /. Bash_history | cut-d ''-f 1 | sort | uniq-c | sort-nr | head

6. killing Nginx processes (killing a process)
Ps-ef | grep-v grep | grep nginx | awk '{print $2}' or
For I in 'PS aux | grep nginx | grep-v grep | awk {'print $ 2'} '; do kill $ I; done

7. list the directory size of the current folder, which is displayed in G, M, and K.
Du-B -- max-depth 1 | sort-nr | perl-pe's {([0-9] +)} {sprintf "%. 1f % s ", $1> = 2 ** 30? ($1/2 ** 30, "G"): $1> = 2 ** 20? ($1/2 ** 20, "M"): $1> = 2 ** 10? ($1/2 ** 10, "K"): ($1, "")} e'

Shaw answer: du-hs $ (du-sk./'ls-F | grep/'| sort-nr | awk' {print $ NF }')
But it is not perfect. But remember.

8. Clear linux buffer cache
Sync & echo 3>/proc/sys/vm/drop_caches

9. convert all file names in the current directory to lowercase letters.
For I in *; do mv "$ I" $ (echo $ I | tr A-Z a-z) "; done

10. several methods to eliminate ^ M in vim
1) dos2unformatted filename
2) sed-e's/^ M // 'filename
3) in vim: s/^ M // gc
4) col-bx <dosfile> newfile
5) tr-s "\ r \ n" "\ n" <file> newfile

11. clear all arp caches
Arp-n | awk '/^ [1-9]/{print "arp-d" $1}' | sh

12. bind the arp address of a known Machine
Cat/proc/net/arp | awk '{print $1 "" $4}' | sort-t.-n + 3-4>/etc/ethers

13. perl-ne 'M/^ ([^ #] [^ \ s =] +) \ s * (=. * |)/& printf ("%-35 s % s \ n", $1, $2) '/etc/my. cnf


14. a user is not allowed to use the rm command.

[Root @ localhost pp] # setfacl-m u: pp: 000/bin/rm
[Root @ localhost pp] # su-pp
[Pp @ localhost ~] $ Mkdir test
[Pp @ localhost ~] $ Rm-rf test/
-Bash:/bin/rm: insufficient permissions

Modify back Command

[Pp @ localhost ~] $ Su root
Password:
[Root @ localhost pp] # setfacl-m u: pp: rwx/bin/rm
[Root @ localhost pp] # su-pp
[Pp @ localhost ~] $ Rm-rf test/
[Pp @ localhost ~] $

15. package and exclude directory usage

Tar zcvf family.tar.gz./family/* -- exclude =./family/1/ss/attachments -- exclude =./family/1/ss/bbs/attachments


16. Upload folders in command line mode in linux

Ncftpput-R-u user-p 'passwd'-P 21 192.168.1.1/home/test // root/test (original directory)

4. view the top 15 programs that occupy the most memory

Ps-aux | awk '{print $4 "\ t" $11}' | grep-v MEM | sort-r | uniq-c | head-15

Ps (shift + M View memory usage, shift + p view cpu)


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.