LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   terminal "cp" problem (https://www.linuxquestions.org/questions/linux-newbie-8/terminal-cp-problem-889933/)

huNti 07-04-2011 09:41 PM

terminal "cp" problem
 
I made a file in terminal "mkedir test", I want to copy 2 text files in it in it. So I do "cp /home/hunti/Desktop test.txt test/test2.txt" and it says "no such file or directory. I also try'd "cp /home/hunti/Desktop/test test/test2.txt" and it says "omitting directory", but nothing happens.

Any advice??

thanks

Diantre 07-04-2011 09:45 PM

You have a couple of mistakes there, first it's mkdir, not mkedir. Second, you give cp the files first and the directory last:

Code:

$cp test.txt test/test2.txt /home/hunti/Desktop
Check the cp manpage for details.

divyashree 07-04-2011 10:50 PM

There are two arguments which cp take:

Code:

cp <source> <destinetion>
If you are copying file , in source you have to give the path(Absolute/relative) of file.
If you are copying directory use -r option with cp and the source is the path(Absolute/relative) to dir.

And the destination is directory always , but while renaming a file destination is a file name.

huNti 07-04-2011 10:59 PM

Thanks for reply. Funny enough
Code:

hunti@hunti-Aspire-M7720:~/Desktop$ cp -r test test/test2.txt
cp: cannot copy a directory, `test', into itself, `test/test2.txt'

works. But I don't want a folder, so I did without -r. :


When I do without -r
Code:

hunti@hunti-Aspire-M7720:~/Desktop$ cp test test/test2.txt
cp: omitting directory `test'

and u can see i get error 'omitting directory', but I don't see anything in folder. with -r I see a folder named text2.


ps: I try's cp man page and nothing was there that helped me.

divyashree 07-04-2011 11:10 PM

Quote:

Originally Posted by huNti (Post 4405139)
Thanks for reply. Funny enough
Code:

hunti@hunti-Aspire-M7720:~/Desktop$ cp -r test test/test2.txt
cp: cannot copy a directory, `test', into itself, `test/test2.txt'

works. But I don't want a folder, so I did without -r. :


When I do without -r
Code:

hunti@hunti-Aspire-M7720:~/Desktop$ cp test test/test2.txt
cp: omitting directory `test'

and u can see i get error 'omitting directory', but I don't see anything in folder. with -r I see a folder named text2.


ps: I try's cp man page and nothing was there that helped me.

In both of your case .. you are copying folder in to file..
I told you before destination is always a directory..
In your case destination is a file..

Try to understand 1st how it works..

Diantre 07-04-2011 11:43 PM

Quote:

Originally Posted by huNti (Post 4405139)
ps: I try's cp man page and nothing was there that helped me.

I find that hard to believe. How about this:

Code:

SYNOPSIS
      cp [OPTION]... [-T] SOURCE DEST
      cp [OPTION]... SOURCE... DIRECTORY
      cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
      Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

You're confusing the SOURCE and DEST.

dEnDrOn 07-04-2011 11:50 PM

Quote:

Originally Posted by huNti (Post 4405089)
I made a file in terminal "mkedir test", I want to copy 2 text files in it in it. So I do "cp /home/hunti/Desktop test.txt test/test2.txt" and it says "no such file or directory. I also try'd "cp /home/hunti/Desktop/test test/test2.txt" and it says "omitting directory", but nothing happens.

Any advice??

thanks


how can you copy a file to another file ?
just edit the file to add relevant items....
it is no big deal to understand that things can be copied into a directory only,but all you are trying is to copy a file into another...which i don't think is possible !
using cp command,destination has to be a directory always....!!!

dEnDrOn 07-04-2011 11:53 PM

if you want help with cp command,then try this......
i'd advice first work out how a command works,then things go a lot more easier..
good luck !

divyashree 07-05-2011 12:05 AM

Quote:

Originally Posted by dEnDrOn (Post 4405171)
using cp command,destination has to be a directory always....!!!

For creating a new file with the name of an existing file .. the destination has to be the file name.[COLOR="Silver"]

dEnDrOn 07-05-2011 12:09 AM

Quote:

Originally Posted by divyashree (Post 4405181)
For creating a new file with the name of an existing file .. the destination has to be the file name.

but why would anyone not edit the file and use cp command to copy a file into another...?

huNti 07-05-2011 12:17 AM

thanks for reply's. I find another way that worked.

Code:

touch /home/hunti/Desktop/test test/test2.txt

T3RM1NVT0R 07-05-2011 12:22 AM

@ Reply
 
Hi huNti,

Welcome to LQ!!!

I would like to point that mkdir is used to create directory and not file. Are you sure you have created a file in the first step. Here are the steps that you can try to perform the test:

1. cd /home/hunti (You are getting into your home directory, you will be there by default if you are logged in as the user hunti)
2. mkdir test1 (creating a test folder test1)
3. cd test1 (getting in the directory test1)
4. touch test1.txt (creating a blank file with the name test1.txt under /home/hunti/test1 )
5. cd .. (getting back to previous directory that is /home/hunti)
6. mkdir test2 (creating another test folder test2, this is the folder where you will copy the file test1.txt)
7. cp /home/hunti/test1/test1.txt /home/hunti/test2 (command to copy over the file)

I am using the full path in the command to avoid confusion.

There are many switches you can use with cp command but here we are only copying one file so no switches are required.

I hope this helps.

Diantre 07-05-2011 12:23 AM

Quote:

Originally Posted by dEnDrOn (Post 4405183)
but why would anyone not edit the file and use cp command to copy a file into another...?

Well, I think the OP is trying to learn some basic commands, but is getting confused with the order of parameters when using cp. He/she mentions in his/her first post that the idea is to create a directory (even though it says "file", I'm sure "directory" was meant), and copy two files into that directory.

Unfortunately, the man page is not helping him/her, so let's hope the tutorial link you posted will be useful for the OP.

divyashree 07-05-2011 12:35 AM

Quote:

Originally Posted by dEnDrOn (Post 4405183)
but why would anyone not edit the file and use cp command to copy a file into another...?


It is one option which is available to the user . It depends on user how he will achieve.

dEnDrOn 07-05-2011 12:37 AM

Quote:

Originally Posted by Diantre (Post 4405199)
Well, I think the OP is trying to learn some basic commands, but is getting confused with the order of parameters when using cp. He/she mentions in his/her first post that the idea is to create a directory (even though it says "file", I'm sure "directory" was meant), and copy two files into that directory.

Unfortunately, the man page is not helping him/her, so let's hope the tutorial link you posted will be useful for the OP.


yeah,exactly that is what came to my mind too.
But now he/she is sorted


All times are GMT -5. The time now is 05:08 PM.