0

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!

mgibson
  • 6,103
  • 4
  • 34
  • 49
  • 4
    protip: if you move a file to a directory, always use a trailing slash: `mv myfile mydir/` , such that if mydir does not exist, you get an error message instead of mydir being created *as a file* (the same if mydir does exist but *as a file* in which case the result will be even more disastreous) – joop Oct 26 '15 at 18:38
  • do you have some symbolic links somewhere it the path? – Nir Levy Oct 26 '15 at 21:25
  • @Nir Levy: Yes, testA (included in DirB_rel, the one I cannot move the file to) is a symlink. Is that a problem? – mgibson Oct 27 '15 at 10:37

2 Answers2

0

the mv command will reference the directory you are currently in and not from where the file is. So if we are in home ~/ and want to move ~/A/file to ~/B/file you use mv as follows:

mv A/file B/

Note that if you use this

mv A/file ../B/

the command will look for B in /home/B and not ~/B since we are in the ~/ directory issuing the command.

madmanali93
  • 273
  • 2
  • 12
  • Hopefully this answers your question if not then if you could rephrase your question because it is a bit confusing. – madmanali93 Oct 26 '15 at 21:35
  • Thanks, I am aware of this though. The makefile I am using, is trying to `mv` a file to from current directory to DirB_abs but uses DirB_rel to achieve this. In my mind, they should be the same, although testA is a symlink. – mgibson Oct 27 '15 at 10:44
0

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

Nir Levy
  • 12,750
  • 3
  • 21
  • 38