Is there a shortcut for unix `cp` to copy a file to the current directory with the same filename?

5

1

I'm hoping there's a shorter way of copying a file from a given directory to the current working directory than typing cp /path/to/file.txt file.txt

I tend to use this command a lot, and reiterating the file name seems... well... redundant.

blz

Posted 2012-10-17T20:49:28.960

Reputation: 413

Answers

21

"." refers to the current directory, so

cp /path/to/file .

will do what you want.

Alan Shutko

Posted 2012-10-17T20:49:28.960

Reputation: 3 698

2and don't forget the ~. It gives the users home directory. Quite convenient. – Matt H – 2012-10-17T20:52:34.760

@Alan Shutko, D'oh! I'm very much used to using .. to go up a level in the directory tree, but I never even thought about what the . could possibly mean! @Matt H, Yes, I often use ~/, but it's good to know that ~. also works! Thank you both! – blz – 2012-10-17T20:54:27.287