Shred files with Terminal (Echo -n)

Hi!

I've recently discovered this command that empties the file content in one line

echo -n > ~/desktop/file.jpg

I want to apply this command to each file on a folder.

Since I don't know anything about terminal, I've tried windows style and it didn't worked 😁

echo -n > ~/desktop/*.jpg

Thanks for your time!

Posted on Dec 3, 2017 2:05 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 3, 2017 7:13 PM

This is a DANGEROUS thing to do, because if you are in the wrong place, you will delete the contents of files you may not wish to loose.


STRONGLY suggest you have a backup, just before doing this operation each and every time you use it.

find /path/to/the/folder/you/want/to/shred -maxdepth 1 | while read file

do

echo -n >"$file"

done

If you need to apply this to just a subset of files, then if you can provide a pattern for file selection you can use:

find /path/to/the/folder/you/want/to/shred -maxdepth 1 -iname "*.jpg" | while read file

do

echo -n >"$file"

done

Where you use the -iname "..." argument and use standard Unix shell file selection wildcards


If you are smart you will first write the code to

echo "$file"

without the "-n >" so the commands just echo out the files that are going to be shredded. Once you are happy the commands are selecting the files you want to shred, then use the echo -n >"$file"

12 replies
Question marked as Top-ranking reply

Dec 3, 2017 7:13 PM in response to Fedebarberan

This is a DANGEROUS thing to do, because if you are in the wrong place, you will delete the contents of files you may not wish to loose.


STRONGLY suggest you have a backup, just before doing this operation each and every time you use it.

find /path/to/the/folder/you/want/to/shred -maxdepth 1 | while read file

do

echo -n >"$file"

done

If you need to apply this to just a subset of files, then if you can provide a pattern for file selection you can use:

find /path/to/the/folder/you/want/to/shred -maxdepth 1 -iname "*.jpg" | while read file

do

echo -n >"$file"

done

Where you use the -iname "..." argument and use standard Unix shell file selection wildcards


If you are smart you will first write the code to

echo "$file"

without the "-n >" so the commands just echo out the files that are going to be shredded. Once you are happy the commands are selecting the files you want to shred, then use the echo -n >"$file"

Dec 6, 2017 7:34 AM in response to Fedebarberan

Applications -> Automator -> Application

User uploaded file

You can then drag and drop a folder on top of the app you create with Automator, and all the files inside will become empty. The names will still exist, but there will be no data associated with any of the files.


Again, a very dangerous script you are creating. You need to be very careful with it.


If you do not want the drag and drop capabilities, and you want an explicit folder, then

User uploaded file

You need to provide "/the/path/to/the/specific/folder" information. This is not a drag and drop app, rather you double-click on the app and it will remove the storage for all the files in the specified folder.

Dec 6, 2017 11:12 AM in response to Fedebarberan

This is security by obscurity. The data is still on your drive. You would need hacker tools to recover the data plus a lot of patience. The only security today is encryption. I'd use disk utility to create encrypted disk volumes. This would be a better solution. Create an encrypted disk volume for each project. When you are done with the project, delete the disk volumes. Poof. The data has gone up in a cloud of smoke.


How to Create an Encrypted Disk Image to Securely Store Sensitive Files on a Mac


an academic flavor. Academics have good eyesight.

http://technology.pitt.edu/help-desk/how-to-documents/creating-encrypted-disk-im age-mac-os-x


R

Dec 7, 2017 12:04 AM in response to rccharles

You are not erasing the data. You are deleting a link to the data. The data stays on the drive. Data is placed in 512 character blocks. This would be hard, but should there be some some known string in the data like GreenMaritians, an app can be written to search the drive for the string GreenMaritians. Once found, the app would have found a 512 character block of your data. Before you smile at the small amount of data, the system write out the data in sequential blocks as much as possible. Whether some one would take the time to do this depends on the value of your data. Stock predictions if accurate might be such data. The results from a test of a medication under development. It can cost a billion dollars to develop a new medication.


You don't have to worry now. You have encrypted all your data block via filevault. This means there isn't a way to search for a common string in your data like GreenMaritians.


Be sure to backup your data well. Any minor glitch on your drive, can mean all the data on the drive is lost.


ssd drives use a level of indirection to the data. All blocks has a number associated with them which is call an address. On the traditional harddrives this is the physical disk address. On a ssd the address you see is a logical address not the physical address. The ssd translates the logical address to the true physical address. The translations doesn't result in the same physical address every time. It is more like a random physical address. When you read a block of data, then you write back a block of data, the out bound data isn't likely to go to the same physical location as the read data. There is no easy way of zeroing out a block of data. You can zero out the entire ssd that you can see, but you still miss a small percentage of unseen blocks.


R

Dec 6, 2017 11:42 PM in response to Fedebarberan

You are not erasing the data. You are deleting a link to the data. The data stays one the drive. This would be hard, but should there be some some known string in the data like GreenMaritians, an app can be written to search the drive for the string GreenMaritians. Once found, the app would have found a 512 character block of your data. Whether some on would take the time to do this depends on the value of your data. Stock predictions if accurate might be such data. The results from a medication test. It can cost a billion dollars to develop a new medication.


You don't have to worry now. You have encrypted all your data block via filevault. This means there isn't a way to search for a common string in your data like GreenMaritians.


Be sure to backup your data well. Any minor glitch on your drive, can mean all the data on the drive is lost.


R

Dec 5, 2017 1:13 PM in response to BobHarris

Hi Bob!

Thanks for the warnings and for your time!

I will need a little extra help here. I'm an advanced user of computers but I have zero coding/commands knowledge.

I've tried that first command on the "Script Editor" app with no luck 😕 "A number can't go after this identifier: maxdepth 1"


find ~/user/desktop/123 -maxdepth 1 | while read file

do

echo -n >"$test.jpg"

done


What I ultimately want is to push one button and the line, script or program can empty the files content. Thanks!

Dec 6, 2017 7:44 PM in response to rccharles

I think is not life or dead sensitive data but I like to treat it as safe as I can and learning stuff in the meantime


- I've just set up File vault. It was a pending task.

- The Automator APP described by Bob it works awesome.

- I remember now those encrypted volumes! Long time ago I was using them, its time to do it again. Thanks for reminding me that!

- Yes, I have extra care about my files, plus most of my work goes online and It isn't so extended in time, I may loose an hour of work at most. That's why I don't want to have anything locally.


- I don't get the whole point when you say that the data is still on the drive after deleting its content. I mean, that's what this idea came from. I know that you can recover files after being erased BUT this files will be having zero KB before deletion so you will recover zero KB files. What am I missing there?


I just find out that secure erase is no longer an option on sierra encripted-ssd drives.

Dec 6, 2017 12:17 PM in response to Fedebarberan

Well after the script I will then secure delete

How do you plan on going about the secure delete?

-- Are you secure deleting the unused space from Disk utility?

-- Moving the files to the trash can and secure deleting the files via trash can delete will not get the data. It's a free radical on the disk drive.


them and make sure encription is enabled.

You use file vault? This will have all data on the drive encrypted. Your method will work without doing any additional work. The file data block will all be encrypted and meaning less.


I'd strongly advise putting up a question and displaying the folder to delete and asking if this is correct before proceeding. I just dropped a file today in the wrong folder. I don't know automator so it's a zero for me.


Your method is a time bomb. What happens when you delete a work in progress folder?


R

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Shred files with Terminal (Echo -n)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.