You are not logged in.

#1 2019-03-02 11:30:39

genericaf
Member
Registered: 2016-03-25
Posts: 17

Best Trash Solution for Command Line

I just removed a couple of files by accident with rm. Unfortunately, I don't have any trash functionality configured on my system. All CLI users that use some trash tool I ask: What's your trash solution? I couldn't find a widespread method. Is there some (pseudo-)standard? What practice would you consider the most common one?

Creating an alias dl (for "delete") for mv -t ~/.Trash seems like a good idea to me, except that trash from other partitions will also end up in my home directory.

I'm aware of the package trash-cli. Do you use it? It's kind of verbose; do you alias it? Will I encounter problems with different partitions or block devices?

Thanks a lot!

Offline

#2 2019-03-02 11:54:09

N_BaH
Member
Registered: 2015-12-30
Posts: 84

Re: Best Trash Solution for Command Line

hi,

trash from other partitions will also end up in my home directory

can you explain ?

Offline

#3 2019-03-02 12:00:00

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Best Trash Solution for Command Line

N_BaH wrote:

hi,

trash from other partitions will also end up in my home directory

can you explain ?

I think the OP means, they are used to some kind of trash tool where "deletion" just moves the item to a place under ~/.Trash

So, if you have some extra storage mounted, and you "delete" it, it gets copied to your home directory. (Presumably.)

Offline

#4 2019-03-02 12:09:43

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Best Trash Solution for Command Line

genericaf wrote:

All CLI users that use some trash tool I ask: What's your trash solution? I couldn't find a widespread method.

People can configure their system how they want. It's not surprising that there is no standardisation amongst all the ad hoc hacks that everyone comes up with for doing this non-standard thing that you want to do.

This is the benefit and curse of using Linux: do what you want, but don't expect it to be standard.

I recommend just get used to the fact that there is no trash. Just get used to using rm. You will thank yourself when you realise how clean your system is without all the crap from the past hanging around. You deleted it, right, so why is it still hanging around?

Sure, if you use rm, it's (basically) gone forever. So don't use rm willy nilly. If you're not sure if you want a file gone forever, save it somewhere and decide sometime in the future whether to rm it. That is basically what all the so-called "trash" systems do anyway.

But when you decide it's really time for that file to be gone, don't equivocate. Pull the trigger. Use rm.

Last edited by /dev/zero (2019-03-02 12:10:34)

Offline

#5 2019-03-02 12:17:55

Morn
Member
Registered: 2012-09-02
Posts: 886

Re: Best Trash Solution for Command Line

I usually just open a file manager in the current directory ("nautilus .") if I want to delete files or folders. File deletion mistakes usually happen due to wildcard expansion gone wrong (or accidentally hitting the space bar in the wrong place), so a GUI is much better because you cannot shoot yourself in the foot with a badly thought out wildcard. Who has the discipline to test each wildcard expression first?

So  "alias rm=nautilus" is best in my experience... smile

Offline

#6 2019-03-02 12:20:15

genericaf
Member
Registered: 2016-03-25
Posts: 17

Re: Best Trash Solution for Command Line

@/dev/zero

You're right, there's not standard, I just hoped for some pro-recommendations :-)

Also, I've been using rm for 5 years now and this is just the second time I deleted something important by accident (this time: typing error). I thought there might be a good solution (maybe just a simple tweak or configuration) of which I'm just not aware. Couldn't find anything online, that's why I'm posting here, hope that's OK :-)

Offline

#7 2019-03-02 12:27:54

progandy
Member
Registered: 2012-05-17
Posts: 5,321

Re: Best Trash Solution for Command Line

The AUR package rmtrash has rm/rmdir compatible scripts for trash-cli if you really want to replace your standard commands. trash-cli follows the xdg trash specification: https://www.freedesktop.org/wiki/Specif … rash-spec/

Normal trash will be in $XDG_DATA_HOME/Trash.

Trash from other partitions may land in one of these locations:
$MOUNTPOINT/.Trash/$UID if the .Trash exists and $UID exists/can be created
$MOUNTPOINT/.Trash-$UID if .Trash is missing and .Trash-$UID exists/can be created
$XDG_DATA_HOME/Trash if both $MOUNTPOINT options fail.
as a last resort the trash operation is refused and nothing is deleted.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#8 2019-03-02 12:39:27

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Best Trash Solution for Command Line

genericaf wrote:

@/dev/zero

You're right, there's not standard, I just hoped for some pro-recommendations :-)

