Create executable file for comand line Linux

2019-09-17 07:32发布

When ever I log into Linux I usually go straight to the same folder i was wondering if in stead of typing in:

$cd Document/..../..../..../..../....

I could create an executable so I could just type ./csFolder and it would go straight there.

3条回答
Bombasti
2楼-- · 2019-09-17 08:14

In addition to the other options (though if you use the function/alias option you want to use an absolute path to the target directory so it works from wherever you happen to be) you can use the environment variable CDPATH to help with this if you have a location you often go to from various other locations.

From the POSIX specification:

CDPATH

A -separated list of pathnames that refer to directories. The cd utility shall use this list in its attempt to change the directory, as described in the DESCRIPTION. An empty string in place of a directory pathname represents the current directory. If CDPATH is not set, it shall be treated as if it were an empty string.

Which means that if you set CDPATH to the parent of your target directory you can just use cd dirname from anywhere and go directly to the directory you wanted to be in.

查看更多
狗以群分
3楼-- · 2019-09-17 08:17

Yo can do a symlink

ln -s /path/to/file /path/to/symlink

查看更多
女痞
4楼-- · 2019-09-17 08:33

You can add a shell function in your .bashrc and restart your terminal:

csf() {
  cd Document/..../..../..../..../....
}

Whenever you want to go to that directory, you just run csf.

查看更多
登录 后发表回答