The following find command will results multiple files and send mail all those

find /home/cde -ctime -1 -name "Sum*pdf*" -exec uuencode {} {} \; |mailx -s "subject" [email protected]

But I am getting attachments like homecdeSum123.pdf and homecdeSum324.pdf. How to get exact file names in my attachment.

2 Answers 2


If I understand you right, you want to have the attachments have filename like Sum123.pdf instead of homecdeSum123.pdf. I assume the latter name is produced by your mail program that removes the slashes in the path name when saving.

I think you should use a different way to call uuencode, removing the path name on the second parameter:

find /home/cde -ctime -1 -name "Sum*pdf*" | while read name; do uuencode "$name" "${name##*/}" | mailx -s "subject" [email protected]; done

This will send a separate mail for every file. The ${name##*/} part will take the variable $name, remove everything up to and including the last slash and return the result.

If you want to send all files in one mail, just put the mailx part of the pipe to the end:

find /home/cde -ctime -1 -name "Sum*pdf*" | while read name; do uuencode "$name" "${name##*/}"; done | mailx -s "subject" [email protected]
  • @ Dubu Thanks alot. But I need to send all attachments in a single mail. Is it possible?
    – Aravind
    Jul 9, 2014 at 13:52
  • @user2910201 Yes, of course. I added this variant above.
    – Dubu
    Jul 9, 2014 at 14:09

Try this oneliner

find /home/cde -ctime -1 -name "Sum*pdf*"  | uuencode files.txt | mailx -s "subject" [email protected]
  • @ dchirikov Thank you, but it didn't work. I am getting files.txt as attachment and the names of files in the directory. I am not getting the actual attachments.
    – Aravind
    Jul 9, 2014 at 7:19
  • Could you clarify your question? Do you need pdf attachments AND list of files?
    – dchirikov
    Jul 9, 2014 at 8:36
  • @ dchirikov Yes I need pdf attachments alone no need of file list in mail.
    – Aravind
    Jul 9, 2014 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .