logo
  • Home
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

Questions & Answers

C Interview Questions
C++ Questions
Linux MCQs
C# Quiz
Java MCQs
JavaScript MCQs
SAN Questions
PHP Questions
Python Quiz

Computer Science Questions

Operating System Quiz
Computer Architecture MCQs
Software Architecture MCQs
Software Engineering MCQs
Artificial Intelligence MCQs
LISP Programming MCQs
Database Management MCQs
Computer Network MCQs
Microprocessor MCQs

C Programming Examples

Simple C Programs
C - Arrays
C - Matrix
C - Strings
C - Bitwise Operations
C - Linked Lists
C - Stacks & Queues
C - Searching & Sorting
C - Trees
C - Strings
C - File Handling
C - Mathematical Functions
C - Puzzles & Games
C Programs - Recursion
C Programs - No Recursion

Java Algorithms

Java - Numerical Problems
Java - Combinatorial Problems
Java - Graph Problems
Java - Hard Graph Problems
Java - Computation Geometry
Java - Sets & Strings
Java - Data-Structures
Java - Collection API Problems

C++ Algorithms

C++ - Numerical Problems
C++ - Combinatorial Problems
C++ - Graph Problems
C++ - Hard Graph Problems
C++ - Computation Geometry
C++ - Sets & Strings
C++ - Data-Structures
C++ - STL Library

C Algorithms

C - Numerical Problems
C - Combinatorial Problems
C - Graph Problems
C - Hard Graph Problems
C - Computation Geometry
C - Sets & Strings
C - Data-Structures

« Prev Page
Next Page »

5 “shred” Command Usage Examples in Linux

Posted on December 21, 2013 by Manish

This tutorial explains Linux “shred” command, options and its usage with examples.

shred – delete a file securely, first overwriting it to hide its contents

DESCRIPTION

shred is a program that will overwrite your files in a way that makes them very difficult to recover by a third party.

Normally, when you delete a file, that portion of the disk is simply marked as being ready for another file to be written to it — but the data is still there. If a third party were to gain physical access to your disk, they could, using advanced techniques, access the data that you thought you had deleted.

The analogy is that of a paper shredder. If you simply crumple up a piece of paper and throw it in the trash can, a third party could come along, root through your trash, and find your discarded documents. If you really want to destroy the document, it’s best to use a paper shredder. (Or burn it, I suppose, but that’s not always practical in a typical office.)

The way that shred accomplishes this type of destruction digitally is to overwrite (over and over, repeatedly, as many times as you specify) the data you want to destroy, replacing it with other (usually random) data. This magnetically destroys the data on the disk and makes it highly improbable that it can ever be recovered.

SYNOPSIS

shred [OPTIONS] FILE […]

OPTIONS :

-f, –force
change permissions to allow writing if necessary
-n, –iterations=N
Overwrite N times instead of the default (25)
-s, –size=N
shred this many bytes (suffixes like K, M, G accepted)
-u, –remove
truncate and remove file after overwriting
-v, –verbose
show progress
-x, –exact
do not round file sizes up to the next full block
-z, –zero
add a final overwrite with zeros to hide shredding
–
shred standard output

Note: Delete FILE(s) if –remove (-u) is specified. The default is not to remove the files because it is common to operate on device files like /dev/hda, and those files usually should not be removed. When operating on regular files, most people use the –remove option.

EXAMPLES

1. Overwrite the data of file1.txt, file2.jpg, and file3.doc using the default shredding methods.

$ shred file1.txt file2.jpg file3.doc

2. Same as above, but also delete those three files, freeing up that space on the disk for later use.

$ shred -u file1.txt file2.jpg file3.doc

3. Overwrite a partition

shred /dev/hda6

Overwrite all data on the partition /dev/hda6.

4. To see what shred is actually doing, give it the verbose -v option:

$ shred -u -v private.txt
shred: private.txt: pass 1/25 (random)...
shred: private.txt: pass 2/25 (cccccc)...
shred: private.txt: pass 3/25 (111111)...
shred: private.txt: pass 4/25 (000000)...
shred: private.txt: pass 5/25 (999999)...
shred: private.txt: pass 6/25 (aaaaaa)...
shred: private.txt: pass 7/25 (924924)...
shred: private.txt: pass 8/25 (b6db6d)...
shred: private.txt: pass 9/25 (6db6db)...
shred: private.txt: pass 10/25 (888888)...
shred: private.txt: pass 11/25 (492492)...
shred: private.txt: pass 12/25 (db6db6)...
shred: private.txt: pass 13/25 (random)...
shred: private.txt: pass 14/25 (ffffff)...
shred: private.txt: pass 15/25 (bbbbbb)...
shred: private.txt: pass 16/25 (777777)...
shred: private.txt: pass 17/25 (444444)...
shred: private.txt: pass 18/25 (dddddd)...
shred: private.txt: pass 19/25 (333333)...
shred: private.txt: pass 20/25 (555555)...
shred: private.txt: pass 21/25 (222222)...
shred: private.txt: pass 22/25 (eeeeee)...
shred: private.txt: pass 23/25 (666666)...
shred: private.txt: pass 24/25 (249249)...
shred: private.txt: pass 25/25 (random)...
shred: private.txt: removing
shred: private.txt: renamed to 00000000000
shred: 00000000000: renamed to 0000000000
shred: 0000000000: renamed to 000000000
shred: 000000000: renamed to 00000000
shred: 00000000: renamed to 0000000
shred: 0000000: renamed to 000000
shred: 000000: renamed to 00000
shred: 00000: renamed to 0000
shred: 0000: renamed to 000
shred: 000: renamed to 00
shred: 00: renamed to 0
shred: private.txt: removed

5. This will overwrite the data on the drive with garbage using 30 passes

 shred -u -n 30 /dev/hda

The drive will need to be re-formatted after this as even the filesystem structure will be destroyed.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.
« Prev Page - 5 “split” Command Usage Examples in Linux
» Next Page - “tail” Command Usage Examples in Linux
« 5 “split” Command Usage Examples in Linux
“tac” Command Usage Examples in Linux »

Deep Dive @ Sanfoundry:

  1. C Programming Examples on Strings
  2. Linux Questions and Answers
  3. C Programming Examples on Stacks & Queues
  4. Python Programming Examples
  5. C Programming Examples
  6. C# Programming Examples on LINQ
  7. C# Programming Examples
  8. C# Programming Examples on Files
  9. C Programming Examples on File Handling
  10. Linux Command Tutorials with Examples and Explanations
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
TOS & Privacy
Jobs
Bangalore Training
Online Training
SAN Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry