Directory contains 26,000 files. How to split into sub-dirs?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Directory contains 26,000 files. How to split into sub-dirs?
I have a directory that contains nearly 26,000 files that have been created over the last couple of years. What is a good way to move them into subdirs with some meaning, i.e. all files up to a certain date get moved into a subdir with a name of that date (or something along those lines)?
I could do it by hand, but I'm sure there's a better way.
If doing it by date is too difficult, I don't mine moving them into subdirs with say, 1500 files each - as long as the files remain in chronological order, in other words, all files in dir 'A' are older than all files in dir 'B' are older than all files in dir 'C' etc.etc.
Originally posted by acid_kewpie ok, i've not really tested squat, but something like this should suffice.
...
This should move all files into directories such as "apr04" or "oct03"
good idea! this is the way I did it:
Code:
#!/bin/bash
for i in *
do
filemonth=`stat --format=%y $i | cut -c 0-7`
mkdir -p $filemonth
mv $i $filemonth/$i
done
evidently, your stat and my stat return different info. This script creates directories that look like this:
2003-09
2003-10
2003-11
2003-12
2004-01
2004-02
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.