{"id":594,"date":"2018-05-16T02:58:39","date_gmt":"2018-05-16T02:58:39","guid":{"rendered":"http:\/\/hyderabadwebhosting.in\/blog\/?p=594"},"modified":"2018-05-26T13:45:31","modified_gmt":"2018-05-26T13:45:31","slug":"how-to-save-command-output-to-a-file-in-linux","status":"publish","type":"post","link":"https:\/\/hyderabadwebhosting.in\/blog\/how-to-save-command-output-to-a-file-in-linux\/","title":{"rendered":"How to Save Command Output to a File in Linux"},"content":{"rendered":"<p><span style=\"font-size: large;\">There are many things you can do with the output of a command in Linux. You can assign the output of a command to a variable, send it to another command\/program for processing through a pipe or redirect it to a file for further analysis.<\/span><\/p>\n<p><span style=\"font-size: large;\">In this short article, I will show you a simple but useful command-line trick: how to view output of a command on the screen and also write to a file in Linux.<\/span><\/p>\n<p><strong><span style=\"font-size: large;\">Viewing Output On Screen and also Writing to a File<\/span><\/strong><\/p>\n<p><span style=\"font-size: large;\">Assuming you want to get a full summary of available and used disk space of a file system on a Linux system, you can employ the df command; it also helps you determine the file system type on a partition.<\/span><\/p>\n<p>df<\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-597 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/8.png\" alt=\"\" width=\"644\" height=\"161\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/8.png 644w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/8-300x75.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">With the -h flag, you can show the file system disk space statistics in a \u201chuman readable\u201d format (displays statistics details in bytes, mega bytes and gigabyte).<\/span><\/p>\n<p>df -h<\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-598 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/9.png\" alt=\"\" width=\"641\" height=\"157\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/9.png 641w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/9-300x73.png 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">Now to display the above information on the screen and also write it to a file, say for later analysis and\/or send to a system administrator via email, run the command below.<\/span><\/p>\n<p>df -h | tee df.log<\/p>\n<p>cat df.log<\/p>\n<p><a href=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-599 size-full\" src=\"http:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/10.png\" alt=\"\" width=\"642\" height=\"260\" srcset=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/10.png 642w, https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/uploads\/2018\/05\/10-300x121.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/p>\n<p><span style=\"font-size: large;\">Here, the magic is done by the tee command, it reads from standard input and writes to standard output as well as files.<\/span><\/p>\n<div class=\"pdf24Plugin-cp\"> \t<form name=\"pdf24Form0\" method=\"post\" action=\"https:\/\/doc2pdf.pdf24.org\/wordpress.php\" target=\"pdf24PopWin\" onsubmit=\"var pdf24Win = window.open('about:blank', 'pdf24PopWin', 'resizable=yes,scrollbars=yes,width=600,height=250,left='+(screen.width\/2-300)+',top='+(screen.height\/3-125)+''); pdf24Win.focus(); if(typeof pdf24OnCreatePDF === 'function'){void(pdf24OnCreatePDF(this,pdf24Win));}\"> \t\t<input type=\"hidden\" name=\"blogCharset\" value=\"Cw1x07UAAA==\" \/><input type=\"hidden\" name=\"blogPosts\" value=\"MwQA\" \/><input type=\"hidden\" name=\"blogUrl\" value=\"yygpKSi20tfPqExJLUpMSkwpT03KyC8uycxL18vM00\/KyU8HAA==\" \/><input type=\"hidden\" name=\"blogName\" value=\"86hMSS1KTEpMUQhPTVLwyC8uycxLBwA=\" \/><input type=\"hidden\" name=\"blogValueEncoding\" value=\"gzdeflate base64\" \/><input type=\"hidden\" name=\"postId_0\" value=\"M7U0AQA=\" \/><input type=\"hidden\" name=\"postTitle_0\" value=\"88gvVyjJVwhOLEtVcM7PzU3MS1HwLy0pKC0BCScquGXmpCpk5in4ZOaVVgAA\" \/><input type=\"hidden\" name=\"postLink_0\" value=\"FchBEoAgCADAFxH3foNJwoyCk5j1+6Y9rkT0sSPKm\/miRHlxEh+hVjY1TNULii8Ih0E3w+GtkWXwGX3G3wSnVgY1qGrzwQ8=\" \/><input type=\"hidden\" name=\"postAuthor_0\" value=\"c\/QLDVAICHJ08XD0AwA=\" \/><input type=\"hidden\" name=\"postDateTime_0\" value=\"MzIwtNA1MNU1NFMwMLIyMLUytgQA\" \/><input type=\"hidden\" name=\"postContent_0\" value=\"rZbNjts2EMfvfYqBTglgW5aT\/fDGNtBL0QBFc2jRoMexNJKIUKRAUtYq6CEP0r5cnqQzlO14P5JssD4YFj9mhvPnb0iu2s3Kt2jAh0HTOimtCVOvPtINaHQVvUk2f9bkCJB\/DZoBQq1M5WGwHeRsV1joVai5m8B2oe0C2BIQctvw9AKUgd+U6W5n8PfeAr1XlfmqQbDc2KFTuNU0AU\/iJMRuY9nIHWamrbOVwwZK64C\/c2LHpmLHznZVzV5a1XIMB44K5SgPBz9QKk3RrOxcdIkG9eCVn61SUWOzStvNT6vva\/NW8lAefG1dYI2CymXRb1kTraW3j0IheNW0HHPL2Xaeyk4fsphqZQiCU\/mHG5D5vMCdov5Rbewom88dEQvJPag9b4BTgU4yO2r+IJvgrKm+m9VfHF+UfDcu4Z2BP+5FfM8Ro9YS8xeOeYx0CPFEAX\/2vmvEk8jUo4kbVFGQVDqRsOPM3RBl2KHSAkVcBqtYQKH8B+AIOY06xez94AM1ohWOMux7JkdmiffCDlHKojyI+0boiMnVpNsR8IICuSZuEM899R4GQUtCtLLrQVlzX+2iPIqAUDsq10kdQnuTpvVQkMMtFj1ta+tFyZky6VbbKu3bac4ykQlpx6vEwqeLeXadzi\/S61lrqmSzUk0FMsJm60TjxyHhheZ2bKMfTJ5ArrnMuKW51HJ2xoyzZ9VgRdOL5RXILkxF4QS8y8+zMlYvrJOE2S9CvU4uX79OWEtV1dybXWYxkqcwBvPPjAbsvp\/Ac11NX83nt1cX0SN\/9klURpTrgp3AiwZvpzGfGwnY3r6EbD7fceDYSiDl7cYn0\/7+cFJOayg1Vl+QjEfFfchO8PYBg+K0ci\/VjfD50791x9jy2YaFFMXnT\/\/JidZggBds12oc\/KkVo8zlE623QyA\/gYYqHL9jQVWqQmm9fMgxL\/fMKC\/PhvL1mVFePo5ydoLyxdXZUF7uUc6ej\/JyRPnV01DO7qCc\/TjKv49X1R61iC5u7U4unxFDPhG\/fV+dXsZ8z7MTuZE1hpP7WGxS7o2vgDh7XxpY8LHMaDsMPLxTyIc68z0B140xD1fmlrTtH0Ua\/oFAcgPMWNnDSM71c7fnTMRn87Mhvzwz8vulPWB+8YX5xeX8bMyP4Zi6xfOhz+aR+myRPQ37xR3sFz+O\/a\/8Fp5EwHgzVA6MaGH5fbAdS0CA2pM3EcDldPZQOtvIWWwKdPIilkeVsBnrwAvXx8H9qw899MTPH\/6X8rj7Lv0f\" \/> \t\t<a href=\"https:\/\/www.pdf24.org\" target=\"_blank\" title=\"www.pdf24.org\"><img src=\"https:\/\/hyderabadwebhosting.in\/blog\/wp-content\/plugins\/pdf24-post-to-pdf\/img\/sheep_32x32.png\" alt=\"www.pdf24.org\" border=\"0\" height=\"32\" \/><\/a> \t\t<span class=\"pdf24Plugin-cp-space\">&nbsp;&nbsp;<\/span> \t\t<span class=\"pdf24Plugin-cp-text\">Send article as PDF<\/span> \t\t<span class=\"pdf24Plugin-cp-space\">&nbsp;&nbsp;<\/span> \t\t<input class=\"pdf24Plugin-cp-input\" style=\"margin: 0px;\" type=\"text\" name=\"sendEmailTo\" placeholder=\"Enter email address\" \/> \t\t<input class=\"pdf24Plugin-cp-submit\" style=\"margin: 0px;\" type=\"submit\" value=\"Send\" \/> \t<\/form> <\/div>","protected":false},"excerpt":{"rendered":"<p>There are many things you can do with the output of a command in Linux. You can assign the output of a command to a variable, send it to another command\/program for processing through a pipe or redirect it to a file for further analysis. In this short article, I will show you a simple\u2026 <span class=\"read-more\"><a href=\"https:\/\/hyderabadwebhosting.in\/blog\/how-to-save-command-output-to-a-file-in-linux\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":596,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-594","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps"],"_links":{"self":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=594"}],"version-history":[{"count":2,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/594\/revisions"}],"predecessor-version":[{"id":600,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/594\/revisions\/600"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/media\/596"}],"wp:attachment":[{"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hyderabadwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}