-1

以下 find 命令将生成多个文件并发送所有这些文件

find /home/cde -ctime -1 -name "Sum*pdf*" -exec uuencode {} {} \; |mailx -s "subject" abc@gmail.com

但我收到了“homecdeSum123.pdf”和“homecdeSum324.pdf”之类的附件。如何在我的附件中获取准确的文件名。请帮助我

4

2 回答 2

0

试图回答似乎至少是您问题的一部分

但我收到了“homecdeSum123.pdf”和“homecdeSum324.pdf”之类的附件。如何在我的附件中获取准确的文件名。

这个问题的公认答案是: find:basename 和 dirname 怎么了? 在我看来包含很多有用的信息,但我试图提取可能是上述问题的答案:

你描述的是当你在做

find /home/cde ....

你得到像“homecdeSum123.pdf”这样的文件名,所以我的看法是你只想要文件的基本名称,而不是目录。

这可以像这样访问(仅作为示例列表)

find `pwd` -name "*.png" -exec echo $(basename {} ) \;

一个轻微的变化是使用它-execdir而不是-exec(取自手册页):

-execdir 命令 {} +

         Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find.

这有帮助吗?

于 2014-07-09T11:00:35.470 回答
0

单个邮件中的所有附件:

 find /home/cde -ctime -1 -name "Sum*pdf*" | while read name; do uuencode "$name" "${name##*/}"; done | mailx -s "subject" abc@example.com

获取单独的邮件:

find /home/cde -ctime -1 -name "Sum*pdf*" | while read name; do uuencode "$name" "${name##*/}"| mailx -s "subject" abc@example.com ; done
于 2014-07-09T14:17:01.697 回答