Sponsored Content
Top Forums Shell Programming and Scripting Split a folder with huge number of files in n folders Post 302906653 by Scrutinizer on Sunday 22nd of June 2014 03:51:46 PM
Old 06-22-2014
Try something like:
Code:
cd XYZ || { echo "directory does not exist" > &2; exit 1 ;}
n=0
for i in *
do
  if [ $((n+=1)) -gt 10 ]; then
    n=1
  fi
  todir=../XYZ$n
  [ -d "$todir" ] || mkdir "$todir" 
  mv "$i" "$todir" 
done

Try it out on a test directory first and/or prepend echo to the mv command to see if it works as desired...

Last edited by Scrutinizer; 06-22-2014 at 05:00 PM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete all folders/files and keep only the last 10 in a folder

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)
Discussion started by: melanie_pfefer
3 Replies

2. Shell Programming and Scripting

Split a huge data into few different files?!

Input file data contents: >seq_1 MSNQSPPQSQRPGHSHSHSHSHAGLASSTSSHSNPSANASYNLNGPRTGGDQRYRASVDA >seq_2 AGAAGRGWGRDVTAAASPNPRNGGGRPASDLLSVGNAGGQASFASPETIDRWFEDLQHYE >seq_3 ATLEEMAAASLDANFKEELSAIEQWFRVLSEAERTAALYSLLQSSTQVQMRFFVTVLQQM ARADPITALLSPANPGQASMEAQMDAKLAAMGLKSPASPAVRQYARQSLSGDTYLSPHSA... (7 Replies)
Discussion started by: patrick87
7 Replies

3. Shell Programming and Scripting

Compare 2 folders to find several missing files among huge amounts of files.

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)
Discussion started by: jiapei100
1 Replies

4. Shell Programming and Scripting

Move all files but not folders to a new folder

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)
Discussion started by: Hopper_no1
4 Replies

5. Shell Programming and Scripting

How to delete a huge number of files at a time

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)
Discussion started by: lisp21
9 Replies

6. Shell Programming and Scripting

Help- counting delimiter in a huge file and split data into 2 files

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)
Discussion started by: lv99
7 Replies

7. Shell Programming and Scripting

moving files from one folder to many folders

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)
Discussion started by: realspirituals
2 Replies

8. Shell Programming and Scripting

Symlink all files from one folder into all found folders

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)
Discussion started by: Spadez
1 Replies

9. UNIX for Dummies Questions & Answers

Split a huge 7 GB File Based on Pattern into 4 files

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)
Discussion started by: KishM
6 Replies

10. Shell Programming and Scripting

Moving files and folders to another folder

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)
Discussion started by: ###
1 Replies
FS_COPYACL(1)						       AFS Command Reference						     FS_COPYACL(1)

NAME
fs_copyacl - Copies an ACL from a directory to one or more other directories SYNOPSIS
fs copyacl -fromdir <source directory (or DFS file)> -todir <destination directory (or DFS file)>+ [-clear] [-id] [-if] [-help] fs co -f <source directory (or DFS file)> -t <destination directory (or DFS file)>+ [-c] [-id] [-if] [-h] DESCRIPTION
The fs copyacl command copies the access control list (ACL) from a source directory to each specified destination directory. The source directory's ACL is unchanged, and changes to the destination directory's ACL obey the following rules: o If an entry on the source ACL does not already exist on the destination ACL, it is added. o If an entry exists on both the source and destination ACLs, the permissions from the source ACL entry replace the current permissions on the destination ACL entry. o If an entry on the destination ACL has no corresponding entry on the source ACL, it is removed if the -clear flag is included and is unchanged otherwise. In other words, if the -clear flag is provided, the source ACL completely replaces the destination ACL. When using this command to copy ACLs between objects in DFS filespace accessed via the AFS/DFS Migration Toolkit Protocol Translator, it is possible to specify files, as well as directories, with the -fromdir and -todir arguments. CAUTIONS
Do not copy ACLs between AFS and DFS files or directories. The ACL formats are incompatible. OPTIONS
-fromdir <source directory> Specifies the source directory from which to copy the ACL. (Specifying an AFS file copies its directory's ACL, but specifying a DFS file copies its own ACL.) A partial pathname is interpreted relative to the current working directory. -todir <destination directory> Specifies each directory for which to alter the ACL to match the source ACL. (Specifying an AFS file halts the command with an error, but specifying a DFS file alters the file's ACL). A partial pathname is interpreted relative to the current working directory. Specify the read/write path to each directory (or DFS file), to avoid the failure that results from attempting to change a read-only volume. By convention, the read/write path is indicated by placing a period before the cell name at the pathname's second level (for example, "/afs/.abc.com"). For further discussion of the concept of read/write and read-only paths through the filespace, see the fs mkmount reference page. -clear Replaces the ACL of each destination directory with the source ACL. -id Modifies the Initial Container ACL of each DFS directory named by the -todir argument, rather than the regular Object ACL. This argument is supported only when both the source and each destination directory reside in DFS and are accessed via the AFS/DFS Migration Toolkit Protocol Translator. -if Modifies the Initial Object ACL of each DFS directory named by the -todir argument, rather than the regular Object ACL. This argument is supported only when both the source and each destination directory reside in DFS and are accessed via the AFS/DFS Migration Toolkit Protocol Translator. -help Prints the online help for this command. All other valid options are ignored. EXAMPLES
The following example command copies the current working directory's ACL to its subdirectory called reports. Note that the source directory's ACL is unaffected. Entries on the reports directory's that are not on the source ACL of the current directory remain unaffected as well, because the -clear flag is not used. % fs listacl . reports Access list for . is Normal rights: pat rlidwka smith rlidwk Access list for reports is Normal rights: pat rl pat:friends rl Negative rights jones rlidwka % fs copyacl -fromdir . -todir reports % fs listacl . reports Access list for . is Normal rights: pat rlidwka smith rlidwk Access list for reports is Normal rights: pat rlidwka pat:friends rl smith rlidwk Negative rights jones rlidwka PRIVILEGE REQUIRED
To copy an ACL between AFS objects, the issuer must have the "l" (lookup) permission on the source directory's ACL and the "a" (administer) permission on each destination directory's ACL. If the -fromdir argument names a file rather than a directory, the issuer must have both the "l" and "r" (read) permissions on the ACL of the file's directory. To copy an ACL between DFS objects, the issuer must have the r permission on the source directory or file's ACL and the "c" (control) permission on each destination directory or file's ACL. SEE ALSO
fs_listacl(1), fs_mkmount(1), fs_setacl(1) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 FS_COPYACL(1)
All times are GMT -4. The time now is 03:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy