Results 1 to 7 of 7

Thread: copying files in terminal

  1. #1
    Join Date
    Jul 2005
    Beans
    37
    Distro
    Ubuntu Gnome 16.10 Yakkety Yak

    copying files in terminal

    What I am trying to do is extract all mine mp3 files that are in subfolders into one main folder. Can anyone help me i cannot remember how to do this in terminal
    Last edited by JustinJS; January 20th, 2009 at 08:44 PM.

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Beans
    1,805

    Re: copying files in terminal

    Say that you want to copy the mp3 files in 'subfolder1' and 'subfolder2' to 'destinationfolder'. Then type
    Code:
    cp subfolder1/*.mp3 subfolder2/*.mp3 destinationfolder
    If you want to see what cp does, use the -v flag, like
    Code:
    cp -v subfolder1/*.mp3 subfolder2/*.mp3 destinationfolder
    ...

  3. #3
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: copying files in terminal

    Quote Originally Posted by JustinJS View Post
    What I am trying to do is extract all mine mp3 files that are in subfolders into one main folder. Can anyone help me i cannot remember how to do this in terminal
    Code:
    find /path/to/mp3s -name "*.mp3" -exec cp {} /path/to/destination/dir \;

  4. #4
    Join Date
    Mar 2008
    Beans
    349
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: copying files in terminal

    Quote Originally Posted by sisco311 View Post
    Code:
    find /path/to/mp3s -name "*.mp3" -exec cp {} /path/to/destination/dir \;
    Is find recursive?

    Edit: cp has a recursive option (-R) so i'm not sure the usefulness of using this command over
    Code:
    cp -R *.mp3 /destination/folder
    Last edited by RequinB4; January 20th, 2009 at 09:28 PM.

  5. #5
    Join Date
    Dec 2006
    Location
    127.0.0.1
    Beans
    1,403

    Re: copying files in terminal

    'cp' is the command you want to use to copy in the CLI. If you are ever uncertain on how to use a specific command you can read the manual by typing 'man' then the command name. For example
    Code:
    man cp
    will give you information on using the cp command. Very useful when you can't remember things like 'whats the option to copy folder recursively?' and other things like that.
    Do not be afraid to joust a giant just because some people insist on believing in windmills.
    Free Moonbase Commander remake @ http://code.google.com/p/tether

  6. #6
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: copying files in terminal

    Quote Originally Posted by RequinB4 View Post
    Is find recursive?
    Yes.

    find /path/to/mp3 -name "*.mp3" = find all *.mp3 in /path/to/mp3 and sub-folders

    -exec cp {} /path/to/destination/dir \; = copy the files to /path/to/destination/dir

    e.g.

    Code:
    find ~/music -name "*.mp3" -exec cp {} ~/allmp3 \;
    Code:
    ~/music/0.mp3
    ~/music/band1/1.mp3
    ~/music/band1/2.mp3
    ~/music/band2/album1/3.mp3
    ~/music/band2/album1/4.mp3
    ~/music/band2/album2/5.mp3
    ~/music/band2/album2/6.mp3
    -->

    Code:
    ~/allmp3/0.mp3
    ~/allmp3/1.mp3
    ~/allmp3/2.mp3
    ~/allmp3/3.mp3
    ~/allmp3/4.mp3
    ~/allmp3/5.mp3
    ~/allmp3/6.mp3

  7. #7
    Join Date
    May 2008
    Beans
    Hidden!

    Re: copying files in terminal

    Quote Originally Posted by RequinB4 View Post
    Edit: cp has a recursive option (-R) so i'm not sure the usefulness of using this command over
    Code:
    cp -R *.mp3 /destination/folder
    No, because globbing is done by the shell (cp never sees '*.mp3', it gets a list of files). -R just makes it copy subdirectories.

Tags for this Thread

Bookmarks

Posting Permissions

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