[Linux ] rm vs shred command

Matthew Boyd
2 min readOct 14, 2020

--

So everyone knows of rm — the remove command. This is one of the first commands you’ll learn along with cp(copy), mv(move) and all of these commands will be used on a daily basis by beginners right up to expert linux users.

However, a lesser known command is shred . In theory, with a real world context, both of these commands will get rid of data for us. However, there is a subtle difference between them, which could be very beneficial to know.

rm will simply delete the file from the file system, however the bytes from the contents will still remain until they are overwritten by another file. However, with shred it will populate the file with random bytes so that your content is destroyed, and then if specified it will delete the contents.

So we have a file called testfile, and in that file there is the following contents:

Now if we run shred testfile and then we cat testfile this is the result:

It has filled our file with lots of random content, so it has an additional layer that rm doesn’t have. rm will simply delete the file’s reference, but the content is still there until it is overwritten, whereas shred will overwrite the contents in that moment so that your contents is essentially gone for good. You can then specify the -u parameter to the shred command and it will then delete the file after it populates it with random foo.

--

--

Matthew Boyd
Matthew Boyd

Written by Matthew Boyd

Learning, and posting my findings!

No responses yet