3

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?

user.dz
  • 48,105

3 Answers3

5

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.

sourav c.
  • 44,715
1

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
}
nux
  • 38,017
  • 35
  • 118
  • 131
0

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

Scott
  • 31
  • 3
  • 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 '14 at 01:36