Ok I now understand better why this happens.
I've also performed this operation on my Ubuntu test server which worked without issues:
Code:
root@10-2-32-173:~# head -2 /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
root@10-2-32-173:/var/cpanel# mv -v hostname_cert_csrs{,.cPbak}
renamed 'hostname_cert_csrs' -> 'hostname_cert_csrs.cPbak'
I then added 100 files to this directory to make it not empty:
Code:
root@10-2-32-173:/var/cpanel# find hostname_cert_csrs.cPbak/ -type f | wc -l
100
After doing this I recreated the hostname_cert_csrs directory, populated it with a number of empty files, and upon trying to move the directory at this time the error was populated:
Code:
root@10-2-32-173:/var/cpanel# mkdir hostname_cert_csrs
root@10-2-32-173:/var/cpanel# touch hostname_cert_csrs/{1..1000}
root@10-2-32-173:/var/cpanel# find hostname_cert_csrs -type f | wc -l
1000
Code:
root@10-2-32-173:/var/cpanel# mv -v hostname_cert_csrs{,.cPbak}
mv: cannot move 'hostname_cert_csrs' to 'hostname_cert_csrs.cPbak/hostname_cert_csrs': Directory not empty
- In the future to prevent this type of issue you can remove the old directory, or when renaming the directory give it another name.
so when i was trying
mv /var/cpanel/hostname_cert_csrs{,.cpbkp} -v
it already had a backup of cpbkp
so i could remove it or rename it to
mv /var/cpanel/hostname_cert_csrs{,.cpbkp1} -v
then it will work. makes sense- duh .... I'm so slow sometimes.
I do want to address why -b worked, The -b flag is 'backup' that creates a backup of the destination prior to overwriting.
You could either change the name of the backup directory that was created. as you showed, and then run the original command.
mv -v /var/cpanel/hostname_cert_csrs.cpbkp /var/cpanel/hostname_cert_csrs.cpbkup.1
or, while running the initial mv command, to change the name of the backup being created by incrementing numbers prior to the curly closing bracket as shown below:
mv -v /var/cpanel/hostname_cert_csrs{,.cPbak2}
An example showing this work is below:
Code:
root@10-2-32-173:/var/cpanel# mv /var/cpanel/hostname_cert_csrs{,.cPbak}
mv: cannot move '/var/cpanel/hostname_cert_csrs' to '/var/cpanel/hostname_cert_csrs.cPbak/hostname_cert_csrs': Directory not empty
Code:
root@10-2-32-173:/var/cpanel# mv -v /var/cpanel/hostname_cert_csrs{,.cPbak2}
renamed '/var/cpanel/hostname_cert_csrs' -> '/var/cpanel/hostname_cert_csrs.cPbak2'
ok just incase someone else needs this information im posting it here as well
SOLVED.. thank you
@cPRex for dealing with all my questions
Kind Regards,
Spiro