Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ahh what a day! bash and aliases

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
shifty_ben
LXF regular


Joined: Tue Oct 04, 2005 10:56 am
Posts: 1292
Location: Ipswich

PostPosted: Sun Feb 26, 2006 12:52 am    Post subject: Ahh what a day! bash and aliases Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Nigel
LXF regular


Joined: Fri Apr 08, 2005 9:03 pm
Posts: 1141
Location: Gloucestershire, UK

PostPosted: Sun Feb 26, 2006 1:26 am    Post subject: RE: Ahh what a day! bash and aliases Reply with quote

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
View user's profile Send private message
shifty_ben
LXF regular


Joined: Tue Oct 04, 2005 10:56 am
Posts: 1292
Location: Ipswich

PostPosted: Sun Feb 26, 2006 11:36 am    Post subject: RE: Ahh what a day! bash and aliases Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
jhooks



Joined: Sat Jan 07, 2006 5:39 pm
Posts: 48

PostPosted: Tue Mar 28, 2006 3:15 pm    Post subject: RE: Ahh what a day! bash and aliases Reply with quote

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
View user's profile Send private message
jhooks



Joined: Sat Jan 07, 2006 5:39 pm
Posts: 48

PostPosted: Tue Mar 28, 2006 3:26 pm    Post subject: RE: Ahh what a day! bash and aliases Reply with quote

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
View user's profile Send private message
shifty_ben
LXF regular


Joined: Tue Oct 04, 2005 10:56 am
Posts: 1292
Location: Ipswich

PostPosted: Tue Mar 28, 2006 3:31 pm    Post subject: RE: Ahh what a day! bash and aliases Reply with quote

Cheers for the suggestions Very Happy 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 user's profile Send private message Visit poster's website MSN Messenger
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast