Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Linux Help

  1. #1
    Regular Coder
    Join Date
    Jun 2004
    Location
    Washington University in St Louis
    Posts
    117
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Linux Help

    Anyone know of the command line for copying all files of a certain extension inside a folder and all its sub directories to another location while maintaining the directory tree? Thanks in advance.

  • #2
    New Coder
    Join Date
    Jan 2005
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe something like this..

    cp /dir/*.mp3 /whereyouwantittogo

    that * means everything with the extension .mp3

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    you will want to use

    cp -r /sourcedirectory /targetdirectory

    the r option tells it to copy recursively in that directory so it will grab all the sub directorys and then copy the entire structure to whatever target directory you specify
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Location
    Washington University in St Louis
    Posts
    117
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Okay, it will copy the entire folder, but what I want to do is copy only certain files of a certain extension.

    So in directory /usr/home/me/bigProject, I want to copy all files of extension *.m to location /usr/home/me/bigProjectBackup, while preserving the relative location of files.

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ahh I see. It would probably be easier to just copy everything and then do a recursive search/delete for all files that you don't want.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    Regular Coder
    Join Date
    Jun 2004
    Location
    Washington University in St Louis
    Posts
    117
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yeah, that's what I told the boss. Let's say I have a very stubborn boss. Thanks for the help, I wrote a program "amv" that uses a bunch of system calls to get the job done.

    On the off chance anyone else may find it useful, I will post the link on this thread at a later point in time.


  •  

    Posting Permissions

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