A legacy web application I’ve inherited control over seems to have hit the maximum number of subdirectories in a folder on my web server. Whenever an article is created in the system, it’s static content is placed in a subdirectory of the document root matching the pattern /uploads/story/{STORY_ID}/. But now the system is unable to create any new directories in the /uploads/story/ folder.
I’d like to address this in 2 steps, but I’m not sure how to run the necessary linux commands to achieve this. Would you be able to help?
-
As a temporary fix to buy me more time to implement a better directory structure, I’d like to archive the static content of all stories with a STORY_ID of less than 1000. These should be moved from
/uploads/story/to/uploads/story_archive/. -
I’ll change the upload path to be
/uploads/story/{THOUSANDS}/{STORY_ID}/in the code, but will need to be able to move all folders within/uploads/story/into this format. e.g./uploads/story/65312/would become/uploads/story/65/65312/. How can I do this?
Edit
Fixing (1) was as simple as running:
$ cd /path/to/uploads/
$ mkdir story_archive
$ for i in {1..999}; do mv story/$i story_archive/; done
Given that you are sure
/uploads/story/*will give you a number in the*part, you can do the following (Note: backup the whole thing just in case):