Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Watch out for mv command and symlinks on Samba shares' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Watch out for mv command and symlinks on Samba shares
Authored by: rtl on Nov 06, '03 12:18:25PM
This example is equivalent to issuing the command mv foo foo with a file named foo in the current directory, i.e. you're overwriting a file with itself. On a local HFS+ or UFS filesystem, this really shouldn't cause any harm, but it looks like the poster has discovered that this isn't a safe operation on a windows share. This is probably a bug that should be reported to Apple - the rename operation is probably being translated into the wrong sequence of smb operations.

Until this is fixed, you can help prevent it in the future by aliasing mv to mv -i, which gives you an "are you sure?" prompt before any potentially destructive operations. You might also consider doing the same for the cp and rm commands. In order to add such aliases to your environment, add these lines to your .tcshrc file if you are using tcsh:

  alias rm 'rm -i'
  alias mv 'mv -i'
  alias cp 'cp -i'

For bash, add this to your .bashrc:

  alias rm='rm -i'
  alias mv='mv -i'
  alias cp='cp -i'

These have been mentioned in several comments in the past, but seemingly never as a hint. Does one the of the Mac OS X bibles have a section on well-known UNIX shell additives that would be useful to newbies?

[ Reply to This | # ]

Watch out for mv command and symlinks on Samba shares
Authored by: ahbe on Nov 06, '03 12:57:39PM
Small correction, use .profile in the root of your home directory, not .bashrc Than make sure you shutdown that terminal session and start again. It should work now. BTW, I believe this is standard operation with the mv command, at least in Linux that's how it works. That is why the "-i" option exists, to warn you. Normally what you say is what it does. Be careful with the command line. On at least two occasions, I did a "rm -r *" thinking I was in the "/tmp" directory, when I was actually at the root while logged on as root. By the time you realize what you just did, its to late. Be careful!

[ Reply to This | # ]
root implies being careful
Authored by: hayne on Nov 06, '03 02:10:20PM
On at least two occasions, I did a "rm -r *" thinking I was in the "/tmp" directory, when I was actually at the root while logged on as root.
This would seem to indicate that you should not log on as root.

[ Reply to This | # ]
root implies being careful
Authored by: bluehz on Nov 06, '03 07:38:32PM

Actually this happened to me the other day while connected smb to my linux box. I deleted a symlink file toa dir in the Finder and it deleted the actual dir. Luckily it wasn't anything important.



[ Reply to This | # ]
Watch out for mv command and symlinks on Samba shares
Authored by: jimhill on Nov 06, '03 12:59:06PM

No, NO, NO!!!!

Do not alias system commands! I can't repeat that strongly enough. If you want the system to hold your hand with "-i" flags, then for the love of God use aliases like "rmi", "cpi", and "mvi". Because if you don't, you _will_ find yourself working on another machine or another account and you'll blow your feet off with no safety net.

Rob -- it would be a grievous error on your part to include "use alias rm 'rm -i'" in any hint. Ever.


---
Mac OS X: Because making UNIX simple is easier than debugging Windows.



[ Reply to This | # ]