You are not logged in.

#1 2018-04-17 22:15:53

Flameslicer
Member
Registered: 2017-10-09
Posts: 2

Is it possible to have a folder delete anything placed into it?

I want to have a folder on my desktop that will automatically delete any files or other folders I put into it as a general trash can. While I know there are plenty of trash can/recycle bin style programs, I haven't found anything that just deletes everything I put into it.

Offline

#2 2018-04-17 22:52:56

circleface
Member
Registered: 2012-05-26
Posts: 639

Re: Is it possible to have a folder delete anything placed into it?

Do you want the file to be deleted immediately, or do you want to wait until you reboot / shutdown.  If reboot / shutdown is ok, you could always create a tmpfs mount point on your desktop, that way the files are moved to ram and thus deleted when you poweroff or restart.

Offline

#3 2018-04-17 22:58:27

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Is it possible to have a folder delete anything placed into it?

If you're happy with a slight delay, just crontab an `rm -Rf /home/flameslicer/Desktop/deleteme/*` every 5 minutes.

Offline

#4 2018-04-17 23:32:54

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

Re: Is it possible to have a folder delete anything placed into it?

You could install and mount a fuse "nullfs". There is a package in the AUR, I don't know how well it works.


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

Offline

#5 2018-04-18 00:26:27

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

Re: Is it possible to have a folder delete anything placed into it?

#!/bin/sh

trash=/home/YourName/Desktop/TrashCan

inotifywait -m $trash | while read line; do
        rm -rf $trash/*
done

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2018-04-18 00:31:28

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Is it possible to have a folder delete anything placed into it?

Trilby's solution is the most elegant... One minor fix is to double-quote $trash if is has any spaces in the path.

Offline

#7 2018-04-18 01:42:08

CarbonChauvinist
Member
Registered: 2012-06-16
Posts: 412
Website

Re: Is it possible to have a folder delete anything placed into it?

Maybe something like nullfs?

OVERVIEW

nullfs is FUSE filesystem driver which discards
all files' data written to it.

Could be fun to try anyway...

::::edit: just realized this was already posted by @progandy, my bad

Last edited by CarbonChauvinist (2018-04-18 01:44:25)


"the wind-blown way, wanna win? don't play"

Offline

#8 2018-04-18 07:31:27

Cody Learner
Banned
Registered: 2017-12-06
Posts: 54
Website

Re: Is it possible to have a folder delete anything placed into it?

Deletion error recovery is the (only?) payoff for dealing with trash, right? I'd likely loose sleep without my usual year+ heap of trash "error insurance".

Thinking the 'find -mtime XX -delete /path/to/trash' command could be useful and avoids parsing ls. Reboot systems only when required, so cron or systemd timer.

Properly set up, a system could delete the trash contents daily of everything older than XX days, maintaining an inventory based on age. Downside, this would be significantly more complicated than writing a simple script as already suggested.

Last edited by Cody Learner (2018-04-18 07:32:59)


Self designated Linux and Bash mechanic.....
I fix and build stuff hands on. I'm not opposed to creating a mess in obtaining a goal.

Offline

#9 2018-04-18 11:10:29

NoSuck
Member
Registered: 2015-03-04
Posts: 157
Website

Re: Is it possible to have a folder delete anything placed into it?

I am befuddled.

If you want to delete something, just delete it.

If you want to pretend to delete something (send it to the recycle bin), just move it to a folder and delete the folder's contents later.

Offline

#10 2018-04-18 11:36:12

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

Re: Is it possible to have a folder delete anything placed into it?

Cody Learner wrote:

Thinking the 'find -mtime XX -delete /path/to/trash' command could be useful

I second that as yet a better approach.

While my inotify script really does precisely what the OP asked for, it seems to be a bit of a silly thing to ask for: one mismovement of the mouse on the desktop and you could destroy important data.

Cody Learner wrote:

Downside, this would be significantly more complicated than writing a simple script as already suggested.

It doesn't need to be.  A systemd user service and/or timer with just that find command would be very efficient.

Although keep in mind that mtime will not be the time the file was moved to the trash, but rather the last time the content of the file was modified.  So this might mean files moved to the trash might become eligible for deletion right away.  Just the same, having this on a timer script means the file will not be deleted instantly, so if you make a mistake, you can pull the file back out of the trash before it vanishes.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2018-04-18 22:48:15

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Is it possible to have a folder delete anything placed into it?

Cody Learner wrote:

Thinking the 'find -mtime XX -delete /path/to/trash' command could be useful and avoids parsing ls.

I take this approach to my ~/Downloads/ folder. Runs each night to delete downloads older than 1 week.

Offline

#12 2018-04-19 04:33:02

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: Is it possible to have a folder delete anything placed into it?

fukawi2 wrote:
Cody Learner wrote:

Thinking the 'find -mtime XX -delete /path/to/trash' command could be useful and avoids parsing ls.

I take this approach to my ~/Downloads/ folder. Runs each night to delete downloads older than 1 week.

*runs off to do this as well*


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

Board footer

Powered by FluxBB