Creating aliases in windows

Console Aliases

This document describes console platform functionality that is no longer a part of our ecosystem roadmap. We do not recommend using this content in new products, but we will continue to support existing usages for the indefinite future. Our preferred modern solution focuses on virtual terminal sequences for maximum compatibility in cross-platform scenarios. You can find more information about this design decision in our classic console vs. virtual terminal document.

Console aliases are used to map source strings to target strings. For example, you can define a console alias that maps «test» to «cd \a_very_long_path\test». When you type «test» at the command line, the console subsystem expands the alias and executes the specified cd command.

To define a console alias, use Doskey.exe to create a macro, or use the AddConsoleAlias function. The following example uses Doskey.exe :

doskey test=cd \a_very_long_path\test

The following call to AddConsoleAlias creates the same console alias:

To add parameters to a console alias macro using Doskey.exe , use the batch parameters $1 through $9 . For more information on the special codes that can be used in Doskey macro definitions, see the command-line help for Doskey.exe or Doskey on TechNet.

All instances of an executable file running in the same console window share any defined console aliases. Multiple instances of the same executable file running in different console windows do not share console aliases. Different executable files running in the same console window do not share console aliases.

To retrieve the target string for a specified source string and executable file, use the GetConsoleAlias function. To retrieve all aliases for a specified executable file, use the GetConsoleAliases function. To retrieve the names of all aliases for which console aliases have been defined, use the GetConsoleAliasExes function.

Create command-line alias in windows

Aug 21, 2019 · 2 min read

Many time we need to use the same commands all-time in the terminal example:

  1. change directory to a long path like-

2. Open your server ssh terminal every time you need to run ssh commands like —

We can set an alias to quickly execute to a particular command like-

But as we close the terminal so it would not work any more. How to make it permanent.

  1. Create a batch file here we can write Doshkey commands

2. Copy command prompt shortcut to desktop/ any location you want —

3. Rename it to any name — alias

4. now provide a path of the batch file to this shortcut by —

a. right click on icon select properties -> shortcut

b. In target give space and add

Done. Now you can easily access your all alias by opening this shortcut

You can now put any number of alias in .bat file

Plea s e give a clap if you like this post. Also, write in the comment section.

Shivam Gupta

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK. Love to write cool stuff

Alias in Windows and it’s Fun Applications using Python

I was wondering how could I possibly get a python script to run automatically every time I open the command-line. I believe that it could have some fun applications.

I imagined opening up the command-line and writing

todo “Learn Ableton Live 10”

to add “Learn Ableton Live 10” to a To-Do List (.txt file).

But how could I pull this off? I mean, obviously, the command-line does not recognize ‘todo’ command and how would I call a python script by hitting ‘todo’ anyway…

This is where ‘Alias’ comes into the picture!

Читайте также:  Ezp2014 drivers windows 10

What is an Alias?

An alias, as the name refers provides an alternate name for existing names. Alias is usually an easier-to-understand name for a defined data object.

For you to understand the idea of alias, I am going to say that “sup” is an alias to “wassup” which itself is an alias to “what’s up” 😛

So we are basically talking about making our own lingos in programming. Doesn’t it sound cool already? 😎

How is Aliasing Useful?

If you type ‘cls’ in a Windows command-line or ‘clear’ in Linux terminal and hit enter, it clears everything out from there. We could make an alias ‘c’ just to perform the same task.

Also, we often have a directory which we frequently have to visit via the terminal by using the ‘cd’ command. It becomes very frustrating to use the ‘cd’ command every time we open a new terminal to enter into that directory, especially when the directory has a very long path. This is another appropriate use case of setting up an alias.

And similarly, we can make aliases for various different commands that are valid for a command-line.

How to Create an Alias in Windows?

Let’s now learn how to create an alias. Belonging to an intelligent species, you might have already figured out how to create an alias, after seeing the 2 examples that I used earlier.

You got that correct!

We use ‘doskey’ command to create an alias. We write ‘doskey’, then the alias name followed by the equal to sign (‘=’ ) further followed by the command that the alias is supposed to run.

How to Call an Alias?

Once we are done creating the alias, calling them is as simple as typing the name of the alias and hitting the enter key in the command-line!

Let’s see the alias ‘teleport’ that we created earlier in action now.

Creating an Alias for a Python Program?

Now that we know how to create an alias, it seems pretty straightforward to figure out the way how we can create an alias for calling a python script.

