rm non-permanent delete

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
COKEDUDE

rm non-permanent delete

Post by COKEDUDE »

I read this article as a way to do a non-permanent of something.

I saw 2 problems. The first that my rm is located at /bin/rm. I would assume I would change the location to /bin/rm. The second my rm is a executable file and not a text file. So will replacing my rm file with the shellscript below work? I would think they would need to be the same type of files.
As far as how to make stuff go to the trash instead of deleted, run this as root:

Code: Select all

mv /usr/bin/rm /usr/bin/rm.bak
Now copy this script and save it as /usr/bin/rm:

Code: Select all

#!/bin/bash

mkdir ~/.Trash &> /dev/null

while [ ! -z "$1" ]; do
    mv "$1" ~/.Trash/
    shift
done
This will, instead of deleting files, move them to the .Trash directory in your home directory, and you can delete them for real later.
http://www.linuxforums.org/forum/364949-post2.html
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
randomizer

Re: rm non-permanent delete

Post by randomizer »

You'll need to run this as well:

Code: Select all

chmod +x /bin/rm
This makes the script executable.
piquat

Re: rm non-permanent delete

Post by piquat »

Could you also have created an alias like rmn (for non-perm) and made that execute your script, thereby saving the original rm in case you want to use it to?
randomizer

Re: rm non-permanent delete

Post by randomizer »

That's probably a better idea. You'd just have to make sure you don't type the wrong one by accident ;) Then again, there's nothing stopping you from using /bin/rm.bak just as you would /bin/rm.
COKEDUDE

Re: rm non-permanent delete

Post by COKEDUDE »

piquat wrote:Could you also have created an alias like rmn (for non-perm) and made that execute your script, thereby saving the original rm in case you want to use it to?
Could you explain how to do that please? I am not familiar with using aliases.
libssd
Level 4
Level 4
Posts: 288
Joined: Tue Jun 22, 2010 11:26 am

Re: rm non-permanent delete

Post by libssd »

Answers here: http://forums.linuxmint.com/viewtopic.php?f=46&t=40582

You can create aliases on the fly, but they won't survive a terminal session; to make them permanent, you need to add them to (I think it's the same in Mint as in Ubuntu) .bashrc, which just happens to be filled with lots of alias examples. The .bashrc file should be in your home directory.
COKEDUDE

Re: rm non-permanent delete

Post by COKEDUDE »

This works good :).

Code: Select all

alias rmdi="rm -ri"
randomizer

Re: rm non-permanent delete

Post by randomizer »

That does exactly the same as "rm -r" except that it will bug you about every single file it wants to delete.
Locked

Return to “Software & Applications”