| View previous topic :: View next topic |
| Author |
Message |
shifty_ben LXF regular

Joined: Tue Oct 04, 2005 10:56 am Posts: 1292 Location: Ipswich
|
Posted: Sun Feb 26, 2006 12:52 am Post subject: Ahh what a day! bash and aliases |
|
|
Hi all,
having just spent the best part of three hours recovering deleted inodes after a very badly placed space, I think its time I set up an alias for rm. Although there are a lot of other users that remotely log into my webserver I think it is probably as much for me as anyone else. What I want to do is move any 'deleted# files to a folder in /var lets call it /var/deleted then I will set up a cron job to clear this every 7 days or so.
I was going to add this to my /etc/profile
alias rm="mv /var/deleted"
but then it occurred to me if I do that, then it will in effect be the user typing
mv /var/deleted foo.txt
which isn`t what I want, it may be because its late but I cant for the life of me think of how to enter it so it works in the way I want to, any help will be much appreciated
Thanks
Ben _________________ Need a New Signature |
|
| Back to top |
|
 |
Nigel LXF regular

Joined: Fri Apr 08, 2005 9:03 pm Posts: 1141 Location: Gloucestershire, UK
|
Posted: Sun Feb 26, 2006 1:26 am Post subject: RE: Ahh what a day! bash and aliases |
|
|
I guess the best way would be to set up a bash script that cycles through it's arguments moving them to /var/deleted, then alias that script to rm.
That would take care of the case where you type
rm foo.txt bar.doc old/*.junk
You would have to have something that removed parameters (eg -i), or better yet did something appropriate with them. _________________ Hope this helps,
Nigel. |
|
| Back to top |
|
 |
shifty_ben LXF regular

Joined: Tue Oct 04, 2005 10:56 am Posts: 1292 Location: Ipswich
|
Posted: Sun Feb 26, 2006 11:36 am Post subject: RE: Ahh what a day! bash and aliases |
|
|
Kool cheers, Im going to see if I can put something together tomorrow, 9 weeks of straight work and then the stress of that last night have left me rather knackered.
Damn my fat fingers! _________________ Need a New Signature |
|
| Back to top |
|
 |
jhooks
Joined: Sat Jan 07, 2006 5:39 pm Posts: 48
|
Posted: Tue Mar 28, 2006 3:15 pm Post subject: RE: Ahh what a day! bash and aliases |
|
|
If it were me, I would want so way of dealing with multiple files of the same name. Perhaps a simple way to do it would be to have get the full path for the file(s) to be deleted so that when you did
'rm ~/file.txt' in '/home/user'
it ra
'mkdir -p /var/deleted/home/user/; mv /home/user/somefile.txt /var/deleted/home/user/file.txt'
Perhaps you would want some way to keep multiple deleted copies of the same file. You could append a timestamp to the end of each file or even better move it to a folder which was timestamped. E.g. 'timestamp=$(date +%Y%m%d%H%M%S\-%N); mkdir -p /var/deleted/$timestamp/home/user/; mv /home/user/somefile.txt /var/deleted/$timestamp/home/user/file.txt'
Anyway have fun. |
|
| Back to top |
|
 |
jhooks
Joined: Sat Jan 07, 2006 5:39 pm Posts: 48
|
Posted: Tue Mar 28, 2006 3:26 pm Post subject: RE: Ahh what a day! bash and aliases |
|
|
| I forgot to mention. mv and cp can both overwrite files, perhaps you should alias them to scripts that can determine when files will be overwritten so that they also an go to a "recycle bin". |
|
| Back to top |
|
 |
shifty_ben LXF regular

Joined: Tue Oct 04, 2005 10:56 am Posts: 1292 Location: Ipswich
|
Posted: Tue Mar 28, 2006 3:31 pm Post subject: RE: Ahh what a day! bash and aliases |
|
|
Cheers for the suggestions Ive taken a different approach and made and alias for rm which leads to rm -i that should be enough to prevent to many issues. I make nightly backups now so if anything does go its not the end of the world _________________ Need a New Signature |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|