It's 2026, you should not be using command prompt (or batch.) In powershell ls is a built in alias to get-childitem and has been for years, and in recent versions of windows you'd have to go out of your way to get a command prompt (you would have to open a powershell terminal and then run cmd.)
On one our linux machine filesystem became strange, probably because somebody mistyped `ls /bin` as `ln /bin`. I think docs say hardlinking folders is impossible or maybe /bin was a symlink.
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
Underrated 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.
Let 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%
> 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.
If 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.
I could've done better with research, but this post has been collecting dust in the drafts, so I decided to try my first (and last) time to finish the work I started a few months ago.
Not 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.
Maybe 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.
Different 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.
Lots 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.
Its very likely that its just because i have almost no experience with powershell meanwhile i have now ~4-5 years of dailying linux but i just find the powershell commands to be very cumbersome to use.
They are wayyy to long and descriptive instead of just 2-4 letters, there are 500 different commands for very specific uses instead of 10 tools that you can use and combine todo almost everything and if i recall correctly (my memory might trick me here tho) the errors are far less readable at a first glance and fill the entire terminal for simple things.
CMD meanwhile feels like bash.
Most of my issues with it are probably just skill issues tho since like i said i dont really use or know it alot so i am happy to be corrected :) I mean if every Windows Sysadmin tells me how great powershell is, i cant just assume that they all are wrong (Or maybe its just the only way todo something thats otherwise simple over the terminal on windows, idk)
The verbosity especially in cmdlet names kind of sucks but having everything be an object with properties and methods, vs having to chop up and parse and pipe text is quite nice. I haven't had the pleasure of being a linux admin professionally so I don't have much experience on the linux side.. but just like a really simple example of getting in interface's IP address.. Grabbing a property from get-netipaddress is easier/faster/simpler to me than chopping up text output from ifconfig.
This applies to errors of course, there are a number of properties for an error that you can look at (and use in scripts to handle errors) if the full output is too much or unclear.
Because 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
I 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.
"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.
rm 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.
Yes 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.
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
reply