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



## Spartrekus (May 7, 2019)

Hello

I believe that there should be no prompt confirmation y/n to move a file using mv, for instance, or to copy, to delete... using regular mv, cp and rm.

Reason because it can be an issue and best example
bsd is not like windows.

best regards
sp.


----------



## zirias@ (May 7, 2019)

There is none. You have to explicitly request this behavior with `-i`. Maybe you have an alias configured in your shell.


----------



## Spartrekus (May 7, 2019)

there should be no -i or other.

For instance,
mv freedom without popups for a terminal. one can leave this for X.


----------



## zirias@ (May 7, 2019)

So you're complaining about an optional feature that's off by default? Well then ...


----------



## SirDice (May 7, 2019)

By default it doesn't ask for confirmation. Are you suggesting the `-i` option needs to be removed? Why?


----------



## xtremae (May 7, 2019)

People seem to be oblivious to the fact that tools like mv, cp, et al. are used in production environments by scripts, automation, build systems, etc.
These flags are there so admins and devs can override default behavior for debugging purposes to solve real problems.


----------



## scottro (May 7, 2019)

As has been written above, that isn't the default behavior of mv, somehow it got configured that way on your machine. 
Secondly, if you have a disagreement with a design decision, the best place to try to get it changed would be by filing a pr, rather than mentioning it here. Though, IMHO, asking here does X or Y merit filing a pr is fine.  (And as you found by asking here, it isn't a default design decision).


----------



## Spartrekus (May 7, 2019)

SirDice said:


> By default it doesn't ask for confirmation. Are you suggesting the `-i` option needs to be removed? Why?



we talk unix or not.
if it is unix there shall be no confirmation.

mv shall have no confirmation. it is a danger for integrity of the user data and usage.


----------



## SirDice (May 7, 2019)

Spartrekus said:


> we talk unix or not.
> if it is unix there shall be no confirmation.


The confirmation question is _optional_.









						Definition of OPTIONAL
					

involving an option : not compulsory… See the full definition




					www.merriam-webster.com
				











						Definition of OPTION
					

an act of choosing; the power or right to choose : freedom of choice; a privilege of demanding fulfillment of a contract on any day within a specified time… See the full definition




					www.merriam-webster.com


----------



## zirias@ (May 7, 2019)

Which is the default behavior. Confirmation is an optional feature that must be explicitly requested on invocation. Is there anything you don't understand about that? So, what exactly is your problem?


----------



## SirDice (May 7, 2019)

Spartrekus I suggest you make your point properly and quickly. Or else I'm going to consider this whole thread a feeble trolling attempt and act accordingly.


----------



## Sevendogsbsd (May 7, 2019)

Why would we want to make a change to a tool that acts as a safeguard if the admin so chooses? As *xtremae *stated, in a production environment, there should be some safeguard in place to prevent damaging a system accidentally. If you don't what a prompt, don't enable it.


----------



## Spartrekus (May 7, 2019)

I am sorry that you don't get it. It is simple and easy to understand. Let's try to discuss together about it, it if you would like...

rm with and without -rf has a clear distinction for the usage, but it will never ask user for a confirmation. Off course, not.
This is not without an meaningful intention behind.

A SH script need to be ruled by rules, which are coherent with the all system. CP, MV or RM do no need confirmation for default copy and delete operations, right.  The shell is the backend of X, and it shall be readily operational for further advanced scripting using shell or other.

In an Unix like system, whatever it is, cp, mv and rm are the most important binaries, actually for an Unix operating system, especially BSDs which are believed to be more reliable. If you need to consider annoyance, giving high risks for file operations on large harddisks, then it will endanger the basic admin operations.

A binary such as cp, rm and mv shall never need a single confirmation by default, because it would highly endanger the operating system and user data. It should be fairly important to remove confirmations from those. It is important to do backup, copy, delete, move without any doubts that it will be unrealiable.

An override issue can be forced, but it could be left free of confirmation from the user.

Crivens
Likely you won't accept that earth is not flat... but I tried to explain you in further details. 

(Just simple understanding of Unix basics is necessary to understand the above.)


----------



## zirias@ (May 7, 2019)

You're confused. `cp`, `rm` and `mv` all have the same consistent behavior, not only on FreeBSD, but e.g. as well on GNU and probably any other UNIX-like system: 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`.


----------



## Spartrekus (May 7, 2019)

Zirias said:


> You're confused. `cp`, `rm` and `mv` all have the same consistent behavior, not only on FreeBSD, but e.g. as well on GNU and probably any other UNIX-like system: 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`.



override is an issue.


----------



## zirias@ (May 7, 2019)

It is. And this is getting ridiculous. If you think it isn't, describe exactly what you do (exact command typed) and how the outcome is not what I described above.

Just to make this as clear as possible:

`mv` will overwrite target without asking
`mv -i` will ask before overwriting
`mv -i -f` will overwrite without asking
This is *the same* behavior like rm and cp.


----------



## Spartrekus (May 7, 2019)

Zirias said:


> It is. And this is getting ridiculous. If you think it isn't, describe exactly what you do (exact command typed) and how the outcome is not what I described above.
> 
> Just to make this as clear as possible:
> 
> ...



Tell me a single good reason why it should ask ....


----------



## zirias@ (May 7, 2019)

Doing stuff _interactively_ as root on a production system? That's what `-i` stands for: _interactive_. It's recommended to configure aliases for such interactive use. If you don't like the feature, *just don't use it*.


----------



## Spartrekus (May 7, 2019)

Zirias said:


> Doing stuff _interactively_ as root on a production system? That's what `-i` stands for: _interactive_. It's recommended to configure aliases for such interactive use. If you don't like the feature, *just don't use it*.



Did you understand my above post, describing in details this?


----------



## zirias@ (May 7, 2019)

Giving up on this obvious troll ...


----------



## Spartrekus (May 7, 2019)

Zirias said:


> Giving up on this obvious troll ...



it is serious, but it demands understanding.  
You can give up, it is allowed.


----------



## Spartrekus (May 7, 2019)

I am fine with it. ok.

Why then we cannot _*override*_ ?


----------



## PMc (May 7, 2019)

Not that I would fully get the idea of the thread  (propably it's not meant to  ), but the -i has good use cases, e.g. when some files with unprintable characters have appeared and we're not certain if our glob does catch them (or might catch something else).


----------



## hukadan (May 7, 2019)

`% touch non sense
% ls
non     sense
% mv non sense
% ls
sense`
No question asked.


----------



## Spartrekus (May 7, 2019)

hukadan said:


> `% touch non sense
> % ls
> non     sense
> % mv non sense
> ...



simply try ... cd ; cp /usr/local/bin/mc . ; ./mc ; touch test ; cp test mc

got it?


----------



## Maxnix (May 7, 2019)

Spartrekus, sorry, but if you would have described your situation better we could have prevented an X-Y problem.
What you are experiencing happens when you try to write to a file when you have not writing permissions (even if you are the owner). While this is the same behaviour you get using the *-i* flag, it is not optional, and is the behaviour defined by POSIX in such cases: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/mv.html.
Moreover, specifing the *-f* flag you can override this behaviour (again, this is defined by POSIX too).


----------



## Spartrekus (May 7, 2019)

Posix is not a good reason to keep such thing, which is actually outdated. Just let it be free, libre, and have write authorization.
An operating system should have solid, reliable binaries, whatever POSIX may recommend or not. Common sense and not rules and religions.


----------



## obsigna (May 7, 2019)

Spartrekus said:


> Posix is not a good reason to keep such thing, which is actually outdated.
> An operating system should have solid, reliable binaries, whatever POSIX may recommend or not. Common sense and not rules and religions.


This turned into a ridiculous troll thread. You are trying to overwrite the binary of a running process, which has been locked by the OS because it is running. Do you want to fool us?


----------



## Spartrekus (May 7, 2019)

obsigna said:


> This turned into a ridiculous troll thread. You are trying to overwrite the binary of a running process, which has been locked by the OS because it is running. Do you want to fool us?



In any cases, a prompt for y/n can not be recommended for usage in scripts (note by default).

It is not necessary and obliged to lock it, right?

You are free to run anytime :  # rm -rf /*   which would delete all.


----------



## Maxnix (May 7, 2019)

Spartrekus said:


> An operating system should have solid, reliable binaries, whatever POSIX may recommend or not. Common sense of a programmer, not rules and religions.


It has. This is good sense. Why? Easy: because it's better to be safe than sorry. Remember that the UNIX philosophy includes choosing the more common situation as the default behaviour. How many times you will try to remove a "non-writable" file/directory? And why there are not write permissions? Probably for a good reason, that is up to the user/admin to know. It's again the "empower the user" logic, while it could not seem so. I find this invaluable in an private environment, let's figure in a production one!
Regarding to POSIX: this is not a matter of religion. It is again good sense: POSIX, SUS, were born to favorite interoperability between systems (and for the mental health of their sysadmins IMHO  ), not by caprice. "But this are rules!" - Of course. Rules, when baked by a logic, are a good thing. The page I referenced before gives you the reasons behind it.


----------



## Spartrekus (May 7, 2019)

Maxnix said:


> It has. This is good sense. Why? Easy: because it's better to be safe than sorry. Remember that the UNIX philosophy includes choosing the more common situation as the default behaviour. How many times you will try to remove a "non-writable" file/directory? And why there are not write permissions? Probably for a good reason, that is up to the user/admin to know. It's again the "empower the user" logic, while it could not seem so. I find this invaluable in an private environment, let's figure in a production one!
> Regarding to POSIX: this is not a matter of religion. It is again good sense: POSIX, SUS, were born to favorite interoperability between systems (and for the mental health of their sysadmins IMHO  ), not by caprice. "But this are rules!" - Of course. Rules, when baked by a logic, are a good thing. The page I referenced before gives you the reasons behind it.



I think that you could see that "blocking" or "preventing" is not a mean to increase safety considering rm, cp and mv. It is actually rather the opposite. A least for binaries of such importance (mv, cp, ...) and "large audience".
The Unix philosophy tends rather to go to simple solution, does the job well. A confirmation is annoyance, it can be against these principles. I am sure that I can find a good example where this confirmation can endanger the system, due to trust that OS does what you should be taking care of. What about if we change the terminal parameters... this confirmation is hence useless. Just matter of understanding what does the terminal. These files cp and mv are the foremost important components of the operating system. Therefore they should work and be reliable. BSDs want reliable base system, right.

Anyone should be allowed to override and overwrite - by default using cp and mv for programming principles.

For more fun and human, it is definitely better to be free - Isn't it written FreeBSD?  

Safety, Security,... is the job of the admin.... Likely, at least. Admin knows what is running, the risks, and what does the operating system.
Next> Next> ...Warning > Do you want to delete ? Do you really want to delete? Are you really Sure? this is Windows and annoyance.
If admin needs popups and helpful explanations, then, there is X11 applications for that, ideally suited for each of user needs.

Confirmations, or "Popups", make the operating system more unreliable especially for _cp, mv and rm.

Feel free to ask for more information. _


----------



## SirDice (May 8, 2019)

Looking at the history, the option has existed for nearly 35 years and people _expect_ it to be there. 




__





						rm
					






					www.freebsd.org
				




The rm from 4.4BSD Lite also has it: https://www.freebsd.org/cgi/man.cgi...manpath=4.4BSD+Lite2&arch=default&format=html
And it contains a nice little footnote; IEEE Std1003.2 (``POSIX'') compatible. POSIX isn't "old", it actively maintained and regularly updated. 
Here's the 2018 definition of rm: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html

I suggest you state your case on the mailing lists and perhaps submit a PR to get the option removed. You can also try and join IEEE and get the POSIX standard redefined. Until then I give you very little hope you will get this option removed.


----------



## Spartrekus (May 8, 2019)

Thank you for history and your post !
I will join the POSIX rather for more specific answer. 

It is clear that FreeBSD should follow POSIX; that's a standard.

Here typical case where override might happen by OS. it hangs due to confirmation y/n requirement (POSIX).
example:   
	
	



```
cd ; cp /usr/local/bin/mc ; screen -d -m  ./mc ;   touch foo ;   mv foo mc
```
Eventually, it could be leading to a stopped script during process, if the user programs a list of commands. In other words, some scripts might hang.

@*Maxnix*
What would you think would be the possible danger of overwritting a file on a running process, without this required confirmation ?
With an example for a better understanding.


----------



## ljboiler (May 8, 2019)

System is not required to load entire file into memory for running process when process starts.  What happens when running process needs to load more of process file into memory for later functions, and file is suddenly not available?


----------



## Spartrekus (May 8, 2019)

ljboiler said:


> System is not required to load entire file into memory for running process when process starts.  What happens when running process needs to load more of process file into memory for later functions, and file is suddenly not available?


The process is then killed and seg. fault likely.

What happen then if a running script hangs during a backup while running. Then, no completed script and no backup at all.
I would prefer that the backup runs well and that it is reliable.

In both cases, it is a data/script/process failure.


----------



## SirDice (May 8, 2019)

ljboiler said:


> System is not required to load entire file into memory for running process when process starts. What happens when running process needs to load more of process file into memory for later functions, and file is suddenly not available?


I'm not entirely sure but I suspect the file descriptor is still open so the file isn't really deleted, it's still there until all file descriptors referencing it are closed. It's the same issue with people having a filled up /var/log and removing logfiles but not restarting syslogd(8), the space is freed only if their file descriptors have been closed. Until that happens syslogd(8) will be completely oblivious and will continue to use the, now deleted, files as if nothing happened.


----------



## Spartrekus (May 8, 2019)

SirDice said:


> I'm not entirely sure but I suspect the file descriptor is still open so the file isn't really deleted, it's still there until all file descriptors referencing it are closed. It's the same issue with people having a filled up /var/log and removing logfiles but not restarting syslogd(8), the space is freed only if their file descriptors have been closed. Until that happens syslogd(8) will be completely oblivious and will continue to use the, now deleted, files as if nothing happened.



no idea about /var/log ...

For some small ps processes, it does not affect at all actually.
Like mc, you can run it in memory, midnight commander will continue to work like nothing happen, and actually mc can be replaced by anything. Just memory will let mc run like nothing happen.
If the user start this overwritten mc, then, a newer ps is created and mc (new) will run like nothing happened. Nice and the user is happy. No data loss.


----------



## PMc (May 8, 2019)

Spartrekus said:


> The process is then killed and seg. fault likely.



Nope. This would happen inside the kernel VM, so it wouldn't be a segfault, but very likely a panic. The same as you get when plugging off the disk with the swapspace -  it is technically the same, loss of disk-backed virtual memory.

But SirDice is right, the binary file is still open.



Spartrekus said:


> For some small ps processes, it does not affect at all actually.
> Like mc, you can run it in memory, midnight commander will continue to work like nothing happen, and actually mc can be replaced by anything. Just memory will let mc run like nothing happen.



Nope. There is no such thing as a process "running in memory". All memory pages in use must be disk-backed.[1] (Read Matthew Dillon's beautiful paper on the VM.) Simple reason: there can always be a process coming along with a higher priority and high memory demand, and then the stuff must be evicted.

[1] Exception is wired mem, which is not supposed to be paged out. (Thats why I don't like these incredibly high wired counts we see nowadays - they feed on system robustness.)


----------



## Spartrekus (May 8, 2019)

PMc said:


> Nope. This would happen inside the kernel VM, so it wouldn't be a segfault, but very likely a panic. The same as you get when plugging off the disk with the swapspace -  it is technically the same, loss of disk-backed virtual memory.
> 
> But SirDice is right, the binary file is still open.
> 
> ...


Thank you very much ! 

It helps a lot !


----------



## Spartrekus (May 8, 2019)

An example, little thinking...

If you open a PDF document, under Windows, then, acrobat reader (for instance) will have this opened PDF.  When you would like to write on this PDF document, it will block by the (hmm) operating system. You need then to close the process reading the PDF, in order to write and to replace the PDF by another one.

Why actually should BSDs not be the same? Actually, it should too, to be more according to data safety and similar behavior.


----------



## obsigna (May 8, 2019)

Spartrekus said:


> If you open a PDF document, under Windows, then, acrobat reader (for instance) will have this opened PDF.  When you would like to write on this PDF document, it will block by the (hmm) operating system. You need then to close the process reading the PDF, in order to write and to replace the PDF by another one.



This is actually a limitation (feature) of Windows. On macOS for example most applications are aware of externally applied changes to files they have opened, and this includes renaming, changes to the content and even deleting.

For example when I open a PDF file on the desktop in Preview, and then move the file into the trash can, then the window head immediately informs the new location. When I then empty the trash can, then Preview immediately closes the window, because the underlying document has gone and it was opened read-only. A editor leaves the document open, but when you want to save it then the editor asks for a new file name and location.

Another example. When I open the same text file in two different text editors (e.g. TextEdit.app and CotEditor.app) and then change and save text in one editor, the new text automatically and almost immediately appears in the opened text document of the other one.

Mac users expect this kind of global file state awareness. Windows users better don’t expect too much.


----------



## PMc (May 8, 2019)

obsigna said:


> Another example. When I open the same text file in two different text editors (e.g. TextEdit.app and CotEditor.app) and then change and save text in one editor, the new text automatically and almost immediately appears in the opened text document of the other one.



Yeah, they can afford this because they are running mostly single-user. On a unix, where multi-user was always the default, you would not want your editor-contents happily changing just because somebody else had edited the underlying file - you would want to get a notification and the option to save your copy somewhere else (like emacs does).


----------



## obsigna (May 9, 2019)

PMc said:


> Yeah, they can afford this because they are running mostly single-user. On a unix, where multi-user was always the default, you would not want your editor-contents happily changing just because somebody else had edited the underlying file - you would want to get a notification and the option to save your copy somewhere else (like emacs does).



This has nothing to do with single- vs. multi-user. In this respect there is no difference between macOS and FreeBSD. This has to do with system services which macOS provides as an easy API for application level programmers. The example of the OP was Acrobat Reader on Windows, so I choose similar full featured GUI applications on macOS only in order to give a counter example for a behaviour that he saw on Windows.

Now, when I open the very text file on macOS in nano, or vi, or emacs in the Mac terminal (all 3 come with macOS included and are ready to use in /usr/bin), then I don’t expect that these editors are aware of the changes which have been applied externally to any files which they have opened - of course not.


----------



## PMc (May 9, 2019)

obsigna said:


> This has nothing to do with single- vs. multi-user. In this respect there is no difference between macOS and FreeBSD.



Not _technically_. But the feature You did describe does only make sense within a single (probably graphical) user session - which is the major use-case for a MAC. My comment was about useability, not about technology.



> Now, when I open the very text file on macOS in nano, or vi, or emacs in the Mac terminal (all 3 come with macOS included and are ready to use in /usr/bin), then I don’t expect that these editors are aware of the changes which have been applied externally to any files which they have opened - of course not.



So these are not compiled with the API? *biggrin*
Indeed, as soon as I manage to find that terminal, I feel almost at home...


----------



## obsigna (May 9, 2019)

PMc said:


> Not _technically_. But the feature You did describe does only make sense within a single (probably graphical) user session - which is the major use-case for a MAC. My comment was about useability, not about technology.
> 
> 
> 
> ...



People who don’t know how to correctly spell Mac, better don’t find the Terminal.


----------



## Spartrekus (May 9, 2019)

So. then, on an Unix operating system, which possibility do we have to set or to allow file modification without notification ?  none, likely ?

override warning stops all scripts, if process is running, can it be set to let user free running his/her scripts?

This is actually  a limitation of FreeBSD, because LINUX has not such a problem.
- on FreeBSD: it hangs,
- on Linux: it works,
=> Let's be jealous of linux.


----------



## obsigna (May 9, 2019)

What’s wrong with:

`cd ; cp /usr/local/bin/mc . ; ./mc ; touch test ; echo y | mv test mc`

In a script you would add > /dev/null 2>&1 to the actual cp/mv/rm command, in order to suppress any stray y’s.


----------



## Spartrekus (May 9, 2019)

obsigna said:


> What’s wrong with:
> 
> `cd ; cp /usr/local/bin/mc . ; ./mc ; touch test ; echo y | mv test mc`



This is  a scripting workaround. 
However you can think maybe that the user would like, sometimes, to dream that his/her shell script will work without workaround - if possible. 
Likely there is another workaround is to use the Linux coreutils.


----------



## obsigna (May 9, 2019)

Are you kidding?


----------



## Spartrekus (May 9, 2019)

obsigna said:


> Are you kidding?



ok, so, I am not so sure that many users like this " echo y | mv test mc " to override the limitation, but it might be definitely a workaround.


----------



## PMc (May 9, 2019)

obsigna said:


> People who don’t know how to correctly spell Mac, better don’t find the Terminal.



Do I look like somebody who would care? I recommend these things usually for people above 85, so that figures.


----------



## hukadan (May 9, 2019)

Spartrekus said:


> I am not so sure that many users like this " echo y | mv test mc "


People even created a command to do that (yes(1)), so I think it is a rather common situation.


----------



## SirDice (May 9, 2019)

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


```
-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`.


----------



## hukadan (May 9, 2019)

SirDice said:


> No need for these ridiculous constructs.


While I agree on the mv(1) case, my remark was more general : it is not uncommon to feed *yes* to a command if there is no flag to silence the prompt.


----------



## SirDice (May 9, 2019)

hukadan said:


> it is not uncommon to feed *yes* to a command if there is no flag to silence the prompt.


That I agree with.


----------



## Spartrekus (May 9, 2019)

Sounds better indeed.

Actually to be coherent shoud it be?


```
rm -f   file
mv -f file trg
cp -f file trg
```

actually to feel really like Unix original it should be 

```
unlink  -f   file
mv -f  trg  file 
cp -f  trg   file
```

To be free and wild: 

```
unlink   file
mv  trg  file 
cp    trg   file
```


----------



## zirias@ (May 9, 2019)

You're still riding that horse? Just compare with this early answer:


Zirias said:


> […] `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 ...


----------



## SirDice (May 9, 2019)

It's even explicitly stated in the manual pages:
mv(1):

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


```
-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):

```
-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.)
```


```
-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):

