Shawn Brar
Shawn Brar

Reputation: 1420

Run a command on a list of files

The command shred in ubuntu does not shreds files recursively. Hence, I wanted to list all the files in a directory by doing find -L and then shred these files using shred. However, find -L | shred does not works. Can someone please help me do so?

Thanks in advance.

Upvotes: 1

Views: 519

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207385

You can actually get them done in parallel very simply with GNU Parallel like this:

find -L -type f -print0 | parallel -0 -X shred

Upvotes: 2

Socowi
Socowi

Reputation: 27205

find | shred works as if you ran just shred and then started typing the paths to be shredded into the terminal. But shred does not care about stdin. It only shreds paths given as arguments.

To pass the paths printed by find as arguments to another program you can use xargs, or better find -exec.

Here we also only shred files, as shred someDirectory will just print an error.

find -L -type f -exec shred {} +

Reminder: Depending on your file system and hardware shred might not overwrite the physical original. Especially file systems like Btrfs with its CoW mechanism and SSDs with their wear leveling are problematic.

Upvotes: 0

Related Questions