Linux commands: Difference between revisions

Jump to navigation Jump to search
1,624 bytes added ,  18 December 2025
m
Tags: Mobile edit Mobile web edit
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:


== Help for command ==
== Help for command ==
: [[Image:Owl icon.jpg]] Help for command:  
{{Tips}} Help for command:  


* {{Gd}} [https://explainshell.com/ explainshell.com - match command-line arguments to their help text]
* {{Gd}} [https://explainshell.com/ explainshell.com - match command-line arguments to their help text]
Line 290: Line 290:
* {{kbd | key=kill -9 <PID>}}. Force to kill the process with PID number: 101, enter {{kbd | key=kill -9 101}}. <ref>[http://linux.vbird.org/linux_basic/0440processcontrol.php#killjobs 鳥哥的 Linux 私房菜 -- 第十六章、程序管理與 SELinux 初探]</ref>
* {{kbd | key=kill -9 <PID>}}. Force to kill the process with PID number: 101, enter {{kbd | key=kill -9 101}}. <ref>[http://linux.vbird.org/linux_basic/0440processcontrol.php#killjobs 鳥哥的 Linux 私房菜 -- 第十六章、程序管理與 SELinux 初探]</ref>


Kill the process by process name<ref>[https://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex Find and kill a process in one line using bash and regex - Stack Overflow]</ref>
'''Kill the process by process name'''<ref>[https://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex Find and kill a process in one line using bash and regex - Stack Overflow]</ref>
* {{kbd | key=<nowiki>sudo kill $(ps aux | grep '<NAME>' | awk '{print $2}')</nowiki>}}
* {{kbd | key=<nowiki>sudo kill $(ps aux | grep '<NAME>' | awk '{print $2}')</nowiki>}}
'''Kill the process by port number'''<ref>[https://stackoverflow.com/questions/11583562/how-to-kill-a-process-running-on-particular-port-in-linux How to kill a process running on particular port in Linux? - Stack Overflow], [https://linux.die.net/man/8/lsof lsof(8) - Linux man page]</ref>
* {{kbd | key=<nowiki>kill -9 $(lsof -ti:3000) 2>/dev/null</nowiki>}}: Force kill the process using port 3000. The {{kbd | key=2>/dev/null}} suppresses error messages if no process is found. Replace 3000 with your target port number.
* Alternative (shorter command): {{kbd | key=fuser -k 3000/tcp}}: Kill the process using TCP port 3000 (if {{kbd | key=fuser}} is available on your system)
Explanation:
* {{kbd | key=<nowiki>lsof -ti:3000</nowiki>}}: Find the process ID (PID) using port 3000
** {{kbd | key=-t}}: Output only the PID
** {{kbd | key=-i:3000}}: Filter by port 3000
* {{kbd | key=2>/dev/null}}: Redirects error messages (stderr) to {{kbd | key=/dev/null}} (discards them) Useful when no process is found on the port to avoid error output
* {{kbd | key=<nowiki>$(lsof -ti:3000)</nowiki>}}: Command substitution<ref>[https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html Command Substitution (Bash Reference Manual)]</ref>: executes the command inside {{kbd | key=$()}} and replaces it with the output
** First runs {{kbd | key=lsof -ti:3000}} to get the PID(s)
** Then substitutes the PID(s) into the {{kbd | key=kill -9}} command
** Example: if port 3000 is used by PID 12345, {{kbd | key=<nowiki>kill -9 $(lsof -ti:3000)</nowiki>}} becomes {{kbd | key=kill -9 12345}}


=== Find process running on port ===
=== Find process running on port ===
Line 516: Line 530:
* [[Open command window here]]
* [[Open command window here]]


[[Category:Linux]]
[[Category: Linux]]
[[Category:Windows]]
[[Category: Windows]]
[[Category:Database]]
[[Category: Database]]
[[Category:MySQL]]
[[Category: MySQL]]
[[Category: Revised with LLMs]]

Navigation menu