In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it possible?
My temporary solution is to use /tmp
as a temporary place to store a copy of the file. cp myfile /tmp
when I am in the first directory, and then cp /tmp/myfile .
when I am in the second directory. But I may check if the file will overwrite anything in /tmp
.
Is there something similar to a clipboard for copying and pasting a file?
Using Bash, I would just visit the directories:
$ cd /path/to/source/directory
$ cd /path/to/destination/directory
Then, I would use the shortcut ~-
, which points to the previous directory:
$ cp -v ~-/file1.txt .
$ cp -v ~-/file2.txt .
$ cp -v ~-/file3.txt .
If one wants to visit directories in reverse order, then:
$ cp -v fileA.txt ~-
$ cp -v fileB.txt ~-
$ cp -v fileC.txt ~-
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments