Curiosamente, parece que a resposta pode ser: "Depende".
Para ficar claro, mv é especificado para
The
mvutility shall perform actions equivalent to therename()function
A especificação de função de renomeação declara:
This
rename()function is equivalent for regular files to that defined by the ISO C standard. Its inclusion here expands that definition to include actions on directories and specifies behavior when the new parameter names a file that already exists. That specification requires that the action of the function be atomic.
Mas a mais recente a especificação ISO C para rename() afirma:
7.21.4.2 The
renamefunctionSynopsis
#include <stdio.h> int rename(const char *old, const char *new);Description
The
renamefunction causes the file whose name is the string pointed to byoldto be henceforth known by the name given by the string pointed to bynew. The file namedoldis no longer accessible by that name. If a file named by the string pointed to bynewexists prior to the call to therenamefunction, the behavior is implementation-defined.Returns
The
renamefunction returns zero if the operation succeeds, nonzero if it fails, in which case if the file existed previously it is still known by its original name.
Surpreendentemente, observe que não há exigência explícita de atomicidade. Pode ser necessário em algum outro lugar no C Standard mais recente disponível publicamente, mas não consegui encontrá-lo. Se alguém puder encontrar esse requisito, edições e comentários serão mais do que bem-vindos.
Veja também A renomeação () é atômica?
Por a página de manual do Linux :
If
newpathalready exists, it will be atomically replaced, so that there is no point at which another process attempting to accessnewpathwill find it missing. However, there will probably be a window in which botholdpathandnewpathrefer to the file being renamed.
A página man do Linux afirma que o substituto do arquivo será atômico.
Testando e verificando que a atomicidade pode ser muito difícil, se for até onde você precisa ir. Você não está claro sobre o que você quer dizer com o uso de "Como posso verificar se o mv é atômico". Você quer requisitos / especificação / documentação que é atômica, ou você precisa realmente testar isso?
Note também que os acima assumem que os nomes dos dois arquivos de operandos estão no mesmo sistema de arquivos. Não consigo encontrar nenhuma restrição padrão no utilitário mv para impor isso.