Find the answer to your Linux question:
Results 1 to 4 of 4
Hello people, In an attempt to rearrange all my folders, I made a text file that contains something like this: /home/folder1 /home/folder2 file1.gif file2.doc /home/testserver /home/testserver/day1 specs.doc report.pdf I'm looking ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Posts
    1

    Copying files


    Hello people,
    In an attempt to rearrange all my folders, I made a text file that contains something like this:

    /home/folder1 /home/folder2
    file1.gif
    file2.doc
    /home/testserver /home/testserver/day1
    specs.doc
    report.pdf


    I'm looking for something that would read in this text file and then copy file1.gif and file2.doc from /home/folder1 to /home/folder2 AND specs.doc and report.pdf from /home/testserver to /home/testserver/day1 (suppose /home/testserver/day1 hasn't been created yet). Obviously I have a very huge list, so copying manually wouldn't be fun.

    Is there any tool/program/commands that could do this?
    Thx,

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    $ cp -r /home/folder1/* /home/folder2

    man cp....

    <=== { casper } ===>
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Linux Newbie stubbe's Avatar
    Join Date
    May 2006
    Posts
    143
    I suppose bash can do that kind of stuff.

    you could try make yourself a simple bash script

    using cp and mv command

    try create a text file containing these lines (just example) :

    sh
    cp /home/folder1/*.* /home/folder2/*.*
    cp /home/testserver/*.* /home/testserver/day1/*.*


    save it, change the permission, and run it.

    What this file do is copy the whole files inside those source folders into the destination folders. Maybe there're some errors, I cannot memorize the complete cp command syntax, and I'm not really an advanced bash scripter, so read the bash manual or any bash freak out there, see if you can find anything there.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined! DusteD's Avatar
    Join Date
    May 2006
    Location
    Denmark
    Posts
    35

    Cool heres a script

    Hi, i understand you want to copy only certain files, from from/to certain folders.
    Ive made a script (i use this for backing up my server) that does just that.

    The script is very easy to understand, i even added instructions for you and two example folders

    Code:
    #!/bin/bash
    #Copy certain files from one folder to another, www.dusted.dk
    #Usage:
    #Make the lists:
    #from_list[number]="/the/place/you/want/to/copy/from"
    #to_list[number]="/the/destination/for/files/on/this/list"
    #files_list[number]="the.gif files.jpg you.bin want.sh 'to copy.exe'"
    #You can have as many lists as you want, just update the "lists" variable with the numbers you gave your lists.
    
    lists="1 2"
    
    files_list[1]="file1 file2 file3"
    from_list[1]="/home/dusted/Desktop/folder1"
    to_list[1]="/home/dusted/Desktop/folder2"
    
    files_list[2]="file4 file5 file6"
    from_list[2]="/home/dusted/Desktop/folder3"
    to_list[2]="/home/dusted/Desktop/folder2"
    
    #No reason to edit below this point
    for numlist in $lists
     do
     echo "Copying from ${from_list[$numlist]} to ${to_list[$numlist]}"
      for file in ${files_list[$numlist]}
       do
         echo "    Copying $file"
         cp  "${from_list[$numlist]}/$file" "${to_list[$numlist]}"
       done
     done
    Copy script to an empty file, edit as needed, use "bash scriptname" to execute it.

    Also, please let me know i got what you meant right!

Posting Permissions

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