~USER
is just a shorthand notation for the home directory of user USER
. For a normal user, this would typically be /home/USER
, but for root, it is typically /root
.
As for your question whether one is preferable to the other: The only difference is that ~root
gets expanded dynamically to root's home directory, whereas /root
is an absolute path that does not undergo any expansion process. What you want depends on your particular use case. If you want your script to work on machines where root's home directory lies elsewhere than in /root
, then use ~root
. If you want to make sure that the absolute path /root
is always used, use /root
.
In practice, it should not make any difference in most cases, though I would personally feel safer using /root
unless I have reason to expect that my script will be run on machines where root's home directory is not /root
.