How to Make an "Alias" for a Long Path

How to make an alias for a long path?

Since it's an environment variable (alias has a different definition in bash), you need to evaluate it with something like:

cd "${myFold}"

or:

cp "${myFold}/someFile" /somewhere/else

But I actually find it easier, if you just want the ease of switching into that directory, to create a real alias (in one of the bash startup files like .bashrc), so I can save keystrokes:

alias myfold='cd ~/Files/Scripts/Main'

Then you can just use (without the cd):

myfold

To get rid of the definition, you use unalias. The following transcript shows all of these in action:

pax> cd ; pwd ; ls -ald footy
/home/pax
drwxr-xr-x 2 pax pax 4096 Jul 28 11:00 footy

pax> footydir=/home/pax/footy ; cd "$footydir" ; pwd
/home/pax/footy

pax> cd ; pwd
/home/pax

pax> alias footy='cd /home/pax/footy' ; footy ; pwd
/home/pax/footy

pax> unalias footy ; footy
bash: footy: command not found

How to make an “alias” for a long path in angular-cli?

try this in tsconfig.json:

  {  "compileOnSave": false,  "compilerOptions": {    "outDir": "./dist/out-tsc",    "sourceMap": true,    "declaration": false,    "moduleResolution": "node",    "emitDecoratorMetadata": true,    "experimentalDecorators": true,    "target": "es5",    "typeRoots": [      "node_modules/@types"    ],    "lib": [      "es2017",      "dom"    ],    "paths": {      "@services/*": ["app/services/*"] // here!    }  }}

How can I create an alias to a directory so that I don't have to type the long path every time?

If you're using OSX you can open the hidden file named .bash_profile in your root user directory and add an entry like this:

alias define_your_shortcut='define your path'

You can do this for anything. For example here is an alias for your example:

alias FolderBelongingToUser='cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser'

Here's another example using a command to toggle hidden files

alias showfiles='defaults write com.apple.finder ShowAllFiles TRUE'
alias hidefiles='defaults write com.apple.finder ShowAllFiles FALSE'

After you make any changes to your bash_profile you'll need to either logout and login or you can open terminal and tell it to reload your bash_profile with this command

source ~/.bash_profile

I'm not personally familiar with Windows but if your using Windows a quick search result explained that this is how you would create a command prompt alias in Windows

AddConsoleAlias( TEXT("test"), 
TEXT("cd \\<a_very_long_path>\\test"),
TEXT("cmd.exe"));

Alternatively it looks like someone provided a good answer to doing this in Windows here: https://superuser.com/questions/560519/how-to-set-an-alias-in-windows-command-line

Aliases in Windows command prompt

To add to josh's answer,

you may make the alias(es) persistent with the following steps,

  1. Create a .bat or .cmd file with your DOSKEY commands.

  2. Run regedit and go to HKEY_CURRENT_USER\Software\Microsoft\Command Processor

  3. Add String Value entry with the name AutoRun and the full path of your .bat/.cmd file.

    For example, %USERPROFILE%\alias.cmd, replacing the initial segment of the path with %USERPROFILE% is useful for syncing among multiple machines.

This way, every time cmd is run, the aliases are loaded.

For Windows 10, add the entry to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor instead.

For completeness, here is a template to illustrate the kind of aliases one may find useful.

@echo off

:: Temporary system path at cmd startup

set PATH=%PATH%;"C:\Program Files\Sublime Text 2\"

:: Add to path by command

DOSKEY add_python26=set PATH=%PATH%;"C:\Python26\"
DOSKEY add_python33=set PATH=%PATH%;"C:\Python33\"

:: Commands

DOSKEY ls=dir /B $*
DOSKEY sublime=sublime_text $*
::sublime_text.exe is name of the executable. By adding a temporary entry to system path, we don't have to write the whole directory anymore.
DOSKEY gsp="C:\Program Files (x86)\Sketchpad5\GSP505en.exe"
DOSKEY alias=notepad %USERPROFILE%\Dropbox\alias.cmd

:: Common directories

DOSKEY dropbox=cd "%USERPROFILE%\Dropbox\$*"
DOSKEY research=cd %USERPROFILE%\Dropbox\Research\


  • Note that the $* syntax works after a directory string as well as an executable which takes in arguments. So in the above example, the user-defined command dropbox research points to the same directory as research.
  • As Rivenfall pointed out, it is a good idea to include a command that allows for convenient editing of the alias.cmd file. See alias above. If you are in a cmd session, enter cmd to restart cmd and reload the alias.cmd file.

When I searched the internet for an answer to the question, somehow the discussions were either focused on persistence only or on some usage of DOSKEY only. I hope someone will benefit from these two aspects being together here!


Here's a .reg file to help you install the alias.cmd. It's set now as an example to a dropbox folder as suggested above.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="%USERPROFILE%\\alias.cmd"

For single-user applications, the above will do. Nevertheless, there are situations where it is necessary to check whether alias.cmd exists first in the registry key. See example below.

In a C:\Users\Public\init.cmd file hosting potentially cross-user configurations:

@ECHO OFF
REM Add other configurations as needed
IF EXIST "%USERPROFILE%\alias.cmd" ( CALL "%USERPROFILE%\alias.cmd" )

The registry key should be updated correspondly to C:\Users\Public\init.cmd or, using the .reg file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="C:\\Users\\Public\\init.cmd"

create alias for path

You could just create a variable in your powershell profile with that path as the value.

Then all you would need to do is something like

cd $dotNet4path

To add something to your profile profile, type $profile, into a powershell window and it will display the path to your powershell profile file. Create it if it does not exist.

Then put this line in the file, save and restart powershell.

$dotNet4path = "C:\windows\microsoft.net\framework\v4.0.30319"

Long name aliases for file and directory paths in emacs

See Bookmarks.



Related Topics



Leave a reply



Submit