Working with the trash-cli Command (with examples)
The trash-cli command-line tool allows users to manage their trashcan, providing a convenient way to put files and directories into the trash, remove specific items, empty the trash, list trashed files, and restore them from the trashcan. In this article, we will explore different use cases of the trash-cli command, including code examples, motivations, explanations of arguments, and example outputs.
Putting Files and Directories into the Trash
To put specific files or directories into the current trashcan, we can use the trash-put
command followed by the path to the items we want to trash.
trash-put path/to/file_or_directory1 path/to/file_or_directory2 ...
Motivation:
We may want to remove unnecessary files or directories from our system, but sometimes we delete them accidentally. The trash-put
command provides a safer way to move the files or directories to the trashcan instead of permanently deleting them.
Explanation:
path/to/file_or_directory1
,path/to/file_or_directory2
, etc.: These arguments represent the paths to the files or directories that we want to move to the trashcan.
Example Output:
/path/to/file_or_directory1 trashed successfully.
/path/to/file_or_directory2 trashed successfully.
Removing Files from the Trashcan
If we want to remove specific files from the current trashcan, we can use the trash-rm
command followed by the paths to the items we want to remove.
trash-rm path/to/file_or_directory1 path/to/file_or_directory2 ...
Motivation:
There might be situations where we accidentally trashed files that we now need to permanently delete. The trash-rm
command allows us to remove specifically selected items from the trashcan.
Explanation:
path/to/file_or_directory1
,path/to/file_or_directory2
, etc.: These arguments represent the paths to the files or directories that we want to remove from the trashcan.
Example Output:
/path/to/file_or_directory1 removed successfully from the trash.
/path/to/file_or_directory2 removed successfully from the trash.
Emptying the Trashcan
To completely empty the current trashcan, we can use the trash-empty
command.
trash-empty
Motivation:
Over time, the trashcan can accumulate a significant amount of files and directories, taking up storage space. By using the trash-empty
command, we can free up this space by permanently deleting all items stored in the trashcan.
Explanation:
This command does not require any additional arguments.
Example Output:
Trashcan emptied successfully. 5 items removed.
Listing Trashed Files and Directories
To list all the files and directories that are currently in the trashcan, we can use the trash-list
command.
trash-list
Motivation:
When we want to review the contents of our trashcan before permanently deleting or restoring any items, the trash-list
command provides a convenient way to display a comprehensive list of trashed files and directories.
Explanation:
This command does not require any additional arguments.
Example Output:
1. /path/to/file1
2. /path/to/directory1/
3. /path/to/file2
Restoring Files and Directories
To restore a specific file or directory from the trashcan, we first need to determine its number in the displayed list from the trash-list
command. We can then use the trash-restore
command followed by the respective number.
trash-restore number
Motivation:
Sometimes, we realize that we have mistakenly trashed important files or directories, and we want to restore them instead of losing them permanently. The trash-restore
command provides a straightforward way to recover specific items from the trashcan.
Explanation:
number
: This argument represents the number assigned to the trashed file or directory that we want to restore, as displayed by thetrash-list
command.
Example Output:
/path/to/file1 restored successfully.
In conclusion, the trash-cli command-line tool offers a practical solution for managing the trashcan. With the provided examples and explanations, users can effectively trash, remove, empty, list, and restore files and directories from the trashcan, ensuring a safer and more efficient approach to managing deleted items.