Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

I want a custom command named something like "ServerStart" or something which is a combination of two commands, one after the other.

  • The first command would be cd .Server
  • The second being java -Xmx7168M -Xms7168M -jar server.jar

How do I do this so this becomes one Terminal command?

share|improve this question

marked as duplicate by Radu Rădeanu Jul 15 at 8:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers 3

up vote 4 down vote accepted

Usually alias is used to make a short custom command for one or more long commands. See How to create a permanent "alias"?

You can combine two command as,

command1 && command2

Then command2 will be issued if command1 is successfully executed. So make an alias like,

alias ServerStart='cd /path/to/.Server && java -Xmx7168M -Xms7168M -jar server.jar'

Source ~/.bashrc as . ~/.bashrc. After that the command ServerStart will issue both the commands together for you.

share|improve this answer

Instead of having the first command be cd .Server you can have the command be java -Xmx7168M -Xms7168M -jar /full path here/server.jar

Put it in a text file and save it at /usr/bin/ServerStart. chmod +x /usr/bin/ServerStart

share|improve this answer
    
Instead of /usr/bin/, you can create a folder named bin (or whatever) in your home folder, then add it your PATH by appending the line export PATH="$HOME/bin:$PATH" to your .bashrc file. –  edwin Jul 15 at 1:36

You could use alias command .

For more help visit this site Site .

Open terminal :

alias ServerStart=' cd /path/to/.Server ; java -Xmx7168M -Xms7168M -jar server.jar '

So now when you type ServerStart in terminal it will execute the two commands .

To save , so you can use it all the time add the following in you ~/.bashrc file .

ServerStar() {
   cd .Server
    java -Xmx7168M -Xms7168M -jar server.jar
}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.