To use the current directory as the destination directory use a single dot '
Using your example you would type:
cp ~/anotherdir/dir2/file .
To see the dot
../../ directory names in action, copy and paste the following commands into your Terminal:
mkdir a && mkdir a/b && mkdir a/b/c && mkdir a/b/c2
cp /etc/default/grub .
cp /etc/default/grub ..
cp /etc/default/grub ../c2
The output from tree command appears like this:
│ └── grub
│ └── grub
3 directories, 3 files
. at the top of tree output represents the new current directory
a which is the grandparent of
a/b/c which we navigated to using the
cd ../../ command. Underneath
a we see the sub-directories
Line by line analysis
First we created 4 directories on one line by using
&& to join multiple lines together.
Then we changed to the directory
a/b/c, which is the current directory for the following copy commands:
- In the first copy command (
cp) we set the destination to our
current directory (c) with
- In the second copy command we set the destination to the parent
directory (b) with
- In the third copy command we set the destination to the sibling
directory (c2) with
Then, as stated earlier, we changed the current directory to
a and ran the
tree command to display all directories and files under
After we are done, we remove the three directories and files with:
rm -r tree