繁体   English   中英

如何从光盘中删除未使用的组织模式附件文件

[英]How to delete unused org-mode attachment files from disc

在组织模式中,删除了许多具有附件文件的标题后,不同的文件现在保留在我的数据子目录中的光盘上。

是否有一个函数或脚本可以找到所有不相关的文件并进行清理?

在搞乱org-capture-templates然后删除一堆没有按照我想要的方式出现的条目之后,我今天遇到了同样的问题。

我写下了这个脚本,它完成了工作(对我而言)。

#!/bin/sh

## Location where org-mode stores attachments
datadir="$HOME/Dropbox/Documents/Org/data";
orgdir="$HOME/Dropbox/Documents/Org/"

echo "The following files appear orphaned:";

files=$(find "$datadir" -type f|perl -ne 'print "$1\n" if /([^\/]*)\/[^\/]*$/'|uniq|while read id; do grep -qiR --include "*.org" "$id" "$orgdir" || find "$datadir" -ipath "*$id*" -type f; done)

echo "$files"

if [ "" == "$files" ]; then
   echo "Nothing to do!"
   exit
fi

echo "Delete? y/[n]"
read delete
case $delete in
    y)
        echo "$files" |
        while read fn; do
        rm "$fn";
        done
    echo "Done."
        ;;
    *)
        echo "Not deleting anything!"
        ;;
esac

暂无
暂无

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

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