It didn't change the parent directory. It change the current directory. You can clearly see ./
in the output, which is /home/ubuntu
from the command you ran, and that directory got modified.
If you don't want the current working directory to be modified, you shouldn't be extracting .
. Maybe instead extract just the deploy
directory:
sudo -u ubuntu tar -xzf tar.tgz -C "$(dirname "/home/ubuntu/deploy/")" ./deploy
I can't reproduce this in an 18.04 Docker container (it behaved like you say 22.04 does), so I think your tar file was simply different in your 18.04 deployment.
There is a difference between these two ways of creating tar files in a directory containing a deploy
directory:
tar cvf foo.tar ./deploy
tar cvf foo.tar .
The latter will contain an entry for ./
with the permissions of the current working directory in which it was ran. For example, the first command will result in:
% tar tvf foo.tar
drwxr-xr-x muru/muru 0 2023-03-22 14:46 ./deploy/
-rw-r--r-- muru/muru 0 2023-03-22 14:46 ./deploy/foo
vs. the following for the second command:
# tar tvf foo.tar
drwxr-xr-x muru/muru 0 2023-03-22 05:57 ./
drwxr-xr-x muru/muru 0 2023-03-22 05:46 ./deploy/
-rw-r--r-- muru/muru 0 2023-03-22 05:46 ./deploy/foo
When extracting, the latter will update the permissions of whichever directory it was in to the stored permissions. It's likely your tar file was created like the first one in 18.04 and like the second one in 22.04.