Chapter 10
Copy A File (cp)

10.1 Do This


Source 17: Linux/Mac OSX Exercise 10
  $ cd temp
  $ cp iamcool.txt neat.txt
  $ ls
  iamcool.txt neat.txt
  $ cp neat.txt awesome.txt
  $ ls
  awesome.txt iamcool.txt neat.txt
  $ cp awesome.txt thefourthfile.txt
  $ ls
  awesome.txt iamcool.txt neat.txt thefourthfile.txt
  $ mkdir something
  $ cp awesome.txt something/
  $ ls
  awesome.txt iamcool.txt neat.txt something thefourthfile.txt
  $ ls something/
  awesome.txt
  $ cp -r something newplace
  $ ls newplace/
  awesome.txt
  $


Source 18: Windows Exercise 10
  > cd temp
  > cp iamcool.txt neat.txt
  > ls
  
  
      Directory: C:\Users\zed\temp
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -a---        12/22/2011   4:49 PM          0 iamcool.txt
  -a---        12/22/2011   4:49 PM          0 neat.txt
  
  
  > cp neat.txt awesome.txt
  > ls
  
  
      Directory: C:\Users\zed\temp
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -a---        12/22/2011   4:49 PM          0 awesome.txt
  -a---        12/22/2011   4:49 PM          0 iamcool.txt
  -a---        12/22/2011   4:49 PM          0 neat.txt
  
  
  > cp awesome.txt thefourthfile.txt
  > ls
  
  
      Directory: C:\Users\zed\temp
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -a---        12/22/2011   4:49 PM          0 awesome.txt
  -a---        12/22/2011   4:49 PM          0 iamcool.txt
  -a---        12/22/2011   4:49 PM          0 neat.txt
  -a---        12/22/2011   4:49 PM          0 thefourthfile.txt
  
  
  > mkdir something
  
  
      Directory: C:\Users\zed\temp
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/22/2011   4:52 PM            something
  
  
  > cp awesome.txt something/
  > ls
  
  
      Directory: C:\Users\zed\temp
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/22/2011   4:52 PM            something
  -a---        12/22/2011   4:49 PM          0 awesome.txt
  -a---        12/22/2011   4:49 PM          0 iamcool.txt
  -a---        12/22/2011   4:49 PM          0 neat.txt
  -a---        12/22/2011   4:49 PM          0 thefourthfile.txt
  
  
  > ls something
  
  
      Directory: C:\Users\zed\temp\something
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -a---        12/22/2011   4:49 PM          0 awesome.txt
  
  
  > cp -recurse something newplace
  > ls newplace
  
  
      Directory: C:\Users\zed\temp\newplace
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -a---        12/22/2011   4:49 PM          0 awesome.txt
  
  >

10.2 You Learned This

Now you can copy files. It's simple to just take a file and copy it to a new one. In this exercise I also make a new directory and copy a file into that directory.

I'm going to tell you a secret about programmers and system administrators now. They are lazy. I'm lazy. My friends are lazy. That's why we use computers. We like to make computers do boring things for us. In the exercises so far you have been typing repetitive boring commands so that you can learn them, but usually it's not like this. Usually if you find yourself doing something boring and repetitive there's probably a programmer who has figured out how to make it easier. You just don't know about it.

The other thing about programmers is they aren't nearly as clever as you think. If you overthink what to type, then you'll probably get it wrong. Instead, try to imagine what the name of a command is to you and try it. Chances are that it's a name or some abbreviation similar to what you thought it was. If you still can't figure it out intuitively, then ask around and search online. Hopefully it's not something really stupid like ROBOCOPY.

10.3 Do More

  1. Use the cp -r command to copy more directories with files in them.
  2. Copy a file to your home directory or desktop.
  3. Find these files in your graphical user interface and open them in a text editor.
  4. Notice how sometimes I put a / (slash) at the end of a directory? That makes sure the file is really a directory, so if the directory doesn't exist I'll get an error.


Online Video Course + PDF For $9

For the price of most other course's PDFs only, you can get the full PDF for this class and 2 videos demonstrating the whole book for both Unix/OSX Terminal and Windows PowerShell. The course is self-paced so you can go through it any time you want, as many times as you want.


Signup Now At Udemy.com For $9