如何找出将在`cd -`中使用的路径? [英] How to find out the path that will be used in `cd -`?

查看:58
本文介绍了如何找出将在`cd -`中使用的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以使用 cd-在2条路径之间切换:

I know that it is possible to use cd - to switch between 2 paths:

user@server:~$ cd a
user@server:~/a$ cd ~/b
user@server:~/b$ cd -
/home/user/a
user@server:~/a$ cd -
/home/user/b
user@server:~/b$

我想使用此功能对上一条路径进行操作.也许有一些变量指向先前的路径,所以我可以像以下那样进行稀化:

I want to use this feature to do something with the previous path. Maybe there is some variable that points to the previous path so I can do thins like:

user@server:~/a$ cd ~/b
user@server:~/a$ ls -d $PREVIOUS_PATH
/home/user/a
user@server:~/a$ cp file $PREVIOUS_PATH # will copy file to /home/user/a
user@server:~/b$ cd -

推荐答案

旧工作目录存储在 OLDPWD 环境变量中.每次我们更改目录时,此变量都会更新.这也意味着我们在启动终端时未设置它.

Old working directory is stored in OLDPWD environment variable. This variable is updated every time we change directory. This also means that it is not set when we launch terminal.

user@server:~/a$ cd ~/b
user@server:~/a$ ls -d "$OLDPWD"
/home/user/a
user@server:~/a$ cp file "$OLDPWD" # will copy file to /home/user/a, ""
user@server:~/b$ cd -

这篇关于如何找出将在`cd -`中使用的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