3

How can i add shortcuts like 'rst' for restarting the tomcat in the terminal?

3
  • Voting to migrate on superuser.com
    – Pekka
    Aug 20, 2010 at 9:34
  • Voting to migrate to unix.stackexchange.com
    – AndrewJackson
    Aug 20, 2010 at 9:36
  • @AndrewJackson: Of course you did, at 1 rep.
    – Hello71
    Aug 20, 2010 at 17:24

2 Answers 2

9

Depends on your desktop environment or how you want to access it.

Do you want a nice icon on your desktop?

Create an application icon (which is the closest equivalent to a MS Windows Shortcut): KDE: Perform a right click in a Folder View and select 'Create new -> Link to Application...'

Do you want it to be available from the bash only?

Create an alias in your ~/.bashrc or ~/.profile:

alias rst='service tomcat restart'     # Ubuntu with upstart
alias rst='/etc/init.d/tomcat restart' # Other distributions w/o upstart

However note that it will not be available from shell scripts in this case.

Do you want to make it available just like an executable file to bash and shell scripts?

Create a symbolic link in a folder in the PATH. I recommend to create a ~/bin folder, where you can add your personal scripts and links and add this folder to your path in the .bashrc:

export PATH="$PATH:$HOME/bin"

Note that some applications might fail to start as the working directory is not set properly. In this case create a shell script in your ~/bin folder that changes to the respective folder first:

#!/bin/sh
cd /opt/myAppHomeDirectory
./myapp "$@"

Oh, and don't forget to make this script executable of course using chmod.

2
  • 1
    @Yaba: nice breakdown. Suggested improvements: export PATH="$PATH:$HOME/bin" so that it doesn't break if there is a space in $PATH; in the script, change ./myapp to ./myapp "$@" so that you can still pass command line arguments to the script. Aug 20, 2010 at 15:27
  • You are right. I've edited my post. Just one comment: Spaces in directory names on Unix systems are evil. Sooner or later you will find a script that gets into trouble with it.
    – Banzai
    Aug 20, 2010 at 17:22
5

Multiple possibilities:

  1. create shell scripts of that name and put them somewhere on the PATH (or modify the PATH) to reference the directory containing those scripts
  2. create aliases in your shells .rc file (.bashrc for bash)

You must log in to answer this question.