Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Copying Single File Multiple Times into a Directory

    Hello all!

    I am fairly new to the Linux world, and in my linux class, I am working on a lab, using the Putty client...

    I am in a directory called "week8" and here is the step I'm having issues with:

    Step - Copy the file /bin/touch into this directory 3 times, each time giving the target a different name.

    I have copied files into directories before using "cp," and have been successful. So when I type "cp /bin/touch week8" it looks like it copied, but when I use "ls" to search the directory, nothing shows up.

    Am I missing something here?

    If any more information is needed, please let me know. My "teacher" says this is a fairly easy task; that is all they said when I asked for assistance.


  2. #2
    Hello and welcome!

    First off, just so you know, homework questions are against Forum Rules. However, your question is fairly basic, so I think we can help you here.

    So when you did the command "cp /bin/touch week8", did the directory "week8" already exist in the current working directory? You can confirm by just doing an "ls -l" command, while in the directory you think it is in. you should see the dir in the output, if it exists, e.g.:
    # ls -l
    drwxrwxr-x 2 root root     4096 Nov 12 22:32 week8
    Notice the "d" at the beginning of the permissions in the first column, that indicates that it is a directory.

    To list the contents of a directory in your current working dir, you can put a "./" in front of the dir you are listing (e.g., "ls ./week8"). you can further add a "/" to the end of the dir name, to force ls to look only for dirs (so it would not list a file of the name "week8", confusing you). so putting it together, you could do:
    ls -l ./week8/
    you should then get the output of the directory "week8".

    Going back to your problem, if you are already in a dir called "week8" and let us say that directory is in your home directory (i.e., /home/user/week8), and you wanted to copy something into the "week8" dir, then you'd just have to do:
    cp /some/file .
    the "." is the destination argument to cp and means "the current dir". you can always use the absolute path, too, even if you are in the dir, e.g.:
    cp /some/file /home/user/week8/
    i always add the trailing slash to a dir (i.e., week8/) just in case i make a mistake and the destination dir does not actually exist. in that case, cp will give me an error (which is what i want).

    Hopefully this helps you a little.

  3. #3
    Thank you for the quick response! Yes, this definitely helps; it appears that my syntax was incorrect.

    Thanks again!!

  4. $spacer_open
  5. #4
    Quote Originally Posted by ITstudent View Post
    Yes, this definitely helps; it appears that my syntax was incorrect.
    Great, glad you got it sorted. FYI, if the question you pose in a thread you've started is solved to your satisfaction, you can mark it as Solved using the Thread Tools link at the top of the page.

    I'll go ahead and close this one for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts