Copying files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying files
# 1  
Old 03-20-2014
Copying files

All,

I need to grab and rename common files from several unique directory structures. For example, the directory structures looks like:

/unique_dir/common/common/common/person_name_dir/common_file.txt

There are over 90,000 of these text files that I'd like to put in a single directory as person_name_common_file.txt. I tried to write a simple perl script but I'm a bit over my head:

Code:
#!/usr/bin/perl

use File::Copy;

my $dir;
my @dir = `find . -type d -mindepth 4`;

chdir "/home/admin/pack";

foreach $dir (@dir) {

        chomp $dir;
        move ($dir,"/home/admin/out/");

}

exit 0;

This partially works for the first step of putting all the person_name_dir into a new folder but I need to consider duplicate names (which name1, name2, name3 would be fine) and doing the pre-pending of the common text file with the person's name.

Hopefully I haven't confused my intentions too much. If this is easier done in a shell script or other please let me know. Any guidance is greatly appreciated.

Thanks in advance,

Herb
# 2  
Old 03-20-2014
Quote:
There are over 90,000 of these text files that I'd like to put in a single directory as person_name_common_file.txt
It's a very bad idea to put 90,000 files in one directory. Creating or deleting files inside that folder will become very slow.

What is your actual goal here? I don't mean "moving the files". Why are you moving the files? If we can find a way to accomplish your ask without dumping 90,000 files in one directory you'll be much better off.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-20-2014
The files will be used as a one time read of the txt files. There will not be ongoing reads/writes.
# 4  
Old 03-21-2014
Can't you do this
Code:
 mkdir ("/home/admin/out/person_name_dir");
 move ($dir,"/home/admin/
out/person_name_dir");

Wouldn't it solve the performance problem and the name conflicts?
# 5  
Old 03-21-2014
Quote:
Originally Posted by hburnswell
The files will be used as a one time read of the txt files. There will not be ongoing reads/writes.
That is not the problem, though:
Quote:
Originally Posted by Corona688
It's a very bad idea to put 90,000 files in one directory. Creating or deleting files inside that folder will become very slow.
This could happen during the move, because moving a file counts. Anything which alters the output of 'ls' is altering the directory entry, which is what slows down. Moving the first few thousand files will happen lickety-split, but it will quickly bog down. It could take hours or days to move them all. That's why those files have been split into a tree of folders, to avoid this. All for an operation you say you're going to be doing what -- once? What will you do with them after -- leave them sitting forever, or delete them? Deleting that massive pile of files will take a similarly awful amount of time.

Strangely, "ongoing reads/writes" usually aren't a problem. Creating one file isn't so bad... Opening one file isn't so bad... Which is how people end up with folders full of 90,000 files -- something logging or recording for years and years without cease in the same place. Someday they need to delete them all, and find themselves in big trouble. We regularly get threads like this.

So, let me repeat my question:

Quote:
What is your actual goal here? I don't mean "moving the files". Why are you moving the files? If we can find a way to accomplish your ask without dumping 90,000 files in one directory you'll be much better off.
Please tell us why you think you need 90,000 files in one place. What could you do with them all in one place, that you can't do now?

Last edited by Corona688; 03-21-2014 at 01:39 PM..
# 6  
Old 03-25-2014
@Corona688, thank you for your replies. I've gone back to the team that asked for the initial copy and asked them why they want to do what they're asking.

They are re-thinking what they need and I'll update if necessary.

Thanks again,

Herb
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying files

I'm trying to do this exact same thing, so far I have created this to move files i've named my script CP.sh #!/bin/bash cd /root/my-documents/NewDir/ for f in *.doc do cp -v $f root/my-documents/NewDir $f{%.doc} done When i go to run this in the console i type, bin/sh/ CP.sh but it... (7 Replies)
Discussion started by: MKTM_93_SIMP
7 Replies

2. Shell Programming and Scripting

Copying files excluding some files

Hi, I have a folder which contains files in this format. abc-bin.000001 abc-bin.000002 abc-bin.000003 abc-bin.000004 abc-bin.000005 abc-bin.000006 abc-bin.000007 abc-bin.000008 abc-bin.000009 abc-bin.000010 abc-bin.index I want to copy all the files between abc-bin.000004... (6 Replies)
Discussion started by: arijitsaha
6 Replies

3. Shell Programming and Scripting

Copying files after result

Hi, I have a shell script #!/bin/sh date echo 'HI PROD' echo $Please ENTER THE INPUT 1 for old files 2 for new file read i if ; then cd /apps/acetp3_logs/prod3/O* pwd echo $PLEASE ENTER THE STRING TO SEARCH (PLEASE ENTER THE STRING INSIDE QUOTES ' ') read j echo... (6 Replies)
Discussion started by: thelakbe
6 Replies

4. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

Hi All, I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files. To Do From Directory : /myproject/MainDir To Directory : /myproject/data List of files need to copy is in the file: /myproject/filesList.txt ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

5. Shell Programming and Scripting

Copying Files

Hi All, I'm trying to list some files from my log directory and files are like this log.20110302_20.gz log.20110302_21.gz log.20110302_22.gz log.20110302_23.gz log.20110303_00.gz log.20110303_01.gz log.20110303_02.gz ............ log.20110311_22.gz log.20110311_23.gz... (2 Replies)
Discussion started by: thelakbe
2 Replies

6. UNIX for Advanced & Expert Users

copying of files by userB, dir & files owned by userA

I am userB and have a dir /temp1 This dir is owned by me. How do I recursively copy files from another users's dir userA? I need to preserve the original user who created files, original group information, original create date, mod date etc. I tried cp -pr /home/userA/* . ... (2 Replies)
Discussion started by: Hangman2
2 Replies

7. Solaris

Copying Files

Hi, I understand that to copy files across server, the feasible way will be using scp command. Am I right? What if the two servers are not connected to a network? If by using a cross cable to link up both the server, what will be the best (fastest) way to copy files across? scp as well? ... (3 Replies)
Discussion started by: user50210
3 Replies

8. Shell Programming and Scripting

copying files

hi I want to copy all files from the current directory and move to .archive file. Moreover,I want to add .bak to each file name, that will be copied. How can I do that? (4 Replies)
Discussion started by: tjay83
4 Replies

9. Solaris

Copying Files and

I am new user to solaris and installed solaris operating system on full Harddisk 120Gb. I am unable to copy music files to desktop and /home directory. One thing happened while registering is- i entered login-root and its password. The message prompted your system is crashed. Is it because of... (1 Reply)
Discussion started by: patilmukundraj
1 Replies

10. UNIX for Dummies Questions & Answers

Copying files

I like to know the command structure of copying files/directories from a unix box using telnet session to a windows box. (4 Replies)
Discussion started by: alpheusm
4 Replies
Login or Register to Ask a Question