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" abc@gmail.com

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


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" abc@example.com; 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" abc@example.com
|improve this answer|||||
  • @ Dubu Thanks alot. But I need to send all attachments in a single mail. Is it possible? – Aravind Jul 9 '14 at 13:52
  • @user2910201 Yes, of course. I added this variant above. – Dubu Jul 9 '14 at 14:09

Try this oneliner

find /home/cde -ctime -1 -name "Sum*pdf*"  | uuencode files.txt | mailx -s "subject" abc@gmail.com
|improve this answer|||||
  • @ 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 '14 at 7:19
  • Could you clarify your question? Do you need pdf attachments AND list of files? – dchirikov Jul 9 '14 at 8:36
  • @ dchirikov Yes I need pdf attachments alone no need of file list in mail. – Aravind Jul 9 '14 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.