Bash - Trash Command

Make a trash command in bash, which sends files to a recyle bin, instead of deleting them.

For the solution, we will separate each task into separate commands, and then combine then into one trash command.

Move Files Into Trash Folder

Make Trash Folder

In the default directory, we will make a directory for storing trash, then a directory for storing logs.

$ mkdir ~/trash ~/logs

Move Items to Trash

This will move a file to trash. We will make this configurable later.

$ mv file_name.txt ~/trash

Log Actions in a File

Add a Timestamp

This will return a timestamp in the format: HH:MM:SS.

$ date | cut --delimiter " " --fields 4

Log Files

$ date 1>> timestamp

[Bonus] Make It a Script

Add Script to PATH

$ mkdir ~/bin