We use the ‘doskey’ command and assign the command for running a specific python script, to an alias using the equal to sign (‘=’).

Here my alias named “todo” is supposed to run the python script called “todo_list_maker.py” which is located at “C:/Users/anime/Documents/Python Scripts/todo_list_maker/”.

The python script “todo_list_maker.py” takes an input (a to-do list item) from the command-line and puts it in a todo_list.txt

But how do we pass in the arguments to our python script?

It is actually quite simple. All we need to do is add a dollar sign and an asterisk (“$*”) at the end of the alias assigning step in the way it is mentioned down below. It allows the inputs to the python script to be passed while calling the alias.

I have used argparser for parsing the arguments from the command-line in todo_list_maker.py

Mentioned below is the python script ‘todo_list_maker.py’

And following is the command that we need to use in the command-line to call the alias “todo” and add a to-do list item in the to-do list.

And as expected it generates a to-do list (.txt file) on the Desktop (by default)

and adds the to-do list item in it.

So this is how we create an alias for calling a python script and pass arguments in it through the alias.

But there is a last piece of information that I would like to add in this blog. The aliases do not work when we try to call them in a new command-line. This can be fixed by making a Batch or BAT file (.bat file) which would hold the command(s) that would run every time a new command-line terminal is opened.

In Windows, the batch file is a file that stores commands in a serial order. Command-line interpreter takes the file as an input and executes the stored commands in the same order. A batch file is simply a text file saved with the .bat file extension. It can be written using Notepad or any other text editor.

Читайте также:  Mac os pantum ica driver доступ

So we make a BAT file and save it at any location on the computer (Note this location as you would be using this location in a short while). Following is the BAT file that I made. It will first execute the “echo” command and then then the “doskey” command, each and every time a new command-line is opened.

Now we go to the Windows Search option and type “cmd” and then click on “Open file location” option.

We then right-click on the “Command Prompt” icon and select the “Properties” option.

Then we select the “Shortcut” tab and add

“/k C:\Users\anime\doskey_for_python.bat” (/k path_of _the _bat_file) in the “Target” field.

Hit “Apply” and ‘OK’ and we are done.

Now every time we open a new command-line, the BAT file is executed and our alias is ready to be used. This holds true even after we restart the computer which is exactly how we would want it to be.

So finally our “todo” command is ready to be used in the command-line to add new to-do list items in the to-do list.

We can now combine the idea of alias with the infinite functionalities that python brings to the table, to make fun commands do useful tasks!

You can find the code for this “todo list maker” application on my GitHub account by clicking on this link https://github.com/n0obcoder/fun-with-python/tree/master/todo_list_maker

The README.md file provides a decent documentation of the todo_list_maker.py. Please feel free to explore it and add more functionalities to it 🙂

I am writing this blog because I have learned a lot by reading other’s blogs and I feel that I should also write and share my learnings and knowledge, as much as I can. So please leave your feedback in the comments section below to let me know how can I improve my future blogs! 😀

Creating aliases in windows

В процессе работы web-программисту часто приходится пользоваться командной строкой. Это может быть работа с git, установка библиотек через npm или commposer. Создание шаблона приложения. Очистка кэша web-приложения. Управление миграциями базы данных и т.д.

В таком случае могут возникнуть 2 проблемы. Во-первых нужно постоянно печатать повторяющиеся команды. Либо копировать откуда-то. Во вторых нужно помнить эти самые команды. Что тоже бывает сложно. Например команда создания миграции в symfony 3 выглядит так.

В какой-то момент это все надоедает и хочется создать сокращения для команд. Под Windows можно сделать с помощью doskey.

Alias можно создать такой командой. Однако это работает только для текущей сессии.

Если хочется создать много алиасов, имеет смысл создать .bat файл и записать туда все алиасы. Сохранить файл в удобном месте, например так:

Далее нужно сделать так, чтобы все это применялось автоматически при старте системы. Для этого нужно зайти в редактор реестра, выполнив команду regedit.

Далее найти ключ HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Autorun и установить путь к .bat файлу.

Все, можно пользоваться алиасами. Мой список alias выглядит так:

Список включает в себя наиболее частоиспользуемые команды git, команды yii, symfony. Также некоторые команды для работы с mysql. Список обновляется по мере использования мною новых технологий, фреймворков и т.д.

