5 ms·
The Windows equivalents of the most used Linux commands
- jpease 6mo agoCTRL-ALT-DEL?
- jmclnx 6mo agoNot bad, but one big criticism, never do a 'kill -9' first, that will stop the program from cleaning up after itself if killed using -9. Use one of these instead: -TERM then wait, if not -INT then wait, if not -HUP then wait, if not -ABRT If you are sure all of these fail, then use -9 (-KILL). But assume the program has a major bug and try and find another program that will do the same task and use that instead.
- BenjiWiebe 6mo agoHow often does plain 'kill <pid>' not work, but some other signal other than SIGKILL works? Usually the process is either working correctly and terminates when asked, or else not working correctly and needs to be KILLed.
- consp 6mo agoLots of commandline tools will hold on to dear life except for the sigkill. I often have this with running background tasks which get one of their threads in an infinite loop or wait state.
- chasil 6mo agoIt is possible to install a handler for most signals, and that handler can be configured to ignore the signal. Signal 9 cannot be ignored.
- gottheUIblues 6mo agoI don't think of 9 as really being a signal to the process at all, more of an instruction to the OS kernel to terminate the process
- adrianmonk 6mo agoMaybe this logic should be built into the "kill" command (or some other standard command). Given that this is the right way, it shouldn't be more tedious than the wrong way! It could also monitor the target process and inform you immediately when it exits, saving you the trouble of using "ps" to confirm that the target is actually gone.
- eptcyka 6mo agoKill is not a command to kill processes, it is a misnomer. Kill is meant to send signals to processes.
- jolmg 6mo agoDifferent programs may take different amounts of time to cleanup and close. To know if a signal failed takes human judgment or heuristic. A program receiving a signal is even able to show a confirmation dialog for the user to save stuff, etc. before closing.
- adrianmonk 6mo agoThat's a valid point. Another example is SIGHUP, which will cause some programs to exit but other programs to reload their config file. In certain very specific cases, that could even cause harm. So really what "kill" would be doing is automating a common procedure, which is different than taking responsibility for doing it correctly. It would need to be configurable. I still think it would be a net benefit since right now incentives push people toward doing something the wrong way (even if they know better). But I can also see how it might give people a false sense of security or something along those lines.
- jolmg 6mo ago> automating a common procedure It's not common. If `kill` on its own (which does just SIGTERM) doesn't work, you're already in "something wrong is happening" territory, which is why: >>> Given that this is the right way, it shouldn't be more tedious than the wrong way! is also the wrong way to think about this. Trying a sequence of signals is not so much "the right way" as it is "the best way to handle a wrong situation". The right way is just `kill` on it's own. SIGTERM should always suffice. If it doesn't to the user's satisfaction for a nonjustifiable reason, then you can just `kill -9`, but this should be rare. Trying a sequence of SIGINT, SIGHUP, and SIGABRT is technically better than SIGKILL but not really important unless you also want to write a bug report about the program's signal handling or fix it yourself. About SIGINT and SIGHUP, if SIGTERM doesn't work, it's unlikely that SIGINT or SIGHUP would. Likely, it would only be through oversight and the execution of default handlers. `kill -9` is just like `rm -rf`. I wouldn't suggest that `rm` automatically run with `-r` or `-f` when `rm` on its own didn't work, and I wouldn't call automatically trying those flags "the right way".
- consp 6mo agoThis is article is likely LLM generated and it regurgitates as first go what the last resort should be. After seeing that command I stopped reading.
- eptcyka 6mo agoNever use `kill -9`, instead refer to the signal directly. 9 is not always the same signal on all platforms.
- chasil 6mo agoHUP is usually sent to daemons to instruct them to reinitialize and reread their configuration files. Is it still passed when a terminal is disconnected? I understand a dial-up modem was involved in the original intended use.
- trympet 6mo agoOn a modern OS, doesn’t the kernel (eventually) take care of the cleanup anyways?
- WaterRun 6mo agoI recently had a similar idea. https://github.com/Water-Run/Cmdset https://github.com/Water-Run/Cmdset
- Akuehne 6mo agoMy most used windows command is, and will always be, `ls`. Then I'm reminded that it's not a know file or directory.
- IcyWindows 6mo agoIt's been nearly 20 years since powershell came out.
- SoftTalker 6mo agoAnd we had cygwin before that. First thing I always installed on a Windows box so I could use bash and all my favorite utilities.
- moi2388 6mo agoAnd it still sucks
- smackeyacky 6mo agoCygwin was so much work but you’re still stuck in windows.
- deleted 6mo ago[deleted]
- gib444 6mo agoSame! Closely followed by 'cat' lol. 'type' just doesn't register in my brain
- chasil 6mo agoVMS also uses type to dump a file to stdout. I understand that DEC TOPS 20 influenced CP/M and MS-DOS, so that could be the source for type. https://en.wikipedia.org/wiki/TOPS-20 https://en.wikipedia.org/wiki/TOPS-20 Edit: type has its own wiki, and TOPS-20 implemented it. https://en.wikipedia.org/wiki/TYPE_(DOS_command) https://en.wikipedia.org/wiki/TYPE_(DOS_command)
- 8note 6mo agook, but how do i get the only linux command i know? ctrl+r
- usr1106 6mo agoWorks just fine in powershell. Avoid using command prompt and life is already a bit better
- thunderbong 6mo agoF7
- malbs 6mo agofindstr is an underappreciated command line tool. I use it a lot
- hackyhacky 6mo ago> Author's note: From here on, the content is AI-generated Kudos to the author for their honesty in admitting AI use, but this killed my interest in reading this. If you can use AI to generate this list, so can anyone. Why would I want to read AI slop? HN already discourages AI-generated comments. I hope we can extend that to include a prohibition on all AI-generated content. > Don't post generated comments or AI-edited comments. HN is for conversation between humans.
- rmunn 6mo agoIf the author had also included a note explaining that he'd *reviewed* what the AI produced and checked it for correctness, I would be willing to trust the list. As it is, how do I know the `netstat` invocation is correct, and not an AI hallucination? I'll have to check it myself, obviating most of the usefulness of the list. The only reason such a list is useful is if you can trust it without checking.
- tobyhinloopen 6mo agoHow would you know the invocation is correct when written by a human? Don’t humans make mistakes?
- rmunn 6mo agoSure, humans make mistakes... but rarely, vanishingly rarely about commands they use often. Are you going to make a non-typo kind of mistake when typing `ls -l`? AI hallucinations don't happen all the time, but they happen so much more often than "vanishingly rarely". That's why you can't just vibe-code something and expect it to work 100% correctly with no design flaws, you need to check the AI's output and correct its mistakes. Just yesterday I corrected a Claude-generated PR that my colleague had started, but hadn't had time to finish checking before he went on vacation. He'd caught most of its mistakes, but there was one unit test that showed that Claude had completely misunderstood how a couple of our services are intended to work together. The kind of mistake a human would never have made: a novice wouldn't have understood those services enough to use them in the first place, and an expert would have understood them and how they are supposed to work together. You always, always, have to double-check the output of LLMs. Their error rate is quite low, thankfully, but on work of any significant size their error rate is pretty much never zero. So if you don't double-check them then you're likely to end up introducing more bugs than you're fixing in any given week, leading to a codebase whose quality is slowly getting worse.
- themafia 6mo ago> Windows: netstat -n -a | findstr "https" (//note the double quotes) netstat works perfectly fine on linux as well. If you're looking for https connections it's certainly far more efficient than 'lsof'. also if you use '-n' then you're not going to get service names translated, so that probably should be: netstat -n -a | find "443"
- HDBaseT 6mo agotraceroute vs tracert always catches me out.
- not_a_bot_4sho 6mo agoA great non-AI resource on this topic: https://ss64.com/ https://ss64.com/
- flexagoon 6mo ago> Finding a specific file by name across the system > Linux: find / -name "config.txt" This is not how you find a file across the entire system, you use plocate for that. find would take ages to do what plocate does instantly
- gib444 6mo agoNo. "Slower" is not the same as "different functionality". In fact, "find" is guaranteed to be more correct. And more widely available.
- Nux 6mo agoYes and no, with `find` I know I'm getting "live" results from the filesystem, whereas plocate (and s/locate) merely searches through a database updated god knows when, assuming it's even installed and the bulk of the files indexed.
- owlstuffing 6mo agoNot having to run a mess of Linux commands to install software.
- tpoacher 6mo agoCan we do a satirical thread here please? I'm curious what HN can come up with :D I'll start: Linux : trash-empty windows equivalent: format C: Linux : sudo apt update && sudo apt upgrade Windows equivalent: shutdown /r
- srott 6mo agoless or at least more?
- red_admiral 6mo agowhich / where is the one that always trips me up.
- voidUpdate 6mo ago> "Author's note: From here on, the content is AI-generated" Ah, I see, googling the equivalent of "clear" was too much work and you had to get an LLM to do it for you. Well at least you were honest about it
- lietuvis 6mo agoWhat is even the point having this post when its literally a prompt
- Skywalker13 6mo agoridiculous... Why this entry is in the top 30?
- elsadek 6mo agoNot ridiculous as long as there are still who need to learn. right? That said, I didn't see that coming
- quanta-rs 6mo agoWhy would you use CMD when Powershell exists?
- smackeyacky 6mo agoBecause powershell is weird and obtuse? Or because powershell works slightly different in the terminal va the powershell dev environment? Its a tool most of us use under duress rather than choice
- dahauns 6mo agoI certainly won't argue that pwsh is even close to perfect, but...obtuse is just about the most unfitting description of powershell. It offers a level of structure and consistency that is - even with all its shortcomings - orders of magnitude above the wild west of the daily reality of the linux cli. Just because it's the mess we are all intimately familiar with, doesn't make it less of a mess.
- Grisu_FTP 6mo ago"Just because it's the mess we are all intimately familiar with, doesn't make it less of a mess." I kinda feel like you could apply the statement more to powershell tho. I just dont see how Remove-Item is superior to rm and thats just the first example that came to mind (Atleast there are aliases for most stuff afaik so i guess its not AS bad). I also just googled and there seem to be 3-4 different commands (not including the aliases) that do EXACTLY the same thing, atleast the Microsoft article used 1:1 the same description for all of them.
- m4ck_ 6mo agorm only removes files and directories right? Remove-Item can be used for any powershell provider, such as environment variables, active directory, certificates, and registry. And of course you can implement your own providers that utilize *-item cmdlets. I don't know that i'd call either superior, or that i'd even say that they're equivalent. rm is a utility for removing files, remove-item is a little more than that.
- wernsey 6mo agoCan I just do a shout-out for UnxUtils [1]? I've had it on every Windows computer I used at work since forever now, and it is extremely useful to be able to use things like `sed` and `gawk` (and even `make`) from the command prompt [1] https://unxutils.sourceforge.net/ https://unxutils.sourceforge.net/
- smackeyacky 6mo agoYuck. Just install WSL and be done with it
- pjc50 6mo agoUnderrated secondary option: git bash. Lower setup overhead than full WSL, although it is slower if you need to work on a lot of files or spawn a lot of processes.
- anthk 6mo agoAlso, Minc, MinC is not Cygwin. And, yes slower, but it might work even under XP.
- smackeyacky 6mo agoI guess you get git bash for free when you install git, which speaks legions about the pain of powershell
- Ciantic 6mo agoLet me present you my favorite, how do you figure out dirname, basename and filename in batch script? set filepath="C:\some path\having spaces.txt" for /F "delims=" %%i in (%filepath%) do set dirname="%%~dpi" for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi" for /F "delims=" %%i in (%filepath%) do set basename="%%~ni" echo %dirname% echo %filename% echo %basename% It is just as intuitive as one would expect.
- dahauns 6mo ago$file = Get-ChildItem "C:\some path\having spaces.txt" Write-Output $file.DirectoryName Write-Output $file.Name Write-Output $file.BaseName Or if that's still to verbose: $file = gci "C:\some path\having spaces.txt" echo $file.DirectoryName echo $file.Name echo $file.BaseName People should really get over their aversion against powershell.
- m4ck_ 6mo agoYou could just one line it too: Get-Item "C:\some path\having spaces.txt" | select DirectoryName, Name, Basename
- abhikul0 6mo agoOr you can just prepend `wsl` to the linux command you want to run; of course only if you have wsl setup. https://learn.microsoft.com/en-us/windows/wsl/filesystems#run-linux-tools-from-a-windows-command-line https://learn.microsoft.com/en-us/windows/wsl/filesystems#ru...
- gbro3n 6mo agoReally? That's awesome