I've been researching this problem for days, and have gotten no luck . =/
How do you copy a file to another directory without being in the same directory as the file? So, for example, say I wanted to copy the file 'my.txt' that is in the directory ' /export/hom0/user/asdf ' to the directory ' /export/hom0/user/abcd '. without actually being in the directory ' /asdf '. I know this sounds a little confusing, but it has something to do with the 'cp' command.
A file xxx.yyy is called an entry name, because it goes in an entry of a parent directory. It has a full or absolute path of: $PWD/xxx.yyy
A file zzz/xxx.yyy is called a relative path, because it has directories but is still relative to the current working dir $PWD that the process is sitting in: $PWD/zzz/xxx.yyy, which is a blessing or curse depending on what you need. It is great for portability between users or environments like developement, test, production on the same host.
Any file path starting in / is absolute or full. Using them means that what happens is not dependent on $PWD, which is again a blessing or curse depending on what you need. Only one file or device can have that path.
I like you answer very much! You beat me here...
I tried hard not to give a straight solution not knowing if this (looks very much like) is homework but to help the person to search using some deduction... Your explanation on PWD is quite challenging for someone wanting effortless solution to be given...
I am intrigued that nobody has posted a correct solution or a correct hint so far.
Hint: You are allowed to use the absolute path name to a file in a unix "cp" command in either the source filename or the destination filename ... or both.
This will work anywhere, and ensures that the target is an existing directory, by globbing with a trailing slash. If the target was missing or a file, it would be created or overwritten, respectively. The scp/scp2 commands have a -d option to demand that the target be a directory, for safety.