Skip to content
Advertisement

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement