Recycle bin.

Hi.
I've created scripts for a recycle bin that can list, restore and empty it. I only have the problem of deleting two files with the same name. When I do it one file overwrite the other. What could I do to resolve it? The only thing I can think is asking the user to rename file before moving to the recycle bin but it wouldn't be a good solution. Any ideas please?

Thank you.

You do not need to ask the user. You could implement in the script the ability to rename the file going to the "recycling bin", appending something like a day stamp.

1 Like

You could make use of the functionality of man mktemp (linux). Something like:

TRASHFILE=$(mktemp --tmpdir=${TRASHDIR} $(basename ${file}).XXXXXX)

One thing to keep in mind is that moving files to your "recycle bin" are copied if the source and target filesystems are different. This could lead to unpleasant surprises. Also be careful of files with more than one hardlink, or files that are opened by a process.

1 Like