Howto: Send The Content Of a Text File Using mail Command In Unix / Linux

I‘d like to send an email with the content of a text file using mail command in Unix / Linux operating system. How do I do it?

mail command (also mailx command) is an intelligent mail processing system under Unix and Linux. You need to use the following syntax to send an email using mail command:

mail -s 'Subject-Here' < input.file
mail -s 'Uptime Report' < /tmp/output.txt


  • -s ‘Subject’ : Specify subject on command line.
  • To email user.
  • /tmp/output.txt : Send the content of /tmp/output.txt file using mail command.

Send an email as attachment from Unix command line

Either can use the mutt command or uuencode command as described below:

### Attach /tmp/filelist.tar.gz and read the content of a text using /tmp/body.txt ###
mutt -s "Backup status" -a /tmp/filelist.tar.gz < /tmp/body.txt


### Attach /tmp/list.tar.gz and and send it  ###
uuencode /tmp/list.tar.gz /tmp/list.tar.gz | mailx -s "Reports"
### Email photo.png along with a text message read from body.txt ##
(cat body.txt; uuencode photo.png photo.png) | mail -s "Subject"

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts