Terminal command to make shortcut:
alias yourCommand="YourTerminalCommand"
And i accidentally made new command with "yourCommand" so I want to delete it but how?
Use
_unalias [name of alias]_
Don't use
unalias -a
It will delete all your alias.
Related
I have a bash script that I would like to run globally as a command. For that I moved the script to /usr/local/bin/somefile.sh.
Now I still have to call a command called somefile.sh. I would like to have an alias for this command (for example I would just like to call the script with the command sf).
How do I do that?
And to complement answer from #Kent :
alias sf='/usr/local/bin/somefile.sh' using alias
ln -s somefile.sh /usr/local/bin/sf using soft link
mv /usr/local/bin/somefile.sh /usr/local/bin/sf using renaming
There are different ways:
as you mentioned, use alias, man alias for details
create a soft link named sf to your real script
rename your script
Open your .bashrc file located in ~/.bashrc. .bashrc file is read whenever you login to the system. Add the below line to the end of the file.
alias sf='/usr/local/bin/somefile.sh'
then re login or run source .bashrc
If you're on a GNU system, you could use the "alternatives" system:
dir=/usr/local/bin
sudo update-alternatives --install $dir/sf somefile $dir/somefile.sh 10
This creates 2 symbolic links:
/usr/local/bin/sf -> /etc/alternatives/somefile
/etc/alternatives/somefile -> /usr/local/bin/somefile.sh
I intend to set up mac terminal shortcut per instructions but it does not work. This is what I did:
open terminal
nano .bash-profile
#add a few aliases
alias dtt = 'do this thing'
alias gc='git commit -m'
#save the bash profile
source ~/.bash_profile
Afterwards the new alias are present in the bash file. However no autocomplete is present in terminal, if I type dtt, it won't change to 'do this thing'. The shortcut doesn't seem to work.
Anything amiss? Thanks
Alias is used to do something (in your ex. 'do this thing'), typing the command you chose ('dtt'). The terminal won't autocomplete anything.
In fact alias instructs the shell to replace one string with another when executing commands.
You could use it to abbreviate commands. e.g. alias pg="ping". If you type pg google.com it will exec "ping google.com"
Currently, to get to the directory I need to type this:
cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser
Is there a way to make it so that I can just type something like:
cd FolderBelongingToUser ?
I'm familiar with z (uses ranking) and cdargs (uses shortcuts) but there are many other tools designed to make navigation in your shell easier and built-in solutions like CDPATH or the ** wildcard…
CDPATH
Adding something like this in your *rc file:
export CDPATH='.:~:/cygdrive/c/Users/NameOfUser/'
allows you to do exactly what you are after:
$ cd FolderBelongingToUser
or, better:
$ cd Fold<Tab>
**
If your bash is recent enough, you can do something like this:
$ cd **/foo
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
Vim normally supports tab completion, so you can probably type something like
cd ~NamTabFolTab
which will expand to
cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser
Of course, if NameOfUser is you, then you can probably just type
cd ~/FolTab
You can add the following line to your .vimrc
cabbr FolderBelongingToUser /cygdrive/c/Users/NameOfUser/FolderBelongingToUser
Then you can can
cd FolderBelongingToUser
If you want to add more to the path (eg to specify a filename with :w) you can press / after FolderBelongingToUser and it will replace it with the full path and allow you to continue typing.
:ca[bbrev] is a Command line only abbreviation. See: :help :cabbr
If this is a permanent alias, then in your ~/.bashrc, create an alias:
alias FTBU='/cygdrive/c/Users/NameOfUser/FolderBelongingToUser'
You will then be able to access it in your shell by:
$ cd FTBU
As another trick, if you are only going to use the alias to change to the directory then simply add cd to the alias
alias FTBU='cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser'
You then need only type:
$ FTBU
to change to the /cygdrive/c/Users/NameOfUser/FolderBelongingToUser directory. However, if you plan to use the alias for any other purpose, leave the cd out of the alias definition.
If this is a temporary alias, you can simply create an alias from the command line with:
$ alias FTBU='/cygdrive/c/Users/NameOfUser/FolderBelongingToUser'
with the same results. (substitute anything you like for FTBU) Note: you remove an alias with the unalias command. Also Note: you should to check whether an existing system command exists with the name of your alias before assigning it. Simply type the proposed alias at the command line. If you receive something line bash: your_alias: Command Not Found, then you are good to go. There is no minimum number of characters required in an alias. So it you want to use a single-character, that's fine.
Ok, so maybe I'm a little lazy. But is there a way to assign an alias to an application so that if I run a command in the terminal, I could use the alias instead of having to type the actual application's name...
example:
killall TextWrangler
would become...
killall tw
I don't think there is a way to alias textwrangler into tw for use with killall, but you can alias the full killall command this way :
alias killalltw="killall TextWrangler"
Something even shorter : alias killtw="killall TextWrangler"
You can't have any spaces in the alias' name.
For this to be persistent between Terminal sessions you will need to put this line into ~/bash_profile file.
I added an alias in my .bash_profile file in my home directory on Mac Leopard. For example,
alias preview = "open -a preview"
alias lsall = "ls -l"
When I try to run these commands from the command line, I get the message that command not found
Any idea what I might be doing wrong? Thanks!
You just need to lose the spaces around =, i.e.
alias preview="open -a preview"
alias lsall="ls -l"
You also need to name the file .bash_profile if you want it to be executed automatically when you start a new shell.