因此,在 Linux Mint 上大量使用locate命令之后,我遇到了每个查询都在/timeshift/目录中返回一行又一行结果的问题 - Linux Mint将其用作操作系统保存点。
如果我使用,locate anaconda activate.sh
我可能会得到:
/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts
/conda-activate.sh
/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/home/user/.anaconda3/pkgs/spyder-5.1.5-py39h06a4308_1/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/deactivate.d/deactivate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/pkgs/spyder-5.1.5-py39h06a4308_1/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-10_04-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-10_04-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/deactivate.d/deactivate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/pkgs/spyder-5.1.5-py39h06a4308_1/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-15_21-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-15_21-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
只有前三个结果是相关的,那么如何排除目录?
答案1
使用 grep 手动排除目录
您可以使用 -v 选项让 grep 输出所有元素不匹配提供的正则表达式,如下所示:
locate anaconda activate.sh | grep -v "/timeshift/"
这将仅打印不包含字符串的路径/timeshift/
永久排除目录
由于时间移位目录的问题经常重复出现,您可能希望将其从所有定位查询中永久排除。
根据updatedb
文档,您可以在 中/timeshift
添加。运行后,所有查询现在都应排除该目录。PRUNEPATHS=
/etc/updatedb.conf
updatedb
plocate
/timeshift