Linux 在一个命令中更改目录并执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13624097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 17:55:08  来源:igfitidea点击:

Change directory and execute file in one command

linuxbashfedoralaunchergnome-3

提问by Bryan Wolfford

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.

当我想执行一个文件时,似乎在执行它之前我总是必须先 'cd' 进入该文件的目录,除非它因 can't-find-my-dataz 类型错误而失败。

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?

我怎样才能把它变成一行,以便在 Gnome3 中创建自定义启动器时将它作为我的 Exec= _行?

采纳答案by Raber

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

cd /usr/local/bin/minecraft/ && java -Xms512M -Xmx2048M -jar minecraft.jar应该做