Also, I've been using rm for 5 years now and this is just the second time I deleted something important by accident (this time: typing error). I thought there might be a good solution (maybe just a simple tweak or configuration) of which I'm just not aware. Couldn't find anything online, that's why I'm posting here, hope that's OK :-)

Yeah, I see.

So, you've got an existing alias. It works okay, except you don't want your home directory populated with files when you delete them from some extra storage device you've got mounted?

What would you say should happen to a file on the extra storage when you delete it? Just rm it?

Offline

#9 2019-03-02 12:51:47

genericaf
Member
Registered: 2016-03-25
Posts: 17

Re: Best Trash Solution for Command Line

/dev/zero wrote:
genericaf wrote:

@/dev/zero

You're right, there's not standard, I just hoped for some pro-recommendations :-)

Also, I've been using rm for 5 years now and this is just the second time I deleted something important by accident (this time: typing error). I thought there might be a good solution (maybe just a simple tweak or configuration) of which I'm just not aware. Couldn't find anything online, that's why I'm posting here, hope that's OK :-)

Yeah, I see.

So, you've got an existing alias. It works okay, except you don't want your home directory populated with files when you delete them from some extra storage device you've got mounted?

What would you say should happen to a file on the extra storage when you delete it? Just rm it?

I've not actually tried using the alias rm for mv -t ~/.Trash yet. Concerning your question, I think I really like the freedesktop.org's trash-spec which user progandy has kindly linked. I will have a deeper look into the rmtrash package! But I hope some more users want to share their experience here.

Offline

#10 2019-03-02 15:22:17

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,518
Website

Re: Best Trash Solution for Command Line

I just use rm sparingly, only when I really want to remove something.  I have a junk folder for when I'm just cleaning up stuff that I suspect I will not need again and want to get out of the way, I just move old documents into the junk folder.  Periodically I create a dated subfolder of junk and move all of it's contents into the subfolder (so I get nested older and older junk folders).

I rarely ever look into my junk folder, but it has saved my *** a few times when I did need to track down some old information.

Last edited by Trilby (2019-03-02 15:22:47)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#11 2019-03-02 18:19:22

LindyBalboa
Member
Registered: 2016-10-06
Posts: 39

Re: Best Trash Solution for Command Line

I second trash-cli since it is in the community repo and as Progandy said, it follows xdg.

Offline

#12 2019-03-02 18:29:18

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Best Trash Solution for Command Line

As noted; use `rm` thoughtfully. And have a tested backup regime, incremental and snapshots.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#13 2019-03-02 19:59:17

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Best Trash Solution for Command Line

I echo the above comments really.

Read this comment about not using rm unless you are sure that you want to, it sums up the argument quite nicely...
https://apple.stackexchange.com/a/17625

And make sure you keep good backups, they need testing regularly anyway to be of any use.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#14 2019-03-03 02:33:26

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Best Trash Solution for Command Line

/dev/zero wrote:
genericaf wrote:

All CLI users that use some trash tool I ask: What's your trash solution? I couldn't find a widespread method.

People can configure their system how they want. It's not surprising that there is no standardisation amongst all the ad hoc hacks that everyone comes up with for doing this non-standard thing that you want to do.

This is the benefit and curse of using Linux: do what you want, but don't expect it to be standard.

As progandy mentioned, there *is* a standard and it is called the XDG/FreeDesktop Trash Specification.

It doesn't specify which tool you should use to transfer files into the trash, but it definitively defines what a trashcan should look like...

...

And generally in response to the thread: I encourage the use of trash-cli (but then I am also the maintainer of the [community] package). You can if you choose use trash-put as an alias for the rm command, since trash-put supports flags like -d -f -i -r as "ignored (for GNU rm compatibility)".

Some other people might suggest using alias rm='rm -i' for interactive shells, as that will prompt you for each file you try to delete. But that is *not* a trash implementation, it just -- purportedly -- makes you think twice before deleting anything to prevent e.g. fat-fingering and removing things you did not mean to.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#15 2019-03-03 02:54:49

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Best Trash Solution for Command Line

eschwartz wrote:

Some other people might suggest using alias rm='rm -i' for interactive shells, as that will prompt you for each file you try to delete. But that is *not* a trash implementation, it just -- purportedly -- makes you think twice before deleting anything to prevent e.g. fat-fingering and removing things you did not mean to.

Yes. The issue with this is that, over time, you become habituated to hitting Enter twice... It's not really a safety net, it just makes you think you have one.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#16 2019-03-03 03:03:37

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Best Trash Solution for Command Line

I did say "purportedly". big_smile I haven't extensively experimented with such a workflow... in fact, I have not even tried such a workflow at all...


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB