Archive for December, 2008

how to make bash display username, hostname and current working directory

Tuesday, December 23rd, 2008
Just add the following line:

PS1="\u@\h:\w$ "

in your .profile or .bashrc.

UNIX: how to find files that DO NOT match a pattern or other criteria

Saturday, December 20th, 2008
Most people with some basic command line skills can readily issue the unix find command to find files of a specific type or matching a specific pattern.

You can do the exact opposite, that is, find files that do not fulfil a specific criterion. The "secret" is to precede an exclamation mark (!) in the argument list, just before the criterion that you want to negate.

For example:

# find . -type f ! -iname "*.mp3"

The above command will find all files that have not an .mp3 extension.

How to create Shortcuts in Windows from the command line

Wednesday, December 3rd, 2008
It seems that there is not a direct way to create a shortcut from the command line in Windows. The solution presented here takes less than two minutes to set up and works pretty good. However, if you find a better one, I would like to know.

First you have to create a small text file by the name mkshortcut.vbs. Use your favorite text editor to edit the file, even notepad will do. Then copy the following text and paste it into the file:

set WshShell = WScript.CreateObject("WScript.Shell" )
set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk")
oShellLink.TargetPath = Wscript.Arguments.Named("target")
oShellLink.WindowStyle = 1
oShellLink.Save


Then save the file and exit the editor. Make sure that you move the file in a directory in your PATH (usually C:\WINDOWS\System32 is fine). Now, from the command line you can create shortcuts this way:

mkshortcut /target:TargetName /shortcut:ShortcutName

You will have to replace TargetName with the name of the target file and ShortcutName with the name of the shortcut to be created (do not include a .lnk extension!). For example:

C:\>mkshortcut /target:"c:/documents and settings/giannis/desktop" /shortcut:"My Desktop"

C:\>dir *.lnk
Volume in drive C has no label.
Volume Serial Number is 70FC-EBB4

Directory of C:\

12/03/2008  11:12 AM               453 My Desktop.lnk
1 File(s)            453 bytes
0 Dir(s)  46,659,989,504 bytes free

C:\>


Make sure that in target you include the full path of the target file name, starting with the drive letter and going down. For some reason Windows seem unable to create shortcuts with a relative path. Always use absolute paths for target.