Delete the contents of every file in directory


Why would you want to take every file you have and delete its contents? Well if you have sensitive financial or proprietary data you know why. Deleting these files and even using shredding software sometimes allows for the data of these files to be recovered. However, one method of not allowing a file to be recovered is to open the file, modify the contents and delete the file.

Below, I will show you how to easily do that with a few lines of code in practically no time.

First, if you are a windows user, you will need cygwin to accomplish this.  Otherwise, if you are a Linux user you can create and run script below.

  • Open a text editor
  • Type the following code in your text editor

for i in ls

do

cp /dev/null $i

rm $i

done

  • Save your file in the folder where you want to delete all files.  Save the file without the .txt extension.  If you are going to give your file an extension, give it an .sh extension.
  • Open cygiwn and navigate to your file location.  Provided that your file was name cleaner.sh, then type the following command in cygwin:  ./cleaner.sh

That is it.  You can open a window to that folder and view as the magic happen.

If you have any questions, post a comment.  When I get an opportunity, i will post how to accomplish this same task using a windows batch file.

Leave a comment

Filed under Sharing Stuff

Comment on this

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s