{"id":22088,"date":"2023-10-01T16:25:35","date_gmt":"2023-10-01T16:25:35","guid":{"rendered":"https:\/\/linuxways.net\/?p=22088"},"modified":"2023-10-01T16:26:01","modified_gmt":"2023-10-01T16:26:01","slug":"how-to-create-a-blank-file-in-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-create-a-blank-file-in-linux-ubuntu\/","title":{"rendered":"How to Create a Blank File in Linux\/Ubuntu?"},"content":{"rendered":"<p><strong>Files<\/strong> are used extensively to perform daily tasks like writing code, taking notes, etc. Files can be manipulated, i.e., modified, created, and deleted by the processes of the Operating System (OS) as well as users. <strong>Blank Files <\/strong>are files that are empty, i.e., they contain no data and are of zero bytes. <strong>Linux\/Ubuntu\u2019s Terminal <\/strong>can be used to create blank files by <strong>different<\/strong> commands.<\/p>\n<p>This article will demonstrate different ways of creating a blank file in Linux\/Ubuntu 22.04 LTS, i.e., via<\/p>\n<ul>\n<li>Touch Command.<\/li>\n<li>Cat Command.<\/li>\n<li>Echo Command.<\/li>\n<li>Redirection Operator.<\/li>\n<li>Printf Command.<\/li>\n<\/ul>\n<h2><a id=\"post-22088-_vwi4ezl9toa3\"><\/a>How to Create\/Generate a Blank File in Linux\/Ubuntu via \u201ctouch\u201d Command?<\/h2>\n<p>The <strong>touch <\/strong>command creates blank files. A blank file is created via <strong>touch<\/strong> command by the following syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">touch<\/span> <span class=\"sy0\">&lt;<\/span>Filename<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Using the above syntax, a blank file \u201cFile1.txt\u201d is created by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">touch<\/span> File1.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"445\" class=\"wp-image-22111\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-1-300x65.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-1-1024x223.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-1-768x167.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-1-1536x334.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be verified that the new file: File1.txt has been created and it is of zero bytes. File size can also be verified by <strong>stat<\/strong> command as follows:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">stat<\/span> File1.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"526\" class=\"wp-image-22128\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-2-300x77.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-2-1024x263.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-2-768x197.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-2-1536x395.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the size of File1.txt is 0 bytes, i.e., File1.txt is a blank file.<\/p>\n<h2><a id=\"post-22088-_9cojz0t0yw1y\"><\/a>How to Create\/Generate a Blank File in Linux\/Ubuntu via the \u201ccat\u201d Command?<\/h2>\n<p>The <strong>cat (concatenate)<\/strong> command is typically utilized to view the contents of the file. Additionally, it can also be used to create a file. A blank file is created via the <strong>cat<\/strong> command by the following syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">cat<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>Filename<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Using the above syntax, a blank file \u201cFile2.txt\u201d is created by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">cat<\/span> <span class=\"sy0\">&gt;<\/span> File2.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"605\" class=\"wp-image-22144\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-3-300x89.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-3-1024x303.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-3-768x227.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-3-1536x454.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/> There will be a prompt to enter text, but as we are creating a blank file, a combination of [<strong>Ctrl+C<\/strong>] is pressed to save and exit the file. Additionally, from the above image, it can be verified that the new file: File2.txt has been created and it is of zero bytes. File size can also be verified by <strong>stat<\/strong> command as follows:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">stat<\/span> File2.txt<\/div><\/div>\n<h1><a id=\"post-22088-_pph9nkxvp7ni\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"511\" class=\"wp-image-22153\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-4.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-4-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-4-1024x256.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-4-768x192.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-4-1536x383.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/h1>\n<p>From the above image, it can be seen that the size of File2.txt is 0 bytes, i.e., File2.txt is a blank file.<\/p>\n<h2><a id=\"post-22088-_4bes0fcezddt\"><\/a>How to Create\/Generate a Blank File in Linux\/Ubuntu via \u201cecho\u201d Command?<\/h2>\n<p>The <strong>echo <\/strong>command is mainly used to append or overwrite text files. However, if the file doesn&#8217;t exist, the <strong>echo<\/strong> can be also used to create a file. A blank file is created via <strong>echo <\/strong>command by the following syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">echo<\/span> <span class=\"re5\">-n<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>Filename<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Where,<\/p>\n<ul>\n<li>-n: do not output the trailing newline.<\/li>\n<li>&gt;: Overwrite the existing file if &lt;filename&gt; exists.<\/li>\n<li>&gt;&gt;: Append the existing file if &lt;filename&gt; exists.<\/li>\n<\/ul>\n<p>Using the above syntax, a blank file \u201cFile3.txt\u201d is created by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">echo<\/span> <span class=\"re5\">-n<\/span> <span class=\"sy0\">&gt;<\/span> File3.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"705\" class=\"wp-image-22164\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-5.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-5-300x103.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-5-1024x353.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-5-768x264.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-5-1536x529.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be verified that the new file: File3.txt has been created and it is of zero bytes. File size can also be verified by <strong>stat<\/strong> command as follows:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">stat<\/span> File3.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"521\" class=\"wp-image-22169\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-6.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-6-300x76.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-6-1024x261.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-6-768x195.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-6-1536x391.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the size of File3.txt is 0 bytes, i.e., File3.txt is a blank file.<\/p>\n<h2><a id=\"post-22088-_nc1knt1ct9x5\"><\/a>How to Create\/Generate a Blank File in Linux\/Ubuntu via Redirection Operator?<\/h2>\n<p>A <strong>redirection <\/strong>operator is mainly used to append or overwrite text files but if a file does not exist, the <strong>redirection<\/strong> operator creates a new file. A blank file is created via the <strong>redirection <\/strong>operator by the following syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>Filename<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Where,<\/p>\n<ul>\n<li>&gt;: Overwrite the existing file if &lt;filename&gt; exists.<\/li>\n<li>&gt;&gt;: Append the existing file if &lt;filename&gt; exists.<\/li>\n<\/ul>\n<p>Using the above syntax, a blank file \u201cFile4.txt\u201d is created by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"sy0\">&gt;<\/span> File4.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"787\" class=\"wp-image-22176\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-7.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-7-300x115.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-7-1024x394.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-7-768x295.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-7-1536x590.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be verified that the new file: File4.txt has been created and it is of zero bytes. File size can also be verified by <strong>stat<\/strong> command as follows:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">stat<\/span> File4.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"514\" class=\"wp-image-22181\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-8.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-8-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-8-1024x257.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-8-768x193.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-8-1536x386.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the size of File4.txt is 0 bytes, i.e., File4.txt is a blank file.<\/p>\n<h2><a id=\"post-22088-_u8gty7atqoh0\"><\/a>How to Create\/Generate a Blank File in Linux\/Ubuntu via Printf Command?<\/h2>\n<p>The <strong>printf <\/strong>command is used to create a new file along with displaying the data in the file. A blank file is created via <strong>printf <\/strong>command by the following syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">printf<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>Filename<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Using the above syntax, a blank file \u201cFile5.txt\u201d is created by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">printf<\/span> <span class=\"st_h\">''<\/span> <span class=\"sy0\">&gt;<\/span> File5.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"897\" class=\"wp-image-22184\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-9.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-9-300x131.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-9-1024x449.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-9-768x336.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-9-1536x673.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>In the above command, single quotes (\u2018 \u2019) are used in order to create an empty file. If any characters were inserted between single quotes (\u2018 \u2019), then that data would be written in the file. Additionally, from the above image, it can be verified that the new file: File5.txt has been created and it is of zero bytes. File size can also be verified by <strong>stat<\/strong> command as follows:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">stat<\/span> File5.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"525\" class=\"wp-image-22189\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-10.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-10-300x77.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-10-1024x263.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-10-768x197.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22088-10-1536x394.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the size of File5.txt is 0 bytes, i.e., File5.txt is a blank file.<\/p>\n<h2><a id=\"post-22088-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>Blank Files are created by different methods in Linux\/Ubuntu, like <strong>touch, cat, echo, redirection operator<\/strong>, and <strong>printf<\/strong> command. Additionally, the file creation can be verified by either \u201c<strong>ls -l<\/strong>\u201d or by the \u201c<strong>stat &lt;file_name&gt;<\/strong>\u201d command. These commands information about files. This article demonstrated five different methods of creating a blank file in Linux\/Ubuntu 22.04 LTS.<\/p>","protected":false},"excerpt":{"rendered":"<p>Blank Files are created by different methods in Linux\/Ubuntu, like touch, cat, echo, redirection operator, and printf command.<\/p>","protected":false},"author":110,"featured_media":22200,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-22088","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22088"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22088\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22200"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}