Search code examples
linuxterminalmvsles

Why is the 'mv' command not working when moving a file up multiple levels


Operating system: SLES12 VM

So I start off in a directory: DirA: /home/user/testA/testB

My goal is to move a file from this directory to a directory given by DirB_rel: /home/user/testA/testB/../../deliverables/rpm/SOURCE

Note: testA is a symlink which is not included in DirB_abs

Which, when I cd to it, gives a pwd of DirB_abs:/home/user/deliverables/rpm/SOURCE

The problem is, when I try move a file using mv (have tried tar.gz and .txt) from DirA to DirB_rel, the file is deleted from original location as expected, but it does not appear at new location and is therefore lost.

E.g. mv testFile.txt DirB_rel -> File disappears

However, when I use the absolute path for directory B, mv works correctly.

E.g. mv testFile.txt DirB_abs -> Success

Any idea whats going on here?

Thanks!


Solution

  • The problem is with the symlink. When you do user/testA/testB/../../ and testA is asymlink, you wont go back to user, but to the parent directory of the directory testA links to