问题描述
我正在Windows机器上进行开发.对于Linux命令行,我唯一需要的地方是Git Bash.问题是:当我打开它时,我在主目录中.我必须将目录更改为我的工作区,例如:
I am developing on a windows machine. The only place I need for linux command line is Git Bash. The problem is: When I open it, I am in the home directory. I have to change the directory to my workspace, like:
cd ../../../d/work_space_for_my_company/project/code_source
我可以将其包装在.sh文件中,这样就不必手动键入了吗?这应该很简单,但是我对Linux命令行的知识为零.我真的很感激,如果你能走我通过如何创建该.sh文件.
Can I wrap this in a .sh file so I don't have to hand-type it anymore? This should be simple but I have zero knowledge about Linux command line. I am really appreciated If you can walk methrough how to create that .sh file.
推荐答案
只需将该行写入文件"cd.sh",然后在您的shell提示符下执行即可:
Just write that line to a file "cd.sh", then do this from your shell prompt:
. ./cd.sh
或者您可以在$HOME/.bashrc
文件中创建别名或函数:
Or you can create an alias or function in your $HOME/.bashrc
file:
foo() { cd /d/work_space_for_my_company/project/code_source ; }
如果目录名称包含空格或其他shell元字符,则需要使用引号;即使没有必要添加它们也不会造成伤害:
If the directory name includes spaces or other shell metacharacters, you'll need quotation marks; it won't hurt to add them even if they're not necessary:
foo() { cd "/d/Work Space/project/code_source" ; }
(请注意,我省略了../../..
;您不需要它.)
(Note that I've omitted the ../../..
; you don't need it.)
如果添加一行
foo
在函数定义后
到.bashrc
,您的shell将在该目录中启动.或者,如果以后不再需要使用该功能,则可以直接在.bashrc
中使用cd
命令.
to your .bashrc
after the function definition, your shell will start in that directory. Or you can just use the cd
command directly in your .bashrc
if you aren't going to need to use the function later.
(名称foo
只是一个例子;您应该选择一个更有意义的名称.)
(The name foo
is just an example; you should pick a more meaningful name.)
这篇关于如何默认为其他目录而不是主目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!