The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 90,756     Votes:  4 
Tags: bash   command-line   shortcuts   grub  
Link: 🔍 See Original Answer on Ask Ubuntu ⧉ 🔗

URL: https://askubuntu.com/q/840899
Title: Commandline shortcut for current directory similar to ~ for home directory?
ID: /2016/10/23/Commandline-shortcut-for-current-directory-similar-to-~-for-home-directory_
Created: October 23, 2016    Edited:  June 12, 2020
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


To use the current directory as the destination directory use a single dot ‘.

Long Answer

Using your example you would type: cp ~/anotherdir/dir2/file .

To see the dot ., .. and ../../ 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
cd a/b/c
cp /etc/default/grub .
cp /etc/default/grub ..
cp /etc/default/grub ../c2
cd ../../
tree

The output from tree command appears like this:

.
└── b
    ├── c
    │   └── grub
    ├── c2
    │   └── grub
    └── grub

3 directories, 3 files

The . 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 a/b, a/b/c and a/b/c2

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:

Then, as stated earlier, we changed the current directory to a and ran the tree command to display all directories and files under a.

Cleanup

After we are done, we remove the three directories and files with:

cd ~/
rm -r tree
⇧ How do I change permissions so I can edit the PAM password file? Ubuntu changing default audio output after suspend  ⇩