Если нужно добавить сложную составную команду, рекомендую вынести ее в отдельный .bat файл и сделать алиас на него.

Проверено на windows 10. Спасибо за внимание!

How to create an IP alias on Windows

I need to create an alias for my network interface such that it can be accessed locally with either 127.0.0.1 or 33.33.33.33.

In *nix I would do this:

It appears that the netsh tool may be able to do the same thing. If so, how? I’ve seen some examples that seem close, but I don’t understand the options provided.

The motivation for this is to run two instances of JBossAS on the same machine without port offsets. Thus, they would need to use the same port numbers without conflicting.

7 Answers 7

You’d be correct. Also, you can add multiple addresses without touching the command line using the advanced interface properties screen.

It may depend on which version of Windows you have, but here are some steps from my Windows 7 machine. You want to get to your «local adapter settings». There are probably 1000 ways to do this, but here is one.

  • Go to Control Panel -> Network and sharing center
  • Click «change adapter settings» on the left
  • Right click on your local network connection and go to properties
  • Select your TCP/IP v4 protocol and click properties
  • TCP must be set to static addressing, so set it to «Use the following address» and set up your default IP config for the network. Then click advanced.
  • Under IP Address in Advanced TCP/IP settings, click Add
  • Add extra IP addresses as needed
Читайте также:  Linux проверка tcp порта

Another approach is to add the Microsoft Loopback adapter as a network device. This lets you set up a virtual network adapter on your machine. This can be useful for network testing from your own machine. See http://social.technet.microsoft.com/Forums/en-US/w7itpronetworking/thread/259c7ef2-3770-4212-8fca-c58936979851/ for more info.

There is a comment about how to add alias while still using DHCP for the main one. I have similar problem.

The solution is:

  1. Add Microsoft Loopback Adapter as a network device (as suggested by one of the comment).
  2. Specify IP address for the new network interface.

(1) Add Microsoft Loopback Adapter as a network device (taken from here):

  1. Click the Start menu.
  2. Search for “cmd».
  3. Right-click on “cmd” and select “Run as Administrator”
  4. Enter “hdwwiz.exe”

From that point on it’s the same approach as under Vista, i.e.:

  1. In the «Welcome to the Add Hardware Wizard», click Next.
  2. Select «Install the hardware that I manually select from a list (Advanced)» and click Next.
  3. Scroll down and select «Network adapters» and click Next.
  4. Select under Manufacturer «Microsoft» and then under Network Adapter «Microsoft Loopback Adapter» and click Next.

(2) To see the newly added network interface, and specify an IP address:

  1. Go to Control Panel -> Network and Sharing Center
  2. Click on «Change adapter setttings» on the left side
  3. Find the entry with Device Name «Microsoft Loopback Adapter»
  4. Right click on it, and choose Property
  5. Choose «Internet Protocol Version 4 (TCP/IPv4) and hit Properties button.
  6. Select «Use the following IP address:», and enter IP address, Subnet mask, and Default gateway as needed.

go to C:\Windows\System32\drivers\etc\hosts on windows and add a new entry as below

eg: 106.200.247.101 abc.com

Then you will be able to refer to using given hostname

for anyone coming, as i have, from google:
another way to accomplish this is to set a route and set the destination to understand the ip, an example: recently at our company our service was stopped for our T1, some old software that no one had the code for hard coded the external address of our server and we needed to make it go to an internal address of 192.168.2.100 so i set this route on the client machines: route -p add 208.44.37.176 MASK 255.255.255.248 192.168.2.100 METRIC 1 and on the server i set it’s interface to listen on 208.44.37.182

so when the client tries to connect to 208.44.37.182 it would check the routing table, it would do a bitwise AND on the netmask for anything in the routing table to match to the routing address (the 208.44.176) and then route it to the gateway (192.168.2.100) failing this is routes to the default gateway.

so in this case it routes it through to 192.168.2.100 who sees it’s addressed to him and replies in turn. if he wasn’t listening on 208.44.37.182 then he would ignore it (or, if he is configured to do so, pass it along til someone takes it or drops it)

(for those curious about why that netmask:
182 is 10110110
248 is 11111000
176 is 10110000
for a bitwise AND if one of the two bits is 0, the result is 0, if they are both 1 it’s 1. so you see taking 182 and bitwise ANDing it to 248 gives 176)

those are the things i learned when working on this, hope it helps someone else.

Оцените статью