Find the answer to your Linux question:
Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Cabhan
I made a folder named "test" on my desktop. After that I wanted to do txt file in it, so I did Code: cp test.txt test/test2.txt /home/hunti/Desktop and I get ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2

    terminal "cp" problem


    I made a folder named "test" on my desktop. After that I wanted to do txt file in it, so I did
    Code:
    cp test.txt test/test2.txt /home/hunti/Desktop
    and I get error
    Code:
    cp: cannot stat `test.txt': No such file or directory
    cp: cannot stat `test/test2.txt': No such file or directory
    I also tryd
    Code:
    hunti@hunti-Aspire-M7720:~/Desktop$ cp test test/test2.txt
    and get error
    Code:
    cp: omitting directory `test'
    And still see no txt file in my test map. I try'd the help of cp manpage and help but nothing helped me with this.

    What am I doing wrong??

    Thanks

  2. #2
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,488
    Let's start from the beginning with the directory creation.
    Code:
    mkdir test-directory
    Now to create some test files. There are many many fine ways to do this and these are just a couple.
    Code:
    touch testfile-1
    ls -al > testfile-2
    So to copy testfile-1 into our test-directory we simply use
    Code:
    cp testfile-1 test-directory/
    and to copy both files we can either use
    Code:
    cp testfile* test-directory/
    or
    Code:
    cp testfile-1 testfile-2 test-directory/
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    So, let's start with what "cp" does. "cp" copies files. In the first command you ran, you tried to copy a file called "text.txt" in the current directory into the "test/" directory and call the copy test2.txt. The problem is that you do not have a file called "test.txt" in the current directory.

    The second command that you ran, you tried to copy a directory, which "cp" will by default not do. To copy a directory, you must use "cp -R" (the -R stands for "recursive"). However, you also cannot copy a directory into itself, so the command would still have failed.

    elija's answer explains how to create files and copy them around. If you would like to create a text file with some content that you write, you should use a text editor: vi and Emacs are the very popular ones, but they are very complicated. For a simpler commandline editor, you can try nano. For graphical text editors, try gedit (Gnome) or Kate or KWrite (KDE).
    elija likes this.

Posting Permissions

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