获取所有打开的终端的当前工作目录 – macOS

由于兴趣使然,我平时经常打开许多终端。然而,为了在活动中做演讲或出于一些小原因,我需要将自己的终端用于视频传输和录音,为了尽量减轻负担,有时候我会关闭所有终端。

所以,在关闭之前做了什么来着…因为有一些东西,我决定先备份一下。

使用 lsof 命令输出带有 cwd(当前工作目录)的信息,然后通过常见的过滤器一行命令进行执行。

$ for x in $(pidof bash); do lsof -a -d cwd -p $x ; done |  grep bash | awk '{print $9}' | sort | uniq
/Users/sawanoboly
/Users/sawanoboly/develop/src/git.example.com/kafka-docker
/Users/sawanoboly/develop/src/git.example.com/zookeeper-docker/stack
/Users/sawanoboly/develop/src/git.example.com/sawanoboly/kafka-miscs
/Users/sawanoboly/develop/src/git.example.com/sawanoboly/kafka-miscs/landloop
/Users/sawanoboly/develop/src/github.com/confluentinc/cp-docker-images
/Users/sawanoboly/develop/src/github.com/getshifter/base
/Users/sawanoboly/sandbox/kafka-leaning/fluentd
/Users/sawanoboly/sandbox/spot/opencv
/Users/sawanoboly/sandbox/spot/opencv/face_recognition/examples
/Users/sawanoboly/sandbox/spinnaker

以便协助恢复大脑内部的上下文。

bannerAds