separate out files based on name
I have a folder named Pictures that contains a bunch of .jpg files. My problem is that they all have randomly numbered names, then there is a duplicate of the file that is random numbers then the letter a right before the .jpg.
for example, there would be 123.jpg and 123a.jpg, where 123a.jpg is just a resized version of 123. What i'd like to do but have NO clue how to, is to have a script or something go through my Pictures folder, then copy the ones that end in a.jpg to a folder called Resized, and ones that dont have that to a folder called Originals. That way my Pictures folder will be in tact, and i'll have copies of them all separated out. I have to do this all through the CLI on a machine, maybe I dont even need a script and can just do it with a slick command? |
Are they all in the Pictures main directory or are they placed in sub-directories?
|
sub-directories, and lots of them
|
Hence you need a command to search recursively inside the Pictures folder. You can try find, using the -regex option to match file names with numbers and w/ or w/o the trailing a. The -exec action might serve to move them. On the other hand, if you want to preserve the original directory structure inside Resized and Originals, you may want to write a more elaborate script.
|
Code:
mv *a.jpg /destination |
Quote:
Code:
find Pictures/ -name '*a.jpg' -exec cp -vi -- '{}' Resized/ ';' Code:
cd Pictures/ |
cool, thanks guys. I'll try out Nominal's suggestions, I never would have been able to come up with that myself haha.
|
I tried the folder structure one, and it says "missing argument to '-exec' "
|
At this point keep it simple and do a loop to achieve your task step-by-step and to have a better control on what happens. For example, suppose you have the following directories:
Code:
/home/rjo98/Originals Code:
while read src Code:
while read src |
Thanks. How do I get it to run all those lines at once, put them in a .sh file then run that?
|
also, i was hoping to preserve the Pictures folder by just doing copies, in case something screwed up, but i guess that's why we echo first...
|
Quote:
Edit: the thread lived, and had to put in the quote to show what I was referring to. |
Quote:
|
Quote:
|
getting somewhere with ramurd's suggestion...
now i get mkdir: invalid option -- i |
All times are GMT -5. The time now is 07:24 AM. |