```
-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.
```


```
-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".


----------



## Spartrekus (May 9, 2019)

```
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).


----------



## aragats (May 9, 2019)

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.


----------



## Spartrekus (May 9, 2019)

aragats said:


> 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.


----------



## aragats (May 9, 2019)

Spartrekus said:


> what is a bit of a lack is that the same script will run on Linux, but not on bsd


I'll have to grieve you: that script will not run on Linux on ARM! So, it's not even consistent within the same OS!


----------



## Spartrekus (May 9, 2019)

aragats said:


> I'll have to grieve you: that script will not run on Linux on ARM! So, it's not even consistent within the same OS!


thank you


----------



## Spartrekus (May 16, 2019)

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.


----------



## sidetone (May 16, 2019)

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.


----------



## mfaridi (May 16, 2019)

Do you test rsync?


----------



## Spartrekus (May 17, 2019)

mfaridi said:


> 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.


----------



## ralphbsz (May 17, 2019)

Spartrekus said:


> 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.


----------



## obsigna (May 17, 2019)

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.


----------



## aragats (May 18, 2019)

Spartrekus said:


> 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.


----------



## Spartrekus (May 18, 2019)

aragats said:


> `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_ ?


----------



## aragats (May 18, 2019)

Spartrekus said:


> why not just _cp_ ?


Indeed, why? You asked about _scp_, I replied ;-)


----------



## Spartrekus (May 19, 2019)

aragats said:


> 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:

```
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?


