Split a folder with huge number of files in n folders
We have a folder XYZ with large number of files (>350,000). how can i split the folder and create say 10 of them XYZ1 to XYZ10 with 35,000 files each. (doesnt matter which files go where).
Thanks. I have something similar. But I was wondering if there is a way to do this without the explicit loop and moving one file at a time. This is too slow and we have to perform this operation on multiple folders of the given size.
Quote:
Originally Posted by Scrutinizer
Try something like:
Try it out on a test directory first and/or prepend echo to the mv command to see if it works as desired...
Do any of the 350,000 files you're moving have names that contain any space, tab, or newline characters?
Hi Don,
I am on Ubuntu Server 12.04 LTS. The files do not contain any special characters except _
Actually the format is something like
<xyz>_n1_n2_n3.pbx
where <xyz> is a prefix containing only alphabets [a-z A-Z]
n1 is a number less than 10
n2 is a number less than 1000
n3 is a number less than 10000
pbx is the extension
---------- Post updated at 04:08 PM ---------- Previous update was at 04:06 PM ----------
Quote:
Originally Posted by MadeInGermany
Aren't 350 000 files too many arguments for for i in *?
Safer and faster is
Thanks.. Although I did not get an error for too many files with for I in *, find seems faster and as you mentioned safer if the number of files increase.
Aren't 350 000 files too many arguments for for i in *?
Safer and faster is
In theory, no. The for i in * is all processed inside the shell without having to create an argument list like it would for ls * (which would almost certainly fail hitting ARG_MAX limits).
Another possibility would be something like set -- * which would then allow you to use $# to split groups of files instead of going round-robin. Invoking mv for each file to be moved is going to be much slower than invoking mv to move groups of files.
If filenames are of the form <xyz>_n1_n2_n3.pbx would it make more sense to create a directory for each n2 value rather than ten directories with an arbitrary spread of files into those new directories. If part of the filename can be used to determine which directory to search, it should make it much faster to find needed files after the files have been rearranged. If this is of interest to the submitter, we could help come up with a way to help do this.
I recently bought Synology server and realised it can run scripts. I would need fairly simple script which moves all files and folders from ARCHIVE folder to WORKING folder. I would also need to maintain folder structure as each of the folders may contain subfolders. How would I go about it as I am... (1 Reply)
Hi,
I have a Huge 7 GB file which has around 1 million records, i want to split this file into 4 files to contain around 250k messages each.
Please help me as Split command cannot work here as it might miss tags..
Format of the file is as below
<!--###### ###### START-->... (6 Replies)
Hi.
I have a folder which contains my application. I then have a flexible number of folders in another directory, called “sites”. It looks like this:
-Application
-- Test.html
-- CSS
--- Style.css
-Sites
--Site1
--Site2
I want to symlink all the files in the application folder... (1 Reply)
I have a more than 10 K files in a folder. They are accumulated in a period of more than an year (Say from 13th July 2010 to 4th June 2011). I need to perform housekeeping on this. The requirement is to create a folder like 13Jul2010,14July2010,......3June2011,4June2010 and then from the main... (2 Replies)
I’m new to Linux script and not sure how to filter out bad records from huge flat files (over 1.3GB each). The delimiter is a semi colon “;”
Here is the sample of 5 lines in the file:
Name1;phone1;address1;city1;state1;zipcode1
Name2;phone2;address2;city2;state2;zipcode2;comment... (7 Replies)
I met a problem on HPUX with 64G RAM and 20 CPU.
There are 5 million files with file name from file0000001.dat to file9999999.dat, in the same directory, and with some other files with random names.
I was trying to remove all the files from file0000001.dat to file9999999.dat at the same time.... (9 Replies)
Hi,
I have a sub directory with a number of files and folders. What i want is a subdirectory with just folders and not files for cleanliness sake. So I want to move the files into the new folder but keep the folders in the same place. Move all files (but not folders) to new folder.
I am... (4 Replies)
Hi, all:
I've got two folders, say, "folder1" and "folder2".
Under each, there are thousands of files.
It's quite obvious that there are some files missing in each. I just would like to find them. I believe this can be done by "diff" command.
However, if I change the above question a... (1 Reply)
Hi,
I want to write a script that deletes all folders and keep the last 10 recent folders.
I know the following:
ls -ltr will sort the folders from old to recent.
ls -ltr | awk '{print $9}' will list the folder names (with a blank line at the beginning)
I want to get the 10th folder from... (3 Replies)