What Type of Terminal User Are You?

In that case, an alias might be a very good idea (such as alias rm = trash), so even if you do run the rm command, bash, or whichever shell you use will replace rm with trash, but unless they both share the same syntax, you’ll probably get errors for unknown arguments.

Ernie

3 Likes

Dont forget to make the alias for root too.

3 Likes

You’re right, and I’m not so sure how well that particular alias might work because I don’t know what the differences between the command-line arguments for rm and trash may be (I don’t know anything about the trash command), although it may also be possible to create a separate alias for each argument, but then the order in which they are listed may be important too so things get more complicated in that case, however that could be an interesting bit to explore, and then perhaps incorporate into my system

Ernie

3 Likes

Hi again, :waving_hand:

@ernie and @nevj :

I think the trash command and the rm command do not use the same syntax in Linux. The trash command is used to move files to a trash bin, while the rm command is used to permanently delete files without recovery.

Command Syntax Comparison

rm Command

The rm command is used to remove files and directories in Linux. Its basic syntax is:

$ rm [options] <file ...>
  • Options: Common options include:
    • -f: Force deletion without confirmation.
    • -i: Prompt for confirmation before each deletion.
    • -r: Recursively delete directories and their contents.

trash Command

The trash command is an alternative that moves files to a trash bin instead of permanently deleting them. Its syntax is:

$ trash [options] <file ...>
  • Options: Common options include:
    • --list: Show files in the trash.
    • --empty: Empty the trash.

Key Differences

Feature rm Command trash Command
Purpose Permanently deletes files Moves files to trash bin
Recovery No recovery option Files can be restored from trash
Confirmation Can prompt with -i option No prompt, but safer by default
Directory Deletion Requires -r for directories Handles directories automatically

The trash command is generally safer for users who want to avoid accidental permanent deletions, while rm is more direct and powerful for immediate file removal.

Many greetings from Rosika :slightly_frowning_face:

2 Likes

So an alias may not work very well.

3 Likes

Hi Neville, :waving_hand:

I guess so.
Unless you think of a shortcut other than rm.

E.g.: a personal shortcut of mine is yy for a dedicated exa command:

functions yy
# Defined in /home/rosika/.config/fish/functions/yy.fish @ line 1
function yy --wraps='env EXA_COLORS=da=33:di=35 exa -lg' --description 'alias yy=env EXA_COLORS=da=33:di=35 exa -lg'
  env EXA_COLORS=da=33:di=35 exa -lg $argv; 
end

(fish syntax)

The use of it has soon become second nature to me. :wink:

Cheers from Rosika :slightly_smiling_face:

3 Likes

Hmmm - interesting…

I wonder how “trash” would handle files on a share?

e.g. if I’m using Nautilus to browse files on my hdd - and press delete - they go into “Trash”… However if I’m browsing remote files on an NFS mount (i.e. my NAS) - there’s no “Trash” and delete, deletes the files “permanently”… I don’t have snapshots enabled on my NAS…

4 Likes

@daniel.m.tripp :

Hi Dan, :waving_hand:

I myself have no idea but your questions sounds interesting.
Here´s duckduckgo´s Search Assist´s opinion:

The trash command in Linux, specifically using utilities like trash-cli, can manage files on a shared network by moving them to the trash directory, typically located at ~/.local/share/Trash/. However, the ability to access and manage these files may depend on the permissions set on the shared location. Tom’s Hardware linuxquestions.org

Handling Files on a Share with the Trash Command in Linux

Overview of Trash Command

The trash command in Linux, particularly through utilities like trash-cli, allows users to move files to a trash directory instead of permanently deleting them. This command is useful for recovering files later.

Behavior on Shared Locations

When using the trash command on files located on a shared network drive, the following points are important:

  • File Movement: The trash command will attempt to move the file to the local trash directory (usually located at ~/.local/share/Trash). This may not work as expected if the shared location does not support this operation.
  • Permissions: The ability to move files to the trash depends on the permissions set on the shared drive. If you lack the necessary permissions, the command may fail.
  • Network Protocols: The behavior can vary based on the network protocol used (e.g., SMB, NFS). Some protocols may not support moving files in the same way as local files.

Using Trash-CLI

If you want to use trash-cli for files on a share, you can follow these commands:

Command Description
trash-put <file> Move a file to the trash.
trash-list List all files in the trash.
trash-restore <id> Restore a file from the trash.
trash-empty Empty the trash.

Conclusion

Using the trash command on shared files can be limited by permissions and the capabilities of the network file system. Always check the specific behavior based on your setup and the type of shared drive you are using.

Cheers from Rosika :slightly_smiling_face:

4 Likes

Hi @Rosika,

Did not know about the ‘trash’ command. Thanks for the info.

3 Likes

Hi Howard, :waving_hand:

I´m glad you like it.
I use it at least once per 28 days for resetting my vnstat database:

sudo trash /var/lib/vnstat/vnstat.db

I need a fresh (empty) database every 4 weeks for a special script (which I wrote a very long time ago) to work properly.

sudo trash-list | wc -l
33

O.K., seems I have to empty my trash one day. :wink:

Many greetings from Rosika :slightly_smiling_face:

3 Likes