----------



## Spartrekus (May 19, 2019)

_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.


----------



## tedbell (May 19, 2019)

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. 
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.


----------



## tedbell (May 19, 2019)

Spartrekus said:


> 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.


----------



## Spartrekus (May 19, 2019)

tedbell said:


> 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.


This Posix sounds like an microsoft-attempt to unify and to make Unix (linux first) like windows.... systemd is an example of Redhat power to control Unix. Since Windows goes for Linux., Norms and standard can influence BSDs.

I would like to try on UNIX v.5.
Does anyone has Unix v.5. still running?

Can you try:

main(){  getchar(); }
compile,
and run it, and then  copy with cp on this runnning executable.
I am looking forward to have results of it  that will be fun.

This is more than purism, it is actually physics.
Any systems can or could evolve to increase its size and complexity. It is called non-linear dynamical systems, and mathematical modelling is possible.
There is a minimal programming trend, which allows an operating system or a software to run at full speed and efficiently.
In other words, it is better to have 10 smaller programs in Unix, rather than using a single large one. It is better to keep small programs. There is a high probability that you will always return soon or later to use again the small, efficient, program. 

Possible analogy, the less one has, the more control.




__





						Amazon.com: Minimalist Lifestyle: Rediscover Yourself and Find Freedom From Clutter (Minimalism Books, Time Managment, Values, Minimalist Living, Business) eBook : Morgan, Raymond F.P.: Kindle Store
					

