How can I copy a single file and maintain directory structure?
Solution 1:
cp --parents /dir/another/file /tmp
will do exactly what you want.
Solution 2:
rsync can be a good help for this :
rsync -Ravz my/first/dir/file.txt another_dir
will gave as result
another_dir/my/first/dir/file.txt
Solution 3:
You can use tar
to preserve paths while copying files:
tar cf - /dir/another/file | (cd /tmp && tar xf -)