Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Aug 20 '10 at 9:37

This question came from our site for professional and enthusiast programmers.

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

2 Answers 2

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.

share|improve this answer
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. –  Gilles Aug 20 '10 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. –  Yaba Aug 20 '10 at 17:22

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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.