LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-30-2015, 11:46 PM   #1
funknotik
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Rep: Reputation: Disabled
Simple cp commands doesn't work. Sorry noobing out here.


I'm trying to simply copy a file into the same directory. I'm in /Documents

There is a file called "file" for example

I type

cp file file2
it returns

cpmitting directory 'file'

nothing happens.

Not sure what I'm doing wrong here every video I see it's really this simple.
 
Old 07-31-2015, 12:26 AM   #2
kenam08
LQ Newbie
 
Registered: Jul 2015
Posts: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by funknotik View Post
I'm trying to simply copy a file into the same directory. I'm in /Documents

There is a file called "file" for example

I type

cp file file2
it returns

cpmitting directory 'file'

nothing happens.

Not sure what I'm doing wrong here every video I see it's really this simple.

Hi are you trying to copy on the same directory?

try cp /sourcepath/filename /pathdestination/filename
 
Old 07-31-2015, 12:28 AM   #3
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Current: Debian and OpenSUSE. Past: Arch, RedHat (pre-RHEL). FreeBSD & OpenBSD novice, Hackintosh
Posts: 1,191
Blog Entries: 7

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
What it's telling you is that file is a directory, and you haven't specified -R (recursive) as an option.

Oddly, if you are sure this is a regular file, something else is going on.
 
Old 07-31-2015, 12:42 AM   #4
funknotik
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by goumba View Post
What it's telling you is that file is a directory, and you haven't specified -R (recursive) as an option.

Oddly, if you are sure this is a regular file, something else is going on.

Thanks for your response. I'm in the Documents folder and simply typing cp file file2 should copy teh file to teh same directory but instead I get the error message I mentioned before. I'm running it on vmware don't know if that has anything to do with it. This has never happened before really strange, it started after I re installed a new ubuntu distro.
 
Old 07-31-2015, 01:01 AM   #5
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Current: Debian and OpenSUSE. Past: Arch, RedHat (pre-RHEL). FreeBSD & OpenBSD novice, Hackintosh
Posts: 1,191
Blog Entries: 7

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Paste the output of ls -l here (paste the output between (code] (/code] tags, replace open paren with open bracket).
 
Old 07-31-2015, 01:32 AM   #6
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 899

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
New ubuntu distro
probably means that you dont have rights to read the old file or to copy it as file2 into the "documents" folder.

OK
 
Old 07-31-2015, 09:21 AM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,913
Blog Entries: 9

Rep: Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524Reputation: 3524
Paste the output of
Code:
ls -al
 
Old 07-31-2015, 10:17 AM   #8
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,667

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
First, try issue:
Code:
chown -R $USER: ./file
[change that $USER to your username, always end with a colon ":" ]

Then, try issue:
Code:
cp -r ./file file2
Feed back tell us what happen.

Last edited by malekmustaq; 07-31-2015 at 10:19 AM.
 
Old 07-31-2015, 10:53 AM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
Quote:
Originally Posted by funknotik View Post
Thanks for your response. I'm in the Documents folder and simply typing cp file file2 should copy teh file to teh same directory but instead I get the error message I mentioned before. I'm running it on vmware don't know if that has anything to do with it. This has never happened before really strange, it started after I re installed a new ubuntu distro.
As he said, according to the error message, "file" is not a file, it's a directory. In order to copy a directory, you need to use the recursive switch in cp, which is -r or -R.
 
Old 08-01-2015, 02:44 AM   #10
funknotik
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
You are all right I use mkdir to create a file called file.txt.

Then I entered cp file.txt file2.txt

I tried the following commands

thor@ubuntu:~/Documents$ ls
file2.txt filenew.txt file.txt
thor@ubuntu:~/Documents$ cp file.txt file2.txt
cp: omitting directory ‘file.txt’
thor@ubuntu:~/Documents$ cp -r file.txt file3.txt
thor@ubuntu:~/Documents$ ls
file2.txt file3.txt filenew.txt file.txt
thor@ubuntu:~/Documents$ ^C
thor@ubuntu:~/Documents$

It works when I use cp -r file.txt file2.txt to copy the file. But not when I simply use cp file.txt file2.txt .
I saw video where it worked the second way I described which is why im wondering why it's not working. but i did use mkdir to make the files which I guess is the problem. Please confirm. thanks again guys.
 
Old 08-01-2015, 03:19 AM   #11
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,277
Blog Entries: 11

Rep: Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253Reputation: 3253
Quote:
Originally Posted by funknotik View Post
You are all right I use mkdir to create a file called file.txt.

