Why isn't this sudo mv operation with wildcard working?
It's almost certainly due to the fact that your ordinary user account cannot access the directory, so the shell cannot enumerate the files that would match the wildcard.
You can confirm this easily enough with a command like this
ls /home/jira-plugins/installed-plugins
If you get a permission denied then there is no way the shell is going to be able to expand a *
wildcard in that directory.
Why? Consider your command
sudo mv /home/jira-plugins/installed-plugins/* /var/atlassian/application-data/jira/plugins/installed-plugins/
The order of processing is (1) expand the wildcards, (2) execute the command, which in this case is sudo
with some arguments that happen to correspond to a mv
statement.
You can solve the problem in one of two ways
Become root and then move the files
sudo -s mv /home/jira-plugins/installed-plugins/* /var/atlassian/application-data/jira/plugins/installed-plugins/
Expand the wildcard after running
sudo
sudo bash -c "mv /home/jira-plugins/installed-plugins/* /var/atlassian/application-data/jira/plugins/installed-plugins/"
As you do sudo ls
to list the folder, I assume one or more directories in the path are unreadable by regular users. That would explain the behaviour. The key misunderstanding here is when glob expansion of the *
is done. It is done by the shell, before invoking any command. If the shell does not have permissions enough, it can not expand it.
What happens in this case in more detail is:
- Your shell tries to expand the command line. Since you do not have the right to read
/home/jira-plugins/installed-plugins
as yourself, it will not be able to expand the glob pattern/home/jira-plugins/installed-plugins/*
. It will leave it unmodified. After this stage,*
is no longer special. - Your shell invokes the command
sudo
with the argumentsmv
/home/jira-plugins/installed-plugins/*
, and/var/atlassian/application-data/jira/plugins/installed-plugins/
sudo
invokesmv
with the arguments/home/jira-plugins/installed-plugins/*
, and/var/atlassian/application-data/jira/plugins/installed-plugins/
mv
tries to move a file actually named/home/jira-plugins/installed-plugins/*
, but it doesn't exist and thus the error message.