{"id":14096,"date":"2022-01-20T19:17:48","date_gmt":"2022-01-20T19:17:48","guid":{"rendered":"https:\/\/linuxways.net\/?p=14096"},"modified":"2022-01-20T19:17:48","modified_gmt":"2022-01-20T19:17:48","slug":"delete-and-dispose-of-files-properly-in-ubuntu-with-shred","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/delete-and-dispose-of-files-properly-in-ubuntu-with-shred\/","title":{"rendered":"Delete and Dispose of Files Properly in Ubuntu With Shred."},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Usually, when a file is deleted on your computer, the system only deletes the file&#8217;s reference. The file remains intact for an indefinite time in your system memory.<\/p>\n<p>Anyone can retrieve these files with file recovery programs and see the deleted data from your storage. It&#8217;s a serious risk if the files contain your private and sensitive information. So how can you erase your files permanently on Ubuntu?<\/p>\n<p>This is when the shred tool comes in handy. This article will go over the shred command&#8217;s workings, limitations, and various ways to use them to dispose of files securely.<\/p>\n<h2>How Does shred Work?<\/h2>\n<p>Shred is a command-line tool that repeatedly overwrites a file&#8217;s original content with zeros. In this way, the original contents of any file get replaced by zeros, so the original data cannot be recovered even if the file is restored. The file can then be securely removed from system storage.<\/p>\n<h2>Limitations of the shred Command<\/h2>\n<p>The Shred utility does not work on journaled, RAID-based, or compressed file systems. It also does not work on the multiple Network File Systems (NFS). You can see the <a href=\"https:\/\/linux.die.net\/man\/1\/shred\">shred man page<\/a> for more detailed information.<\/p>\n<p>Given the above limitations, you should not use shred on a hard drive as overwriting can induce damage to it.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Ubuntu or any other Linux-based distribution<\/p>\n<p>Terminal access<\/p>\n<h2>Basic Syntax of the shred Command<\/h2>\n<p>The basic syntax of the shred command is as follows:<\/p>\n<pre>shred options filename<\/pre>\n<p>Where filename is the full path of the file you want to delete, And options are flags used to run different methods provided by the command.<\/p>\n<h2>Permanently Delete a File With shred<\/h2>\n<p>Run the following command to delete a file permanently.<\/p>\n<pre>shred -uvz text.txt<\/pre>\n<p>Option -u will delete the file, the -v option will display all the processes in the command console, and the -z option will overwrite the file\u2019s content.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"436\" class=\"wp-image-14097\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-401.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-401.png 969w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-401-300x135.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-401-768x346.png 768w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/><\/p>\n<h2>Delete\/Overwrite File Content With shred<\/h2>\n<p>If you do not want to delete a file and only want to remove the contents of the file, you can run the following command.<\/p>\n<pre>shred -vz text.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1085\" height=\"146\" class=\"wp-image-14098\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-402.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-402.png 1085w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-402-300x40.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-402-1024x138.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-402-768x103.png 768w\" sizes=\"auto, (max-width: 1085px) 100vw, 1085px\" \/><\/p>\n<p>Open the targeted file and you will see the file&#8217;s content is replaced with strings of zeros.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"901\" height=\"480\" class=\"wp-image-14099\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-403.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-403.png 901w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-403-300x160.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-403-768x409.png 768w\" sizes=\"auto, (max-width: 901px) 100vw, 901px\" \/><\/p>\n<h2>Overwrite File Content Multiple Times With shred<\/h2>\n<p>You can overwrite a file multiple times to ensure that the data is replaced. Just specify the number of times you want to overwrite a file with the -n option. Keep in mind that shred utility will always do an extra overwrite.<\/p>\n<pre>shred -uvz -n 3 text.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1361\" height=\"486\" class=\"wp-image-14100\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-404.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-404.png 1361w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-404-300x107.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-404-1024x366.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-404-768x274.png 768w\" sizes=\"auto, (max-width: 1361px) 100vw, 1361px\" \/><\/p>\n<p>You can see the overwrite is done four times in the output.<\/p>\n<h2>Permanently Delete Multiple Files With shred<\/h2>\n<p>You can also delete multiple files with shred. Just mention multiple filenames in the command.<\/p>\n<pre>shred -uvz test1.txt test2.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1230\" height=\"718\" class=\"wp-image-14101\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-405.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-405.png 1230w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-405-300x175.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-405-1024x598.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-405-768x448.png 768w\" sizes=\"auto, (max-width: 1230px) 100vw, 1230px\" \/><\/p>\n<h2>Delete Files With Specific Formats<\/h2>\n<p>You can also delete by their specific formats. Run the following command to delete all the text files in the folder.<\/p>\n<pre>shred -uvz *.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1402\" height=\"747\" class=\"wp-image-14102\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-406.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-406.png 1402w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-406-300x160.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-406-1024x546.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-406-768x409.png 768w\" sizes=\"auto, (max-width: 1402px) 100vw, 1402px\" \/><\/p>\n<h2>Overwrite Part of a File With shred<\/h2>\n<p>Shred lets you do partial overwriting too. The command below will overwrite the one kilobyte of the file.<\/p>\n<pre>shred -vz -s 1K test3.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1415\" height=\"252\" class=\"wp-image-14103\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-407.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-407.png 1415w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-407-300x53.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-407-1024x182.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-407-768x137.png 768w\" sizes=\"auto, (max-width: 1415px) 100vw, 1415px\" \/><\/p>\n<p>You can see that part of the file has been overwritten.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"983\" height=\"522\" class=\"wp-image-14104\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-408.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-408.png 983w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-408-300x159.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-408-768x408.png 768w\" sizes=\"auto, (max-width: 983px) 100vw, 983px\" \/><\/p>\n<h2>More About shred<\/h2>\n<p>You can run the following command and see what else the shred utility has to offer.<\/p>\n<pre>shred \u2013help<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1416\" height=\"673\" class=\"wp-image-14105\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-409.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-409.png 1416w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-409-300x143.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-409-1024x487.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-409-768x365.png 768w\" sizes=\"auto, (max-width: 1416px) 100vw, 1416px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>The default method for deleting files and folders in Ubuntu is really simple and easy, but it is neither permanent nor secure. Your files can be recovered and leaked with the help of data recovery software.<\/p>\n<p>Shred combats this issue by overwriting the file content with random data before deleting the file. In this tutorial, you have learned how to permanently delete files in Ubuntu using the shred utility.<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction Usually, when a file is deleted on your computer, the system only deletes the file&#8217;s reference. The file remains intact for an indefinite time in your system&hellip;<\/p>","protected":false},"author":1,"featured_media":14242,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[305,31],"class_list":["post-14096","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-shred-command","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14096","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=14096"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14096\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14242"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=14096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=14096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=14096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}