繁体   English   中英

zsh / bash-如何将所有打开的终端选项卡的目录写入文件?

[英]zsh / bash - How to write directories of all open terminal tabs to file?

我想将每个终端选项卡的工作目录写入一个文件。 我想我已经接近了以下内容,但问题是同一(当前)目录路径多次写入文件。

for x in $(ps | grep zsh)
do
  echo "$(pwd)" >> "tabs open $(date +%Y_%m_%d_%H_%M_%S).txt"
done

在此先感谢您提出我的新问题。

这不是您所需要的100%解决方案,但据我所知,它是最接近的。

# For each PID of the "-bash" processes...
for x in $(ps -ef | grep -v grep | grep -- "-bash" | awk '{print $2}'); do 
    # check if the file is readable (only user has access)
    if [[ -r /proc/$x/cwd ]]; then
        # print details including the working directory
        ls -ld /proc/$x/cwd
        # ... or just PID and it's working directory
        echo $x : $(ls -ld /proc/$x/cwd | awk '{print $11}')
    fi
done > "tabs_open_$(date +%Y_%m_%d_%H_%M_%S).txt"

“ -bash”是实际上位于终端中时的进程名称。 该脚本将不考虑用户在终端窗口内手动启动的“ bash”过程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM