ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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?
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.
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:
while read src
do
dst=${src/Pictures/Resized}
echo mkdir -p $(dirname $dst)
echo mv $src $dst
done < <(find /home/rjo98/Pictures -name \*a.jpg)
then the original ones:
Code:
while read src
do
dst=${src/Pictures/Originals}
echo mkdir -p $(dirname $dst)
echo mv $src $dst
done < <(find /home/rjo98/Pictures -name \*.jpg)
The echo statements are for testing purposes. Once you've verified the resulting commands are what you're looking for, remove the echo and run again. Please, note that the find command in the first loop searches the *a.jpg files, the second one searches all the remaining jpg. Hope this helps.
Thanks. How do I get it to run all those lines at once, put them in a .sh file then run that?
Just copy/paste them on the command line, modify the path in the find command according to the actual path of the Pictures directory and press enter. Beware of not removing the echo statements before testing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.