14,954
edits
Tags: Mobile edit Mobile web edit |
|||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
(1) | (1) Different Linux commands that achieve the same outcome, | ||
(2) | (2) Commands that are either equivalent or alike across Windows and Linux systems. | ||
== Help for command == | == 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 289: | 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 484: | Line 499: | ||
=== Clean the screen/console === | === Clean the screen/console === | ||
* {{Win}}: {{kbd | key= cls}} <ref>[https://technet.microsoft.com/en-us/library/bb490879.aspx Cls]</ref> | * {{Win}}: {{kbd | key= cls}} <ref>[https://technet.microsoft.com/en-us/library/bb490879.aspx Cls]</ref> | ||
* {{Linux | * {{Linux}}: {{kbd | key= clear}} <ref>[https://www.linux.org/threads/clear-clear-your-terminal-screen.78/ Clear! (clear your terminal screen) | Linux.org]</ref> | ||
* {{Mac}} | |||
** {{kbd | key= clear}} | |||
** {{kbd | key=⌘ command}} +{{kbd | key=K}} <ref>[https://stackoverflow.com/questions/2198377/how-can-i-clear-previous-output-in-terminal-in-mac-os-x macos - How can I clear previous output in Terminal in Mac OS X? - Stack Overflow]</ref> | |||
== help for command == | == help for command == | ||
| Line 512: | 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]] | |||