Bash script to empty HUGE Trash Can? [Solved]

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Niely

Bash script to empty HUGE Trash Can? [Solved]

Post by Niely »

Hello

I've got a small problem.
Somehow I got so amazingly much files in my Trash Can that it's impossible to delete them all in once.
The delete trash-can command also doesn't work, if I try to delete a few; my PC just stucks.

So, I need a Bash snippet which will delete ONE file at a time from my Trash Can, with a timeout of 1 second.
That way my RAM doesn't get overloaded and after letting it running a night the job will be done. :)

So, any Bash script that can do this?

Thanks for reading,
Niely
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
kyphi
Level 9
Level 9
Posts: 2735
Joined: Sat Jul 09, 2011 1:14 am
Location: The Hunter Valley, Australia

Re: Bash script to empty HUGE Trash Can?

Post by kyphi »

Why not use this command:

Code: Select all

sudo rm -rf ~/.local/share/Trash/files/*
Linux Mint 21.3 Cinnamon
Niely

Re: Bash script to empty HUGE Trash Can?

Post by Niely »

Like I said it doesn't work. It must one by one with a time-span of one second.
That command just ends in terminal, but doesn't delete anything.
Niely

Re: Bash script to empty HUGE Trash Can?

Post by Niely »

^Thanks a lot! Exactly what I needed and it's very useful + helpful.
tadaensylvermane
Level 2
Level 2
Posts: 88
Joined: Tue Jun 25, 2013 8:50 pm

Re: Bash script to empty HUGE Trash Can? [Solved]

Post by tadaensylvermane »

just for reference a for loop would be the way to get 1 file every second, at least is how i would do it...

Code: Select all

for i in ~/.local/share/Trash/files/* ; do
  rm -rf "$i"
  sleep 1
done
Locked

Return to “Scripts & Bash”