Thursday, November 18, 2021

Rename files using power shell

I definitely miss Linux a lot. However, my main working environments are in Windows. It has been 5 years!

Just had a call with one of the customers. I need to rename 100+ files. Sigh. During the call, I had time pressure, and I couldn't tolerate with continuous of try and error. So, I used the slowest and safest but human-error-proned way of doing it, rename it manually, one by one.

We got silence moment in the call, then we suggested to communicate via email to sync up. Phew, pressure went away. So I did a quick Google search. I have tried to search for this solution for several times, but I never get it right, get it work. Probably I am still unconsciously resisting to PowerShell. Anyway, recently I seems to have more luck with PowerShell!

Then, in a few minutes, I finally found the "ultimate" solution!

Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace 'a','b' }


And then, suddenly I found out, I forgot how to do this in Linux... Sigh.

* update

This is the equivalent Linux command:

rename 's/a/b/' *.txt


Tuesday, November 16, 2021

WSL - Window Subsystem for Linux

I am not sure how old is this feature available in Windows 10. Recently, I screened through Turn Window features on or off list again and found this. I got excited, and turn it on. I have to admit, this is the best solution for me as of now, which I cannot install Virtual Box on this laptop for whatever reason or policy. :P

I did a search on Google and found this page Install WSL by Microsoft. But it says... You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11. I checked my system, it is running at a lower version. :(

Well, do you think it would stop me from continue? Of course not! If you have it available in the list, of course it should be ready to use!

So I go ahead and enable it. Then, maybe I restarted laptop. In case you want to know how and where to enable it, follow these steps.

1. Open Control Panel
2. Click on "Programs"
3. Click on "Turn Window features on or off"
4. A dialog box pop up, scroll to the end. You'll see this.



5. Click to the checkbox besides Windows Subsystem for Linux
6. Then, maybe restart your system? (I can't recall if I did this or not)

Next, install.. I selected Ubuntu 20.04 LTS.

7. Launch Microsoft Store
8. Search for Linux
9. Click on the Linux distibution that you want to install.
10. Click on the Get button to download
11. Follow the instruction to install

Gaodim!

One thing that doesn't work with this WSL is on the network related command. Here I list the few commands I tried which do not work, even after I have installed the necessary package.

$ show ip route
$ nmap
$ hping3


For example the hping3 command, you'll get the open_sockraw permission error, even you run with sudo!



And best part is, you cannot reboot. :D Unless you restart your Windows. I forgot what triggered me to do the reboot...



You can run this from command prompt. Open a DOS command window, and type wsl. You will get the shell running on your DOS environment!

In case you forgot your password, try this in DOS command window.

wsl -u root

It works like magic!



That's all for my sharing today. If you observed the screenshot earlier, I enabled the Windows Sandbox as well. It is another nice, cool feature that I use for some naughty testing! I'll find time to share it next time.