Find the answer to your Linux question:
Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Roxoff
Code: peter@xb-msi:~/Ubuntu One$ cp -p /home/peter/Ubuntu\ One/CHEM2021\ -\ 1pm\ Fri\ -\ 07\ Oct\ 2011/VIDEO0086.3gp /media/2080-3248/Ubuntu\ One/CHEM2021\ -\ 1pm\ Fri\ -\ 07\ Oct\ 2011/ cp: cannot create regular file `/media/2080-3248/Ubuntu One/CHEM2021 ...
  1. #1
    Linux Newbie
    Join Date
    May 2010
    Posts
    125

    Copy error - "X is a directory" - what's wrong?

    Code:
    peter@xb-msi:~/Ubuntu One$ cp -p /home/peter/Ubuntu\ One/CHEM2021\ -\ 1pm\ Fri\ -\ 07\ Oct\ 2011/VIDEO0086.3gp /media/2080-3248/Ubuntu\ One/CHEM2021\ -\ 1pm\ Fri\ -\ 07\ Oct\ 2011/
    cp: cannot create regular file `/media/2080-3248/Ubuntu One/CHEM2021 - 1pm Fri - 07 Oct 2011/': Is a directory
    Yeah thanks a lot Linux, that's exactly what I want and you're objecting to it for some reason. I want to copy a file into that currently non-existent directory and I want you to create it if it doesn't already exist.

    How do I make Linux do what I want?

  2. #2
    Trusted Penguin Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,393
    By default, cp copies files, not directories. You need to tell it to do its thing recursively, like this:

    Code:
    $ cp -R /home/me/source_dir /home/someoneelse/target
    As you're trying to preserve the permissions here, you might want to look at the '-a' option, which I use all the time when copying directories - it preserves the permissions and timestamps, and does the directory recursion too:

    Code:
    $ cp -a /home/me/source_dir /home/someoneelse/target
    There's a description of the command's switches on its man page. Try:

    Code:
    $ man cp
    lindsey likes this.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Linux Newbie
    Join Date
    May 2010
    Posts
    125
    Quote Originally Posted by Roxoff View Post
    By default, cp copies files, not directories.
    I don't understand - VIDEO86.3gp is a file, not a directory, isn't it?

  4. #4
    Trusted Penguin Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,393
    You could be right - the long directory paths here make this hard to read. But on closer look, the command appears to be complaining about the target directory, not the source one. Did you let your shell complete the path names (by pressing the TAB key) as you entered it? That can reduce typos. You could also drop the trailing '/' character?
    Linux user #126863 - see http://linuxcounter.net/

  5. #5
    Linux Newbie
    Join Date
    May 2010
    Posts
    125
    Quote Originally Posted by Roxoff View Post
    Did you let your shell complete the path names (by pressing the TAB key) as you entered it?
    I thinks so, yes.
    Quote Originally Posted by Roxoff View Post
    That can reduce typos. You could also drop the trailing '/' character?
    But I need to specify a new directory location. I also want to avoid specifying a new filename, so I have to clearly define the destination path with a trailing "/". I want the file to retain its original name.

  6. #6
    Trusted Penguin jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    4,073
    As I understand it, you first need to create the destination directory.
    Code:
    mkdir path_to_directory
    Then you can cp your file over, retaining the original name.

    AFAIK, cp doesn't support actually creating the target directory.
    Last edited by jayd512; 01-27-2012 at 11:15 AM. Reason: clarification
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to Private Messages asking for Linux help. Please, keep it on the public boards.

  7. #7
    Linux Newbie
    Join Date
    May 2010
    Posts
    125
    Quote Originally Posted by jayd512 View Post
    As I understand it, you first need to create the destination directory.
    Code:
    mkdir path_to_directory
    Then you can cp your file over, retaining the original name.

    AFAIK, cp doesn't support actually creating the target directory.
    Really, there is no switch to allow this? Seems pretty basic. I'm surprised cp doesn't support directory creation.

  8. #8
    Trusted Penguin jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    4,073
    I just ran through the man page... nothing there for directory creation.
    Frustrating... I agree.

    I recall running across a few scripts online that serve that function, but it's not actually a default function.
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to Private Messages asking for Linux help. Please, keep it on the public boards.

Posting Permissions

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