Ubuntu – Commandline shortcut for current directory similar to ~ for home directory

bashcommand lineshortcuts

When i use the cp or move command in a terminal window,
i'm currently with bash in a certain folder like this.

NES@server:~/Desktop/dir1$

And now i wanna copy a file from here ~/anotherdir/dir2 into the current
chosen folder in bash (dir1) i would use the command

cp ~/anotherdir/dir2/file ~/Desktop/dir1

does a shortcut string exist to refer to the current chosen directory?
So that in this example i don't have to provide the full path to the target dir, but
the command knows it should use the current chosen directory in bash?
i.e. as ~ stands for the home directory?

Best Answer

Your current directory is . . So, cp /foo/fam/foo . copies the file to your current directory.

The analogous construction for "one directory up," or the parent directory of your current working directory, is two dots, i.e., .. . (Thanks @djeikyb .)

So, from /usr/house/firstfloor/basement , cd .. takes you one level up to /usr/house/firstfloor.

In the same example (starting from /usr/house/firstfloor/basement, the command cd ../.. would take you to /usr/house .

You can also use $PWD with echo to get your current directory:

echo $PWD

Incidentally, $OLDPWD will give you your previous directory. (Which in bash you can also reach by typing cd - .)