Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change directory and execute file in one command

When I want to execute a file, it seems that I always have to first 'cd' into that file's directory before executing it, unless it fails on a can't-find-my-dataz type error.

How can I get around typing two commands to just execute a program?

Example:

cd /usr/local/bin/minecraft/ java -Xms512M -Xmx2048M -jar minecraft.jar 

How can I make that into one line, so as I can put it as my Exec=_ line when creating a custom launcher in Gnome3?

like image 457
Bryan Wolfford Avatar asked Nov 29 '12 10:11

Bryan Wolfford


People also ask

How do I change directories and run a program in command prompt?

Open the Command prompt, type in cd followed by the directory you want to move into, and hit Enter. Change the Windows directory by entering the drive name followed by : in the Command prompt, and hit Enter. In the Command prompt, type cd and drag the folder you want to move into from the GUI.

How do I change directory on one line?

Change Current Working Directory ( cd ) To change directories, use the command cd followed by the name of the directory (e.g. cd downloads ). Then, you can print your current working directory again to check the new path.

How do I move a file from one directory to another in CMD?

To move a file or directory from one location to another, use the command mv. Common useful options for mv include: -i (interactive) — Prompts you if the file you have selected overwrites an existing file in the destination directory. -f (force) — Overrides the interactive mode and moves without prompting.

How do I change the directory of a file?

Change Directories Using the Drag-and-Drop Method If the folder you want to open in Command Prompt is on your desktop or already open in File Explorer, you can quickly change to that directory. Type cd followed by a space, drag and drop the folder into the window, and then press Enter.


1 Answers

cd /usr/local/bin/minecraft/ && java -Xms512M -Xmx2048M -jar minecraft.jar should do it

like image 97
Raber Avatar answered Sep 30 '22 07:09

Raber