0

What does the command cp $1/. $2 do? I know cp is used for copying from source(stored in variable $1) to destination(stored in variable $2). I am just confused with the /. used along with the variable. Can someone please help me understand this?

1 Answer 1

1

The command:

$ cp -R $1/. $2

copies contents of directory pointed by $1 to the directory $2.

Without -R switch this command would fail both when $1 is a file or directory.

In general, . points to the current directory. You can see that by comparing inode's shown by ls:

$ mkdir test
$ ls -ali
9525121 drwxr-xr-x   3 IU    wheel  102 23 mar 12:31 .
 771046 drwxrwxrwt  21 root  wheel  714 23 mar 12:30 ..
9525312 drwxr-xr-x   2 IU    wheel   68 23 mar 12:31 test

$ cd test
$ ls -ali
9525312 drwxr-xr-x  2 IU  wheel   68 23 mar 12:31 .
9525121 drwxr-xr-x  3 IU  wheel  102 23 mar 12:31 ..

Note that inode 9525312 points to test when viewed from the parent directory, and points to . when viewed from inside the test directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.