Prompt confirmation y/n to move a file...

Guess what the -f option does; mv -f test mc. Done. No need for these ridiculous constructs.

Code:
     -f      Do not prompt for confirmation before overwriting the destination
             path.  (The -f option overrides any previous -i or -n options.)

The order of -i and -f is important. Compare mv -i -f sfile dfile and mv -f -i sfile dfile.
 
Sounds better indeed.

Actually to be coherent shoud it be?

Code:
rm -f   file
mv -f file trg
cp -f file trg

actually to feel really like Unix original it should be
Code:
unlink  -f   file
mv -f  trg  file 
cp -f  trg   file

To be free and wild:
Code:
unlink   file
mv  trg  file 
cp    trg   file
 
You're still riding that horse? Just compare with this early answer:
[…] cp, rm and mv all have the same consistent behavior […] By default, no confirmation is asked. -i requests confirmation when anything would be overwritten or deleted. -f means "do anything possible" and also overrides -i.

"do anything possible" includes e.g. overriding permissions if possible ...
 
It's even explicitly stated in the manual pages:
mv(1):
Code:
     -f      Do not prompt for confirmation before overwriting the destination
             path.  (The -f option overrides any previous -i or -n options.)
Code:
     -i      Cause mv to write a prompt to standard error before moving a file
             that would overwrite an existing file.  If the response from the
             standard input begins with the character `y' or `Y', the move is
             attempted.  (The -i option overrides any previous -f or -n
             options.)

cp(1):
Code:
     -f    For each existing destination pathname, remove it and create a new
           file, without prompting for confirmation regardless of its
           permissions.  (The -f option overrides any previous -i or -n
           options.)
Code:
     -i    Cause cp to write a prompt to the standard error output before
           copying a file that would overwrite an existing file.  If the
           response from the standard input begins with the character `y' or
           `Y', the file copy is attempted.  (The -i option overrides any
           previous -f or -n options.)

rm(1):
Code:
     -f      Attempt to remove the files without prompting for confirmation,
             regardless of the file's permissions.  If the file does not
             exist, do not display a diagnostic message or modify the exit
             status to reflect an error.  The -f option overrides any previous
             -i options.
Code:
     -i      Request confirmation before attempting to remove each file,
             regardless of the file's permissions, or whether or not the
             standard input device is a terminal.  The -i option overrides any
             previous -f options.

Note the consistent, "The X option overrides any previous Y options".
 
Code:
mv -f ... 
cp  -f   ...
rm  -f   ...
is full power in the hands.
Does the kernel is at risk if you use -f ? (see above post about kernel issue, potential risk).
 
Actually it's good if a script which is supposed to be run unattended stops working - assuming you log its output to get the info.
It will tell you that something unexpected has happened. If you don't care, just use "-f", however, you may want to add extra checks in your scripts, e.g. if [ "x`pidof mc`" = "x" ] ; ... to make sure that everything is under your control.
 
Actually it's good if a script which is supposed to be run unattended stops working - assuming you log its output to get the info.
It will tell you that something unexpected has happened. If you don't care, just use "-f", however, you may want to add extra checks in your scripts, e.g. if [ "x`pidof mc`" = "x" ] ; ... to make sure that everything is under your control.

pidof might be risk?

what is a bit of a lack is that the same script will run on Linux, but not on bsd / considering that it is starting without this -f option.
Actually, it is normal, because those are very much different operating system.
 
Does scp need also a confirmation as well, like mv and cp ?

Those security are unnecessary. This is annoying and reminds us Microsoft WIndows with millions popups.
 
If yes(1) is not your answer, I have no clue what you're asking.

yes|, then your command will insert y and execute as many times as it's asked. If there's a default that asks for confirmation, it's a safety feature, which can be overridden.
 
Do you test rsync?
thank you for rsync.
I think that it is bloated and unreliable.
I prefer low end solution, reliable and with high functionability.


By default, there should be NO CONFIRMATION, because it is a danger for the script, not the operating system.
The user or root shall know what does the cp/mv/rm file and also to rely on them.
 
thank you for rsync.
I think that it is bloated and unreliable.
Exactly which part of rsync is bloat? If you identify a part that is not useful, maybe the author would remove it.
And I disagree with calling it "unreliable". Matter-of-fact, of standalone programs that are intended to use the network as a transport mechanism, it has some of the best ways of handling network outages, restarting, and being efficient in the presence of slow or intermittent networks. It does show that the original author is really an expert in distributed and networked systems.
 
Please can we close this thread?
Obviously, the OP is a descendant of Don Quijote continuing fighting wind mills.

Given name Spatrekus, family name de la Mancha.
 
Does scp need also a confirmation as well, like mv and cp ?
scp doesn't have -a option, i.e., in particular, you'll get actual files instead of symlinks.
rsync perfectly works, but... the original question was about mv, thus those commands won't help you, since eventually you'd like to delete the source file ;-) Also, copy-and-delete is very different from move if the source and target are on the same filesystem.
 
scp doesn't have -a option, i.e., in particular, you'll get actual files instead of symlinks.
rsync perfectly works, but... the original question was about mv, thus those commands won't help you, since eventually you'd like to delete the source file ;-) Also, copy-and-delete is very different from move if the source and target are on the same filesystem.
why not just cp ?
 
Indeed, why? You asked about scp, I replied ;-)

Thank you. I will write about it, because you can see that I read it.
yeah, scp is fine for that.
I meant that we could try:
Code:
  cd ; gcc helloworld.c -o hello ; ./hello &   scp hello localhost:~/hello

Yeah, I wrote about cp, because I am worried that scripts can hang, causing possible issues or even damages for users with backups, storing data ; likely for data backups only. Actually, it is never good to replace an executable while it is running. But, well, what to do? Security/annoyance/hanging of a script or full power/risks?
 
Checked - scp has also issue.

I check SCP and if you run a executable, scp will not copy it.
The way is to delete the executable /usr/local/bin/mc (if mc is running), and then to scp again, and it will copy it since there is no file.
This POSIX is so much like windows.

Is there a BSD (Netbsd, dragonBSD, ... ) that will allow to override copying??

I like that a file operation copying and moving is just working and 100pct reliable.

Do these poups while copying are also available on Dennis Ritchie Plan9 ?
I would suspect that there is no copying protection, because this is close to Unix original.

Likely, POSIX is sort of Windows empowered thing, to make Microsoft Windows happier and more prosperous ;) Joke.
 
This whole UNIX purism seems silly to me and more a nostalgia trip than anything. It's not really pure UNIX anyway unless you're using the original version and on a terminal of the period. :D
I like the confirmation and I'm glad oh my zsh enables it. I need all the precautions I can get as careless as I am. It's a safeguard like the delete key.🤣
 
Does scp need also a confirmation as well, like mv and cp ?

Those security are unnecessary. This is annoying and reminds us Microsoft WIndows with millions popups.
I find that annoying in windows but at least you can disable it in UNIX. It's not as annoying when it's just a line in terminal.
 
Back
Top