The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 85     Votes:  2     ✅ Solution
Tags: command-line   bash   alias  
Link: 🔍 See Original Answer on Ask Ubuntu 🔗

Title: I am trying to create an alias to run an application. Is there away to bypass creating an alias just to change directories?
ID: /2016/11/15/I-am-trying-to-create-an-alias-to-run-an-application.-Is-there-away-to-bypass-creating-an-alias-just-to-change-directories_
Created: November 15, 2016    Edited:  November 15, 2016
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

When you type echo $PATH you should see /usr/local/bin is already in your path and there is no need to change to that directory in the first place. You can run the executable simply by typing packettracer - there is no need to cd to it.

Even if it is not in your PATH, you don’t need to change to a program’s / script’s directory as a separate command; you can run it by prefixing the executable’s name with the full path, in this case:


Therefore your alias can simply be:

alias pt='/usr/local/bin/packettracer'

or even

alias pt='packettracer'

Before setting an alias, check that the command you want to use doesn’t already exist using the type command. Hopefully you will see that it is not in use:

$ type pt
bash: type: pt: not found

Once you have a suitable alias, to make is permanent you can add it to the end of your ~/.bashrc file (use your favourite text editor; for example, open a terminal and type nano .bashrc add the alias, save and exit, and the alias will be available as soon as you open a new shell).

⇧ Why does my laptop suspend after 5 minutes? How do I find all system files I've edited with `gedit`?  ⇩