Minimalist Lifestyle: Rediscover Yourself and Find Freedom From Clutter (Minimalism Books, Time Managment, Values, Minimalist Living, Business) - Kindle edition by Morgan, Raymond F.P.. Download it once and read it on your Kindle device, PC, phones or tablets. Use features like bookmarks, note...



					www.amazon.com
				




Consequently, the less popups, the more efficient BSD


----------



## fernandel (May 19, 2019)

Spartrekus said:


> I would like to try on UNIX v.5.
> Does anyone has Unix v.5. still running?


If is version 6 not to new than you can try luck on
https://github.com/yisooan/unix-v6


----------



## ralphbsz (May 19, 2019)

Spartrekus said:


> This Posix sounds like an microsoft-attempt to unify and to make Unix (linux first) like windows....


POSIX is older than Linux.  It started in the late 1980s, when the Unix market was beginning to fragment into incompatible versions.  Matter-of-fact, at that time Windows was a purely desktop operating system, and Microsoft also sold a version of Unix (it was called Xenix).  If I remember right, Xenix for a while had the largest market share of all Unixes.



> I would like to try on UNIX v.5.
> Does anyone has Unix v.5. still running?


All Unix versions from AT&T Bell Labs (formerly also known as Western Electric and a few other names) are encumbered by an AT&T copyright.  Furthermore, the original Bell Labs Unix versions only run on a PDP-11 (and I don't know which hardware models they support, not all PDPs are suitable, because they may have different memory layouts).

But fear not: Sometime in the late 90s or early 2000s, the then owner of the AT&T Unix copyright (probably SCO or Caldera or something like that) released the famous version 7 Unix, which was probably the pinnacle of a "workable" Unix version at Bell labs (stuff before was a bit too small and unstable, and afterwards the group focussed more on research topics than on usefulness and stability).  I know that it is possible to find a legally runnable version of V7 Unix, which can be run on a PDP-11.  Now, most likely, you don't have a PDP-11 (few people do), but there are emulators you can use on an x86 machine.  I know that the folks at the Computer History Museum have quite a few V7 Unix machines running on emulators, just for fun.



> Any systems can or could evolve to increase its size and complexity. It is called non-linear dynamical systems, and mathematical modelling is possible.


And now you have progressed into the realm of complete nonsense.



> There is a minimal programming trend, which allows an operating system or a software to run at full speed and efficiently.  In other words, it is better to have 10 smaller programs in Unix, rather than using a single large one.


As a general statement, this is patently untrue.  The performance and efficiency of modern CPUs is dominated by memory interfaces, cache bandwidth, and instruction scheduling.  For that you want tight inner loops, which use the (precious and small) L1 cache efficiently.  This is difficult to achieve with many processes, many address spaces, and the resulting memory fragmentation.


----------



## tedbell (May 19, 2019)

Spartrekus said:


> This Posix sounds like an microsoft-attempt to unify and to make Unix (linux first) like windows.... systemd is an example of Redhat power to control Unix. Since Windows goes for Linux., Norms and standard can influence BSDs.
> 
> I would like to try on UNIX v.5.
> Does anyone has Unix v.5. still running?
> ...



I don't understand. I tried another little C program and I was able to cp the file.


----------



## RedPhoenix (May 19, 2019)

Zirias said:


> It is. And this is getting ridiculous. If you think it isn't, describe exactly what you do (exact command typed) and how the outcome is not what I described above.
> 
> Just to make this as clear as possible:
> 
> ...


Though this Thread seems to have been started by trolling, this reply was very informative...  I never knew this about mv, thanks good sir!


----------



## Spartrekus (May 21, 2019)

tedbell said:


> I don't understand. I tried another little C program and I was able to cp the file.


do you mean that with unix v6 cp.c  you can readily copy on a running process... is that right
I could compile the unix v6 cp.c with gcc.


----------



## tedbell (May 21, 2019)

Spartrekus said:


> do you mean that with unix v6 cp.c  you can readily copy on a running process... is that right
> I could compile the unix v6 cp.c with gcc.


Ohhh. No I did it in freebsd. 
My mistake.


----------



## Spartrekus (May 21, 2019)

tedbell said:


> Ohhh. No I did it in freebsd.
> My mistake.


Originally, first K&R Unix could write on any files, using root access. Move _mv _files as well without thousand millions of popups.
I guess that this cp.c of Unix v6 differs very much from the cp.c of freebsd.
Actually, there is no protection coming from the bsd kernel while copying.

This unix v6 from above contributor is here (no override). This cp is slow, but it can copy well and sufficiently reliably (for experts only):


			https://raw.githubusercontent.com/yisooan/unix-v6/master/source/s1/cp.c
		


Feel free to give a try and experiment cp


----------



## wolffnx (May 21, 2019)

*@Spartrekus *Why dont you compile your own  modified `cp` or `mv` command?
the source is there , I think there is in 
	
	



```
/usr/src/bin/cp
```
instead of want to change the things globaly?
in some time I play with the cp source to change the order to display the name of the file that is copying BEFORE is finished to copy, is a litle detail but in Linux is like that


----------



## Spartrekus (May 21, 2019)

wolffnx said:


> *@Spartrekus *Why dont you compile your own  modified `cp` or `mv` command?
> the source is there , I think there is in
> 
> 
> ...



I am conscious about the necessity of FreeBSD to give high quality. 
Therefore it would be wise to make widely the change cp / mv to remove the cp / mv limitations.


----------



## SirDice (May 21, 2019)

Spartrekus said:


> Therefore it would be wise to make widely the change cp / mv to remove the cp / mv limitations.


I've been keeping track of this thread for a while now and I still have no clue what you mean by "limitations".


----------



## Spartrekus (May 21, 2019)

SirDice said:


> I've been keeping track of this thread for a while now and I still have no clue what you mean by "limitations".


popups and hanging scripts, crontab, backups, ... for a simple cp/mv without hacks.


----------



## hukadan (May 21, 2019)

Spartrekus said:


> cp/mv without hacks


`-f` is not a hack, it is a flag. Or may be you are against flags.


----------



## SirDice (May 21, 2019)

What popups? What hanging scripts? You mentioned that before but never showed a clear example how this is supposed to happen. So far you've only given a bunch of logical fallacies based on faulty assumptions.


----------



## Spartrekus (May 21, 2019)

the simple example:


```
mv dirent/ticalc /usr/local/bin/
override rwxr-xr-x  frodon/frodon for /usr/local/bin/ticalc? (y/n [n])
```
Command hangs, the team don't land on the moon...



SirDice said:


> What popups? What hanging scripts? You mentioned that before but never showed a clear example how this is supposed to happen. So far you've only given a bunch of logical fallacies based on faulty assumptions.



cp 13 ...
If you wanna have a flight to walk on the moon, you would like not to have failure.
That's a same with _cp_ or _mv_.

I believe that this _mv_ could be improved. what do you think?


----------



## PMc (May 21, 2019)

Never mind. They will use Windows (or Linux) for the manned Jupiter mission.

And they will run out of licence when halfway. So the much more important question is: how do you run Paypal without a licence for the OS?


----------



## Spartrekus (May 21, 2019)

PMc said:


> Never mind. They will use Windows (or Linux) for the manned Jupiter mission.
> 
> And they will run out of licence when halfway. So the much more important question is: how do you run Paypal without a licence for the OS?


Funny joke.
If Microsoft or FreeBSD cannot copy or move a file without failure, then, Android will do it ! (joke)

Fortunately or unfortunately,... Nasa will not allow manned flights, powered by Microsoft Windows.


----------



## PMc (May 21, 2019)

Spartrekus said:


> Fortunately or unfortunately,... Nasa will not allow manned flights, powered by Microsoft Windows.



What joke? Elon Musk will resettle to Mars in 2025, St.Peter's will be declared mosque in 2027, and I wanna be on the way to Jupiter by then.


----------



## SirDice (May 21, 2019)

Spartrekus said:


> Command hangs, the team don't land on the moon...


You _explicitly_ configured an alias that added the _-i_ option. If you set that option you should _expect_ that question. If you don't want to get that question then don't set the option in the first place.

This is not a _limitation_ or a _failure_. This is _expected_ behavior. Your reasoning as to why things should be overwritten, or deleted, or whatever, is fine. But your examples simply don't show why this is a problem. Or why the option should be removed.


----------



## Spartrekus (May 21, 2019)

PMc said:


> What joke? Elon Musk will resettle to Mars in 2025, St.Peter's will be declared mosque in 2027, and I wanna be on the way to Jupiter by then.



With a _ mv  _failure, you won't get your flight back to earth in any case:...



> 00:59:19,250 --> 00:59:22,187
> We've gotta transfer all control
> data over the LEM computer...



An alias is not reliable.


> 01:17:06,150 --> 01:17:08,069
> Failure is not an option.


----------



## ralphbsz (May 21, 2019)

You shot yourself in your own foot, when you configured your system to have -i as the default.  That was a bad idea.  Don't do that.  Once you do that, you can not expect scripts to continue working correctly.

Let me give you a more extreme example.  There are lots of scripts in the base OS, as shipped, that rely on the programs ls, cp and mv to function "correctly", meaning exactly as documented.  You have the freedom to reconfigure your system, and replace the ls, cp and mv binaries with a program like "fortune", which does nothing useful, and instead prints a (usually funny) message to stdout.  After you do that, your computer will probably stop working, at the latest when it tries to boot again.

What you are demanding here is: "Make the computer safe to use.  Make it so I can not do cat /usr/bin/fortune > /bin/cp.  Because if I can do it, the space ship will not reach the moon".  My answer to that is: If you want to use a computer to reach the moon, you need a reliable, and well-built system, and you need a reliable and intelligent user/administrator.  Anyone who sets global default of "-i", or replaces important binaries with the fortune cookie program, should not be involved with the space program.  (In reality, a high-reliability computer like the ones used for space flight would even have further safety measures, for example validating the checksums of installed software before liftoff.)

There are good reasons for things like the fact that you can use the ">" operator in the shell to write to files, for flags on commands, and for a file protection system that makes it so normal users can't modify system binaries or global system configuration, but root can.  Which is why there is a required minimum level of competency for people who act as root.

Old joke: To administer a computer, you need to hire a man and a dog.  The man is there to feed the dog.  The dog is there to bite the man if he tries to touch the computer.


----------



## aragats (May 22, 2019)

SirDice said:


> You _explicitly_ configured an alias that added the _-i_ option.


I don't think that's the case. By my understanding the confirmation question occurs when Spartrekus tries to mv a file over an executable when the latter is running. I confirm that, but still *-f* works.
Also, he mentioned that there is no confirmation in Linux in such cases. In general, that's not true: e.g. Debian for ARM (BBB) refuses such transactions at all (maybe because of filesystem in flash memory, not sure).


----------



## zirias@ (May 22, 2019)

Still it doesn't matter, the semantics are very clear and consistent across many *nix systems, even if _some _details (when exactly `-f` is needed) might vary slightly from system to system. Bottom line is, if you want `cp`, `mv` and `rm` to execute the action _no matter what_ (which might or might not be what you want in a script, depending on the usecase), you use `-f`. It's always been that way. A script using one of these commands without `-f` is either intended to fail on unexpected circumstances, or it is just buggy.


ralphbsz said:


> You shot yourself in your own foot, when you configured your system to have -i as the default. That was a bad idea. Don't do that.


I don't think so. A shell shouldn't expand aliases in scripts (and the shells I know don't), the aliases are for interactive use only. Setting aliases with `-i` is recommended in some places, as this flag is _intended _for interactive use. You might actually like it once it saved you from a typo, but after all, it's a personal decision 

BTW, in a script, it's good practice to use absolute pathnames, so some weird /usr/local/bin/cp (however it ended up there) doesn't break your script.


----------



## SirDice (May 22, 2019)

Spartrekus said:


> ```
> mv dirent/ticalc /usr/local/bin/
> override rwxr-xr-x frodon/frodon for /usr/local/bin/ticalc? (y/n [n])
> ```


I should have looked at the code right from the start. You only get that question if it's an interactive shell. If you use the `-i` option the question is slightly different. 

It all happens between lines 204 and 221: https://svnweb.freebsd.org/base/stable/12/bin/mv/mv.c?revision=339434&view=markup

The 25 years worth of changes to mv.c fits on a single page: https://svnweb.freebsd.org/base/head/bin/mv/mv.c?view=log

The same logic has existed since the first commit (lines 133-185): https://svnweb.freebsd.org/base/head/bin/mv/mv.c?revision=1556&view=markup



aragats said:


> Also, he mentioned that there is no confirmation in Linux in such cases. In general, that's not true: e.g. Debian for ARM (BBB) refuses such transactions at all (maybe because of filesystem in flash memory, not sure).


Not all Linux distributions are created equal. Not all of them use the GNU coreutils for cp, mv, etc. So there may be implementation differences between various Linux distributions.


----------



## Spartrekus (May 23, 2019)

SirDice said:


> I should have looked at the code right from the start. You only get that question if it's an interactive shell. If you use the `-i` option the question is slightly different.
> 
> It all happens between lines 204 and 221: https://svnweb.freebsd.org/base/stable/12/bin/mv/mv.c?revision=339434&view=markup
> 
> ...



While not having a prompt, copying protection, while overwriting a document, being read by another process? That would be consistent with other commands (and foremost how Microsoft Windows works). Which makes these mv  options not much coherent.

This is no point to have these protections, it is completely useless.
SirDice: Is there maybe something more Unix, i.e. Unix engineered by Bell lab/Gen. electr., than BSD (FreeBSD), without all those confirmation popups (needs to workaround -f and -i stuffs) for base binaries?
DragonflyBSD? I think that I will reinstall Plan9. It might be quite good alternative for making backups.

ed:
SirDice: btw, a tiny question, what does _unzip_ into the base system (nothing installed)?


----------



## SirDice (May 24, 2019)

Spartrekus said:


> Is there maybe something more Unix, i.e. Unix engineered by Bell lab/Gen. electr., than BSD (FreeBSD), without all those confirmation popups (needs to workaround -f and -i stuffs) for base binaries?


Yesterday I set up a PDP-11 with Unix v7. That was great fun. 

Install emulators/simh and follow the instructions here: http://gunkies.org/wiki/Installing_v7_on_SIMH


----------



## Spartrekus (May 25, 2019)

SirDice said:


> Yesterday I set up a PDP-11 with Unix v7. That was great fun.
> 
> Install emulators/simh and follow the instructions here: http://gunkies.org/wiki/Installing_v7_on_SIMH


you are lucky


----------



## Spartrekus (Jun 25, 2019)

I just did 
	
	



```
scp -r -C directory   192.168.25.100:/bsddrive
```
, this did not ask for a confirmation prompt when overwritting distant.

Thus to be coherent mv and cp should work the same, without forcing option.

scp is very useful, because things just work without worrying about permissions or whatever popups, warning and rings.


----------



## SirDice (Jun 25, 2019)

I suggest you ask Tatu Ylönen why there's a difference. He's the one that wrote the original SSH code from which OpenSSH was forked.


----------



## Spartrekus (Jun 25, 2019)

SirDice said:


> I suggest you ask Tatu Ylönen why there's a difference. He's the one that wrote the original SSH code from which OpenSSH was forked.



maybe interesting to have his opinion indeed.

scp and ssh is good to overwrite to bring more reliable data file transfert.
The point would maybe to look why BSD has 'y' prompt using cp and mv for base system.

Actually, originally Unix was written with cp and mv and they had no confirmation prompt.  The code of Unix v.5 of cp is very simple, readily would erase whatever and destroy the machine if bad command line.

In all cases, it is better to use a reliable cp and mv, rather than using rsync, if simple cp / mv is needed, for easy and not much demanding copy/move.


----------



## aragats (Jun 25, 2019)

The situation when the target already exists is a special case. It may not be possible to overwrite it without causing a crash – why don't you want to accept this fact?


----------



## kpedersen (Jun 25, 2019)

Spartrekus said:


> I think that I will reinstall Plan9. It might be quite good alternative for making backups.



For your ideal world; Plan 9 really could be what you want.

The original designers only made one critical mistake through its whole development; they overestimated the importance of a mouse!


----------



## Spartrekus (Jun 25, 2019)

kpedersen said:


> For your ideal world; Plan 9 really could be what you want.
> 
> The original designers only made one critical mistake through its whole development; they overestimated the importance of a mouse!


You do not need a mouse - me neither. We just need a good gamer keyboard for nice clics - 

I need Unix v.5 or an early BSD release - simple and powerful enough for CLI.
The crap is PDFLATEX that is so huge and not compilable on early BSD versions.

FreeBSD is awesome - thank you guys for your efforts - it is great


----------



## Spartrekus (Jun 25, 2019)

aragats said:


> The situation when the target already exists is a special case. It may not be possible to overwrite it without causing a crash – why don't you want to accept this fact?


there no risk of a crash - it is an utopy.  
rm -rf is also a risk.


----------

