[Mac OS X] How can we divide a number of files that belong to the same folder into several folders

The tutorial is aimed at users of Mac OS X, who need to share a large number of files in a folder, in multiple folders.

In our case, the problem looks like this:

We have a folder "PSD" which contains 2105 files, and these files we 2105 to create folders each containing no more than 300 file.

List Folder Files Mac OS X

To achieve this, the most simple and convenient we command line from Terminal.

1. open Terminal and navigate to the folder in which fisirele that we want to share. In our case the order will be:

cd /Volumes/Stealth/Graphics/PSD

2. View the number of existing files and folders in current location:

ls -l | wc -l

Before proceeding to step 3 is better to make sure that the folder files are not blocked (locked files). If any, during the execution will receive error message "Operation not permitted". With the help of the command "-R chflags nouchg *"We will unlock all files in the current location (Unlock multiple files in Mac OS X).

3. Command line divide the total by which the files in the current folder, the folder that contains a defined number of files:

i=0; for f in *; do d=psd_$(printf %03d $((i/300+1))); mkdir -p $d; mv "$f" $d; let i++; done

Where "psd_" is the prefix of the folders to be created, and "300" is the maximum number of files per folder. These parameters can be modified according to your preferences.

This is how this tutorial looks like Terminal:

Screen Shot at 2015 01-16-21.53.44
Stealth Settings - Split a folder with thousands of files into multiple sub-folders.

This tutorial has been tested and realized MacBook Pro cu OS X Yosemite.

Founder and editor Stealth Settings, from 2006 to the present. Experience on operating systems Linux (in particular CentOS), Mac OS X, Windows XP> Windows 10 si WordPress (CMS).

How to » macOS » [Mac OS X] How can we divide a number of files that belong to the same folder into several folders
Leave a Comment