Advertisement
xe1phix

Xe1phix-[PS]-Cheatsheet-[v4.8.92].sh

Oct 6th, 2022
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.86 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3.  
  4. ##-===========================================-##
  5. ##   [+] show top 10 process eating memory
  6. ##-===========================================-##
  7. ps auxf | sort -nr -k 4 | head -10
  8.  
  9.  
  10. ##-=========================================-##
  11. ##   [+] show top 10 process eating CPU
  12. ##-=========================================-##
  13. ps auxf | sort -nr -k 3 | head -10
  14.  
  15.  
  16. ##-===========================================-##
  17. ##   [+] Show Every Process Running As Root
  18. ##-===========================================-##
  19. ps -U root -u root u
  20.  
  21.  
  22. Which service(s) are been running by root?
  23. ps aux | grep root
  24. ps -ef | grep root
  25.  
  26.  
  27.  
  28. ##-========================================-##
  29. ##   [+] List All Threads For A process:
  30. ##-========================================-##
  31. ps -C firefox -L -o pid,tid,pcpu,state
  32.  
  33.  
  34. ##-=================================================-##
  35. ##   [+] Print User, Service And Num of Processes
  36. ##-=================================================-##
  37. ps -ef | awk '{print $1}' | sort | uniq -c | sort -nr
  38.  
  39.  
  40. ##-=========================================-##
  41. ##   [+] Print The Process ID of Rsyslogd
  42. ##-=========================================-##
  43. ps -C rsyslogd -o pid
  44.  
  45.  
  46. ##-===============================-##
  47. ##   [+] Print sshd Daemon PID
  48. ##-===============================-##
  49. ps -ef | awk '/sshd/ {print $2}'
  50.  
  51.  
  52. ##-=========================================-##
  53. ##   [+] Find The sshd Daemon, And Kill It
  54. ##-=========================================-##
  55. kill $(ps -ef | awk '/sshd/ {print $2}')
  56.  
  57.  
  58. ##-=============================================-##
  59. ##   [+] PSTree - Graphical list of processes
  60. ##-=============================================-##
  61. pstree --arguments --show-pids --show-pgids --show-parents
  62.  
  63.  
  64. ##-=================================================-##
  65. ##   [+] Print User, Service And Num of Processes
  66. ##-=================================================-##
  67. ps -ef | awk '{print $1}' | sort | uniq -c | sort -nr
  68.  
  69.  
  70. ##-========================================-##
  71. ##   [+] List All Threads For A process:
  72. ##-========================================-##
  73. ps -C $Service -L -o pid,tid,pcpu,state
  74.  
  75.  
  76. ##-===============================-##
  77. ##   [+] SSH Uptime Statistics:
  78. ##-===============================-##
  79. ps -eo pid,cmd,etime | egrep -E 'ssh-agent|gnome-keyring-daemon'
  80.  
  81.  
  82. ##-=======================================-##
  83. ##   [+] List processes in a hierarchy
  84. ##-=======================================-##
  85. ps -e -o pid,args --forest
  86.  
  87.  
  88. ##-=========================================-##
  89. ##   [+] Find Processes Being Run As Root
  90. ##-=========================================-##
  91. ps -ef | awk '$1 == "root" && $6 != "?" {print}'
  92.  
  93.  
  94. ##-=========================================-##
  95. ##   [+] Find Processes In A Zombie State:
  96. ##-=========================================-##
  97. ps aux | awk '{if ($8=="Z") { print $2 }}'
  98.  
  99.  
  100. ##-=================================-##
  101. ##   [+] Indepth Group Statistics
  102. ##-=================================-##
  103. ps -eo pid,command,size,vsize,%mem,gid,sgid,egid,fgid,sgroup,rgroup,group,fgroup,egroup,tpgid,tgid,flags
  104.  
  105.  
  106. ##-================================================-##
  107. ##   [+] Stack Statistics, esp eip nwchan etc...
  108. ##-================================================-##
  109. ps -eo pid,uid,user,command,vsize,esp,eip,stackp,nwchan,lwp,psr,nlwp,flags
  110.  
  111.  
  112. ##-=========================================-##
  113. ##   [+] Verbose User & UID Statistics
  114. ##-=========================================-##
  115. ps -eo uid,fuid,suid,ruid,euid,fuser,suser,user,uname,ruser,euser,command
  116.  
  117.  
  118. ##-======================================-##
  119. ##   [+] Verbose Mem & Cpu Statistics
  120. ##-======================================-##
  121. ps -eo uid,gid,user,group,command,size,vsize,sz,%mem,%cpu,flags
  122.  
  123.  
  124. ##-=======================================================-##
  125. ##   [+] pull out just the PID of the master SSH daemon:
  126. ##-=======================================================-##
  127. netstat -anp --tcp -4 | awk '/:22/ && /LISTEN/ { print $7 }' | cut -f1 -d/
  128.  
  129.  
  130. ##-=================================================-##
  131. ##   [+] Count processes related to HTTP server
  132. ##-=================================================-##
  133. ps aux | grep http | grep -v grep | wc -l
  134.  
  135.  
  136. ##-=================================================-##
  137. ##   [+] Display top 5 processes consuming CPU
  138. ##-=================================================-##
  139. ps -eo pcpu,user,pid,cmd | sort -r | head -5
  140.  
  141.  
  142. ##-========================================================================-##
  143. ##   [+] Display the top ten running processes - sorted by memory usage
  144. ##-========================================================================-##
  145. ps aux | sort -nk +4 | tail
  146.  
  147.  
  148. ##-==================================-##
  149. ##   [+] Print the PID of Chrome:
  150. ##-==================================-##
  151. chrome_pid=$(ps -aux | grep "[c]hrome --user-data" | awk '{ print $2 }' | head -n 1 2>/dev/null)
  152.  
  153.  
  154. ##-===============================-##
  155. ##   [+] Kill Chrome processes
  156. ##-===============================-##
  157. alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
  158.  
  159.  
  160. ##-=================================================-##
  161. ##   [+] Count processes related to HTTP server
  162. ##-=================================================-##
  163. ps aux | grep http | grep -v grep | wc -l
  164.  
  165.  
  166.  
  167.  
  168. (ps -aux; ps -ejH; ps -eLf; ps axjf; ps axms; ps -ely; ps -ef; ps -eF;  ps -U root -u root u; ) > ps-dump.txt
  169. (ps -eo 'pid,user,group,nice,vsz,rss,comm') > ps-table-dump.txt
  170.  
  171. ps aox 'pid,user,args,size,pcpu,pmem,pgid,ppid,psr,tty,session,eip,esp,start_time' > ps-columns.txt
  172.  
  173.  
  174. ps -eo pid,user,args --sort user
  175.  
  176. ps -eo pid,user,group,args,etime,lstart jgrep $PID
  177.  
  178. ps -eo pid,user,group,gid,vsz,rss,comm --sort=-rss | less
  179.  
  180. ps -ef --sort=user | less
  181.  
  182. List Processes By % Cpu Usage
  183. ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'
  184.  
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement