Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

January 6, 2021

Updating Windows File Permission from Command Line

Here's how to update Windows file system permission from the command line, using the icacls tool that comes with Windows (C:\Windows\System32\icacls.exe):

icacls ".\folder\*.*" /grant BUILTIN\Users:(RX)

In the example above, it adds Read and Execute permissions to BUILTIN\Users.

September 12, 2020

Git Bash Prompt Showing Date and Time on Windows

Sometimes I have Git Bash open for several days, and knowing when I executed a particular command is helpful. Here's a quick-and-dirty way of showing the date and time in the bash prompt, which came about from looking at C:\Program Files\Git\etc\profile.d\git-prompt.sh and doing echo $PS1.

  • Copy the following content into a text editor and save it as .profile in the %USERPROFILE% folder:
PS1="\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[94m\]\D{%m/%d %H:%M:%S} \[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]"'`__git_ps1`'"\[\033[0m\]\n$ "
MSYS2_PS1="$PS1"
  • Run source .profile to reload the prompt.

For the full list of configurable colors, refer to ANSI Color Escape Codes.

So how did I know to create the .profile file? There's a .bash_profile file in the %USERPROFILE% folder:

# generated by Git for Windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

Windows Terminal

Lately, I've been trying out Windows Terminal with oh-my-posh for PowerShell (based on the post by Scott Hanselman). You can also host cmd, bash (via wsl), etc., in Windows Terminal... I fear my days of using plain cmd and Git Bash on Windows will come to an end soon, though I'll surely miss the start up time of cmd.

February 27, 2018

Touch Command on Windows

Windows still doesn't include touch command... A quick search on Google brings up several posts in StackOverflow, and PowerShell seems to be the best option. With Microsoft now letting you run Linux natively on Windows, perhaps it will never be included in Windows itself.

Examples:

PS C:\> $(Get-Item ".\UseCurrentDateTime.txt").LastWriteTime=$(Get-Date)
PS C:\> $(Get-Item ".\UseSpecificDateTime.txt").LastWriteTime=$(Get-Date "2/26/2018 9:00 PM")

Use the tab key for auto-completion.

Other properties: CreationTime, LastAccessTime

March 23, 2017

Automatically restarting after reboot

I've noticed that some programs, such as Chrome, automatically restarts after a forced reboot from Windows Update. So out of curiosity, did some googling, and found that there's something called Restart Manager. Works the way I thought it would work — listen for some messages during the shutdown process to save state, and register with Windows to have it start the program after reboot.

"shutdown -g" will also restart registered programs after reboot.