Visit Our UNIX and Linux User Community

Moving 100K file to another folder using 1 command

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving 100K file to another folder using 1 command
# 1  
Old 12-04-2009
Moving 100K file to another folder using 1 command


I need to move 1000s of files from one folder to another.
Actually there are 100K+ files.
Source dir : source1
Target dir : target1

Now if try cp or mv commands I am getting an error message : Argument List too long.

I tried to do it by the time the files are created in the source folder.

-rw-r--r-- 1 prod usr1 104 Dec 3 08:01 200912_011.txt

For example the above file we can see that files can be seggregated based on the timings - 08:01 > 1000 file
08:02 > 1000 file.
I can select the time from the ls -lrt command using awk '{print $8}'.

But not able to move files writing a command line. This is how I tried, any solution is welcome.

Thanks in advance.

Last edited by zaxxon; 12-04-2009 at 09:39 AM.. Reason: code tags
# 2  
Old 12-04-2009
Use acombination with find like for example
find . -type f -name "*" -exec cp {} /targetdir \;

find . | cpio -dumpv /targetdir

# 3  
Old 12-04-2009
Moving 100K file to another folder using 1 command

Hello unx100

Good ol' tar is marvellous to copy files from one directory to another:

cd sourcedir
tar -cf - ./ | ( cd targetdir ; tar -xf - )[/FONT]

When writing backup, tar can send data to stdout when you use a single - (hyphen), instead of setting filename for backup file.

On the other hand, when reading, tar can do the same way.

The parentheses ensure the shell enable to shift working directory before writing to working dir.

Have a good time!

Last edited by zaxxon; 12-04-2009 at 10:25 AM.. Reason: added code tags
# 4  
Old 12-04-2009
Bit heavy handed perhaps but I was at a bit of a loose end...

use POSIX;
use File::Copy;

$srcdir = '/source1';
$dstdir = '/target1';

opendir(DIR, "$srcdir");
@FILES= readdir(DIR);
foreach $file (@FILES) {
        chomp $file;

        print "current file is: **$file** \n";
        next unless -f $file;
        copy($srcdir . "/" . $file, $dstdir . "/" . $file) or die "File cannot be copied.";

Specifically looking only to copy files...

The one command would be ./ Smilie

Last edited by zaxxon; 12-04-2009 at 10:25 AM.. Reason: Because I had something to add.| zaxxon: added code tags
# 5  
Old 12-04-2009

Unless the files are being transferred to a different filesystem, I would recommend mv so that you are not touching the data inside the files, but rather only manipulating directory entries, a far less intensive activity. If different filesystems are involved, mv will arrange a copy, if I recall correctly.

The command
xargs - build and execute command lines from standard input

was invented to deal with the issue of long argument lists. See man xargs, search the forums, and experiment to see how it will address your problem.

Best wishes ... cheers, drl
# 6  
Old 12-04-2009
You could use rsync which is very versatile and adapted for a huge amount of data.
# 7  
Old 12-05-2009
Thank you all for your suggestions.

Previous Thread | Next Thread
Test Your Knowledge in Computers #797
Difficulty: Easy
The simplest arithmetic operation in binary is addition.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

2. Homework & Coursework Questions

Shell Scripting , Moving Old file to specific folder

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: There are files stored like 14.Aug.2014.log, 15.Aug.2014.log etc. in a folder $HOME/log you need to find out all... (4 Replies)
Discussion started by: shajoftaj
4 Replies

3. Ubuntu

Shell Scripting , Moving Old file to specific folder

There are files stored like 14.Aug.2014.log, 15.Aug.2014.log etc. in a folder $HOME/logyou need to find out all the log files of last 1 month and move them into $HOME/logs/lastmonth/ this should be implemented with reference of file name. ---------- Post updated at 12:30 PM ----------... (3 Replies)
Discussion started by: shajoftaj
3 Replies

4. Programming

Perl - Moving file based upon filesize in folder

Hi I'm trying to look through a series of directories in A folder, lets just call it A: for example: A/1 A/2 A/3 Etc and I wish to move the files in the folder if they are bigger than a certain size into a structure like below: A/TooBig/1 A/TooSmall/1 A/TooBig/2 A/TooSmall/2... (1 Reply)
Discussion started by: PerlNewbRP
1 Replies

5. Shell Programming and Scripting

Getting folder more than 100K size

Hi , I am trying to get the folder details having size more than sme specified value and also the name of the folder should be like TEST. so 1. In the current directory search for all the folders having name like TEST 2. Print the list of the folder names having size more than 100... (3 Replies)
Discussion started by: Anupam_Halder
3 Replies

6. Shell Programming and Scripting

Shell Script for moving 3 days old file to Archive Folder

Hi Experts, I have a "Source" folder which may contain some files. I need a shell script which should move all files which are older than 3 days to "Archive" folder. Thanks in Advance... (4 Replies)
Discussion started by: phani333
4 Replies

7. Shell Programming and Scripting

using mv command for moving multiple files in a folder

Hi, I have a requirement where I need to move Bunch of folders containing multiple files to another archive location. i want to use mv command .I am thinking when we use mv command to move directory does it create directory 1st and then move all the files ? e.g source... (4 Replies)
Discussion started by: rkmbcbs
4 Replies

8. UNIX for Dummies Questions & Answers

moving file from one folder to another

i have created file in one of the folders on unix UNIX 's36tou -T XYZ /tmp/p400/dataout/ias/AB >/dev/null I am using above command to copy file from one system to unix XYZ is name of file on my system usually this name is very big so i use -T to trim some charaters from name. noe... (1 Reply)
Discussion started by: ajit.yadav83
1 Replies

9. Shell Programming and Scripting

shell script for moving all the file from the same folder

Hi , I need a shell script which basicaly moves all the files from one folder say folder x to folder y and once they are moved to folder y a datetimestamp should be attached to there name for ex file a should be moved to y folder and renamed as a_20081015 (1 Reply)
Discussion started by: viv1
1 Replies

10. Shell Programming and Scripting

moving a file to a new folder and automated ftp

how to move a file to a different folder after an automated FTP . (1 Reply)
Discussion started by: dineshr85
1 Replies

Featured Tech Videos