Then I entered cp file.txt file2.txt

I tried the following commands

thor@ubuntu:~/Documents$ ls
file2.txt filenew.txt file.txt
thor@ubuntu:~/Documents$ cp file.txt file2.txt
cp: omitting directory file.txt


It works when I use cp -r file.txt file2.txt to copy the file. But not when I simply use cp file.txt file2.txt .

You did NOT use mkdir to create the file file.txt.

You DID use mkdir to create the directory file.txt

A directory is not a file no matter what you name it, so you cannot copy it as you would a file using cp. You can copy a directory recursively using the -r option to cp.

Quote:
Originally Posted by funknotik View Post
I saw video where it worked the second way I described which is why im wondering why it's not working. but i did use mkdir to make the files which I guess is the problem. Please confirm. thanks again guys.
Either you are mistaken about what you saw or someone faked the video... it doesn't work that way with directories.

Instead of using mkdir, try touch which will create a file if it does not exist:

Code:
touch somefile.txt
cp somefile.txt somefile2.txt

Last edited by astrogeek; 08-01-2015 at 03:51 AM. Reason: typos, grammer
 
Old 08-01-2015, 06:44 AM   #12
fatmac
Senior Member
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Posts: 3,205

Rep: Reputation: Disabled
If you run
Code:
ls -lh .
you will see if a name is a file, directory, or link.

The first letter shows which,
d = directory
l = link
- = file
(There are others, but these are what you want to know usually.)
 
Old 08-01-2015, 09:43 AM   #13
onebuck
Moderator
 
Registered: Jan 2005
Location: Summer Midwest USA, Central Illinois, Winter Central Florida
Distribution: Slackware®
Posts: 13,471
Blog Entries: 32

Rep: Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659Reputation: 2659
Member response

Hi,

Welcome to LQ!
Quote:
Originally Posted by funknotik View Post
I'm trying to simply copy a file into the same directory. I'm in /Documents

There is a file called "file" for example

I type

cp file file2
it returns

cpmitting directory 'file'

nothing happens.

Not sure what I'm doing wrong here every video I see it's really this simple.
You seem to be confusing the semantics & syntax for the 'cp' command, 'man command' is your friend'. Maybe #2,#3 ,#7 & #9 may be of help while the others will help advance your understanding;
Quote:
Just a few links to aid you to gaining some understanding;


1 Linux Documentation Project
Hope this helps.
Have fun & enjoy!
 
Old 08-01-2015, 10:16 AM   #14
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
Quote:
Originally Posted by funknotik View Post
It works when I use cp -r file.txt file2.txt to copy the file. But not when I simply use cp file.txt file2.txt .
I saw video where it worked the second way I described which is why im wondering why it's not working. but i did use mkdir to make the files which I guess is the problem.
mkdir = MaKe DIRectory
You didn't make a file, you made a directory, it doesn't matter what you chose to call it. You need to use the -r flag in cp if you want to copy a directory.

If you want to create a file, you can do so using numerous other tools, but not mkdir, because by definition mkdir makes directories.
 
Old 08-01-2015, 05:12 PM   #15
funknotik
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
You did NOT use mkdir to create the file file.txt.

You DID use mkdir to create the directory file.txt

A directory is not a file no matter what you name it, so you cannot copy it as you would a file using cp. You can copy a directory recursively using the -r option to cp.



Either you are mistaken about what you saw or someone faked the video... it doesn't work that way with directories.

Instead of using mkdir, try touch which will create a file if it does not exist:

Code:
touch somefile.txt
cp somefile.txt somefile2.txt


Thank you you cleared it up yeah I was using mkdir because that was the first tutorial I learned but a directory is not a file. now I see I have cat > for example for making text files and various other ways to create actual files and now cp works fine with those. I know i have to use cp -r in order to copy a directory file. Thanks again extremely helpful cheers!
 
  


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] stupid simple script doesn't work ?? sharky Linux - Software 4 01-12-2011 02:54 PM
TBB: A simple parallel_for doesn't work! Sinedie Programming 2 05-27-2009 04:40 AM
simple DNAT iptables rule doesn't work. firatkucuk Linux - Networking 2 10-22-2007 02:35 AM
ifconfig amounst other commands doesn't work steveman2000 Linux - Newbie 6 10-21-2005 05:15 PM
Using Select to make a simple directory menu why doesn't it work ctrimble Programming 5 06-07-2004 02:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 AM.

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