Monthly Archives: November 2013

Symbolic Links in Windows

Since Windows Vista we have possibility to create symbolic links on Windows. Yay!

To do that, we have command mklink in Command Prompt:

C:\Users\jj\Desktop>mklink link_to_some_file.txt c:\Dropbox\some_file.txt
symbolic link created for link_to_some_file.txt <<===>> c:\Dropbox\some_file.txt

Symbolic link is not a shortcut. However, its icon desktop looks the same:

link and shortcut icons in Windows

You can find out whether it is a link or shortcut by looking on the properties (left – link, right – shortcut):

link vs shortcut in Windows

You can also check it from the command prompt:
C:\Users\jj\Desktop>dir
Volume in drive C has no label.
Volume Serial Number is A425-1CEF

Directory of C:\Users\jj\Desktop

11/15/2013 10:36 AM <DIR> .
11/15/2013 10:36 AM <DIR> ..
11/15/2013 10:35 AM <SYMLINK> link_to_some_file.txt
11/15/2013 10:36 AM 921 some_file - Shortcut.lnk
2 File(s) 921 bytes
2 Dir(s) 15,738,155,008 bytes free

OT: Don’t you think dir command is to verbose? Who needs e.g. Volume Serial Number each time during listing directory?

In PowerShell, you need to use following command: cmd /c mklink (precede mklink with cmd /c).

I use it for my PowerShell config file. Original one is in Dropbox and symlink just point to it from MyDocuments directory (where it has to be, to be applied by PowerShell).


Windows PowerShell profile

Windows PowerShell is very powerful tool. It contains many useful commands. One of my favorite features is possibility to use some well-known bash commands such as: ls or pwd, which are missing in Windows Command Prompt. The cool thing is the fact, that PowerShell contains combination of Windows Command Prompt and Bash shell commands. E.g. for copying you can use copy (Windows) and cp (Bash).

You can also have personal configuration file (like .bashrc in Unix) to set some persistent settings. To find out, where it is located use command:

PS C:\> echo $PROFILE
C:\Users\jj09\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

I needed to create directory ‘WindowsPowerShell’ and profile file before adding some custom settings. Additionally, I needed to enable scripts on my system (it is disabled by default).

PS C:\> Set-ExecutionPolicy RemoteSigned

More info about Execution Policies can be found here.

My Microsoft.PowerShell_profile.ps1 file:

set-alias subl "C:\Program Files\Sublime Text 2\sublime_text.exe"
set-alias grep select-string
set-alias ssh New-PSSecureRemoteSession
set-alias sh New-PSRemoteSession
set-alias l ls

There is also ‘Power’ version of PowerShell called ISE (Integrated Scripting Environment). Be aware, that it has different profile file (for me it is: C:\Users\jj09\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1). You can check it with the same command like for standard PowerShell (echo $PROFILE). Here is a list of top 10 killer features, which are in ISE, but not in standard PS (Intellisense is my favorite).

PowerShell-autocomplete

Disadvantage of PowerShell is its loading time. Windows Command prompt loads instantaneously, but PS need ~1 second. It is even worse in case of ISE, which needs ~3 seconds (on my Thinkpad X220: i5/8GB/SSD).

You can add custom configuration to Windows Command Prompt too. To do that you need to run command prompt with some arguments.