Copy multiple files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy multiple files
# 1  
Old 06-30-2010
Copy multiple files

Hi

i have 1000 files is a directory, which are serially numbered (file1,file2,file3...). I would like to copy every 200 files to different directories.

many thanks in advance.
# 2  
Old 07-01-2010
One way:

1. Create a list of all files in question, e.g.:

Code:
ls -1 . > file.list

2. Split the list up in junk of 200 lines each:

Code:
LIST_001-200=$( cat file.list | sed -n '001,200p' )
LIST_201-400=$( cat file.list | sed -n '201,400p' )

3. Process each list in turn / as requested:

Code:
mv $( echo $LIST_001-200 ) FOLDER_A
mv $( echo $LIST_201-400 ) FOLDER_B

You get the idea ... ;-)
This User Gave Thanks to dr.house For This Post:
# 3  
Old 07-01-2010
Code:
ls -l > tmp.txt
awk '{print $9}' tmp.txt > ouput.txt

mv `head -200 output.txt` ${UR_FOLDER}
u might have to do this 5times. for moving all 1000files.

try this also
This User Gave Thanks to dazdseg For This Post:
# 4  
Old 07-01-2010
What is the naming convention for the target directories?
# 5  
Old 07-01-2010
Many thanks for the help.

The target directories are named dir1, dir2,....
# 6  
Old 07-01-2010
Open logic script for any number of files. Will need adjusting for actual directory structure. Remove the the "mkdir" line and the "mv" line when tested.

Code:
#!/bin/ksh
FILE_NO=0
DIR_NO=0
while true
do
        if [ ${FILE_NO} -eq 0 ]
        then
                FILE_NO=1
                DIR_NO=1
        else
                FILE_NO="`expr ${FILE_NO} + 1`"
        fi
        FILENAME="file${FILE_NO}"
        DIRNAME="dir${DIR_NO}"
        if [ ! -f "${FILENAME}" ]
        then
                break
        fi
        if [ ! -d "${DIRNAME}" ]
        then
                # Uncomment or correct for directory structure
                echo mkdir "${DIRNAME}"
        fi
        #
        # Uncomment when tested
        echo mv "${FILENAME}" "${DIRNAME}"
        #
        REMAINDER=`expr ${FILE_NO} % 200`
        if [ ${REMAINDER} -eq 0 ]
        then
                DIR_NO="`expr ${DIR_NO} + 1`"
        fi
done


Last edited by methyl; 07-01-2010 at 11:24 AM.. Reason: Correct divisor for remainder calcualation to match requirement.
This User Gave Thanks to methyl For This Post:
# 7  
Old 07-01-2010
Thanks everyone for the timely help.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy data at specified location from multiple files

Hello everyone, Im super new to coding but increasingly in need of it at work. Im have task stacked because of this problems, that I cannot figure out how to solve looking on the internet after trying many many things that looked similar to me. I have multiple data files of the form (see below).... (2 Replies)
Discussion started by: Xfiles_fan
2 Replies

2. Shell Programming and Scripting

Copy files matching multiple conditions

Hello How do i copy files matching multiple conditions. Requirement is to search files starting with name abc* and def* and created on a particular date or date range given by the user and copy it to the destination folder. i tried with different commands. below one will give the list ,... (5 Replies)
Discussion started by: NarayanaPrakash
5 Replies

3. Shell Programming and Scripting

Copy multiple files from A to B through passwordless ssh

hi all, I need to write one script to copy multiple imp files like /etc/passwd /etc/group /etc/shadow /etc/printers.conf from system A, System B and system C to system Z and I need to execute this script on System Z. like if system is equal A copy 1 2 3 files to system Z into... (9 Replies)
Discussion started by: manalisharmabe
9 Replies

4. UNIX for Dummies Questions & Answers

copy multiple files

Hi, I am facing this problem, however i am not finding any solution. Kindly help I have the list of files to be search , i need to search for those files and copy the files to a folder. Really its urgent. MG_0281.JPG Tdfa_0077.JPG The%20SirehSet%20Geduing%20KpgGlam%20.jpg... (4 Replies)
Discussion started by: umapearl
4 Replies

5. UNIX for Dummies Questions & Answers

Copy multiple files with space to folder

Please help , I am in an urgent need, Please help nawk '{for(i=1;i<=NF;i++){printf("%s\n",$i)}}' filename | sed 's/.*com//' | nawk '/pdf/ {printf("F:%s\n",$0)}' | while read line; do mv $line /images/; done the above script works for without spaces but,My path is also having some space... (3 Replies)
Discussion started by: umapearl
3 Replies

6. UNIX for Dummies Questions & Answers

Zip multiple files and copy to help

Hi All, I have a set of large files ~ 500_900Mb I have generated and I'd like to quickly zip and copy them to a new folder elsewhere ... Can anyone suggest a quicky ?? Cheers :) (3 Replies)
Discussion started by: pawannoel
3 Replies

7. Shell Programming and Scripting

ksh to copy multiple files

Guys, I've got a list of about 200 files I need to copy from /tmp to /data. I can't use wildcards because the filenames are all very different. What I want to do is cut and paste them into a file and read that as the input to a copy command (line by line). I tried using find and -exec... (4 Replies)
Discussion started by: Grueben
4 Replies

8. UNIX for Advanced & Expert Users

Very Challenging :Copy files in Multiple Threads

Hello all, I asked this in the basic Unix forum got no answer since one week. So I believe this is an advanced level question hence posting it here. Any suggestions welcome. I have a directory of files of varying sizes. I want to copy all these files in n number of threads to... (2 Replies)
Discussion started by: samoo
2 Replies

9. UNIX for Dummies Questions & Answers

Copy files in Multiple Threads

Hello all, I have a directory of files of varying sizes. I want to copy all these files in n number of threads to another directory such that each copy set is more or less the same size. Example : Say /mydirA It has around say 23 files of various sizes. Number of copy... (0 Replies)
Discussion started by: samoo
0 Replies

10. UNIX for Dummies Questions & Answers

copy multiple files in different directories

I have a report file that is generated every day by a scheduled process. Each day the file is written to a directory named .../blah_blah/Y07/MM-DD-YY/reportmmddyy.tab I want to copy all of this reports to a separate directory without having to do it one by one. However, if I try cp... (3 Replies)
Discussion started by: ken2834
3 Replies
Login or Register to Ask a Question