LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-04-2011, 10:41 PM   #1
huNti
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Rep: Reputation: Disabled
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
 
Old 07-04-2011, 10:45 PM   #2
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 495

Rep: Reputation: 212Reputation: 212Reputation: 212
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.
 
Old 07-04-2011, 11:50 PM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
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.

Last edited by divyashree; 07-05-2011 at 12:26 AM.
 
1 members found this post helpful.
Old 07-04-2011, 11:59 PM   #4
huNti
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
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.
 
Old 07-05-2011, 12:10 AM   #5
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by huNti View Post
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..

Last edited by divyashree; 07-05-2011 at 12:12 AM.
 
0 members found this post helpful.
Old 07-05-2011, 12:43 AM   #6
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 495

Rep: Reputation: 212Reputation: 212Reputation: 212
Quote:
Originally Posted by huNti View Post
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.
 
Old 07-05-2011, 12:50 AM   #7
dEnDrOn
Member
 
Registered: Jun 2011
Location: oMNipre$ent
Distribution: fedora
Posts: 510
Blog Entries: 12

Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by huNti View Post
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....!!!
 
Old 07-05-2011, 12:53 AM   #8
dEnDrOn
Member
 
Registered: Jun 2011
Location: oMNipre$ent
Distribution: fedora
Posts: 510
Blog Entries: 12

Rep: Reputation: Disabled
Thumbs up

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 !
 
Old 07-05-2011, 01:05 AM   #9
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by dEnDrOn View Post
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"]

Last edited by divyashree; 07-05-2011 at 01:07 AM.
 
Old 07-05-2011, 01:09 AM   #10
dEnDrOn
Member
 
Registered: Jun 2011
Location: oMNipre$ent
Distribution: fedora
Posts: 510
Blog Entries: 12

Rep: Reputation: Disabled
Question

Quote:
Originally Posted by divyashree View Post
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...?
 
Old 07-05-2011, 01:17 AM   #11
huNti
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
thanks for reply's. I find another way that worked.

Code:
 touch /home/hunti/Desktop/test test/test2.txt
 
Old 07-05-2011, 01:22 AM   #12
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ 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.
 
1 members found this post helpful.
Old 07-05-2011, 01:23 AM   #13
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 495

Rep: Reputation: 212Reputation: 212Reputation: 212
Quote:
Originally Posted by dEnDrOn View Post
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.
 
Old 07-05-2011, 01:35 AM   #14
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by dEnDrOn View Post
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.
 
Old 07-05-2011, 01:37 AM   #15
dEnDrOn
Member
 
Registered: Jun 2011
Location: oMNipre$ent
Distribution: fedora
Posts: 510
Blog Entries: 12

Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by Diantre View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 09:36 AM
NSLU2 setup- UpSlug2 source build terminal problem- "No such file or directory" RockandRoll24 Linux - Newbie 0 03-22-2010 10:58 AM
Ubuntu odd problem: can't see any text in "Terminal" beeblequix Ubuntu 5 11-01-2007 10:40 AM
konsole problem: "Unable to open a suitable terminal device" Mistreated Linux - Software 2 11-15-2004 04:24 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-22-2003 12:47 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration