在LINUX中,cd -
移动到上一个工作目录并输出其新的pwd
。我只想转到上一个工作目录。我不希望输出位置。怎么做?
发布于 2018-08-21 10:47:56
来自bash手册:
If DIRECTORY is '-', it is converted to '$OLDPWD' before the directory change is attempted. If a non-empty directory name from 'CDPATH' is used, or if '-' is the first argument, and the directory change is successful, the absolute pathname of the new working directory is written to the standard output.
这意味着可以使用$OLDPWD
,而不是-
。但只有它被设置:
cd "${OLDPWD:--}"
为方便起见,可以创建一个helper函数:
cdback() { cd "${OLDPWD:--}" ; }
或者你可以使用pushdir
和popdir
,像这样:
pushdir /path/to/dir
# do something
popdir # return to previous working directory
发布于 2018-08-21 11:51:50
可以将输出输送到dev/null
:
cd - > /dev/null
https://stackoverflow.com/questions/-100002317
复制相似问题