0

I am a beginner with Ubuntu and I tried searching for an answer for this but I can't find one that covers this and I am confused by the output I am getting. I know you can use cp to copy to a parent directory by using .. or copy to your current with ., but I was trying to copy to my previous directory using - and I am getting a weird result.

cp testfile1.ogg -

This doesn't copy the file testfile1.ogg to my previous directory. It creates a file called - in my current directory. If I try

cp testfile1.ogg .. 

then this copies testfile1.ogg to the parent directory. Why does using the - shortcut not work?

  • 1
    Use the $OLDPWD environment variable that bash sets for you. - is not a shortcut for "previous directory", it is often used for STDOUT, but that's a per-command choice, check the man page for the command. – waltinator Sep 16 '23 at 16:31
  • Ok. Thank you. I was thinking I could use - since cd - would take me to the previous directory. Any idea why Ubuntu creates a file called - in my current directory. That seems weird since I am using the cp command and since I used the - it ignores the file I tried to copy and instead creates a file called - – Dean Cole Sep 16 '23 at 16:47
  • It copied the file you told it to copy to a file named - – muru Sep 16 '23 at 22:19
  • Oh. That makes sense. I was looking at this completely wrong. Thanks!! – Dean Cole Sep 17 '23 at 17:10

0 Answers0