i have to move some files from a directory to another one, but this is a bit tricky.
here is my folder structure
/var/www/media_test1/media001/001_pm_001.jpg
th001_pm_001.jpg
/var/www/media_test1/media002/002_pm_001.jpg
th002_pm_001.jpg
/var/www/media_test1/media003/003_pm_001.jpg
th003_pm_001.jpg
/var/www/media_test1/media004/004_pm_001.jpg
th004_pm_001.jpg
i basically want to move the pictures from each folder that do not have th into another directory like this:
/var/www/media_test2/media001/001_pm_001.jpg
/var/www/media_test2/media002/002_pm_001.jpg
/var/www/media_test2/media003/003_pm_001.jpg
/var/www/media_test2/media004/004_pm_001.jpg
what i am thinking is to create a list of the images i want to move by using s ls command to list all pictures + their path that don’t have th -> export that to a file -> build a cp command like:
cp /var/www/media_test1/media001/001_pm_001.jpg /var/www/media_test2/media001/001_pm_001.jpg
cp /var/www/media_test1/media002/002_pm_001.jpg /var/www/media_test2/media001/002_pm_002.jpg
...
then execute the command.
the problem is that i don’t know how to write these commands.
Is there a better way of doing this? any ideas on what commands i can use?
thanks
You can use the find command to do that. Make sure the destination directory exists and then run:
That will find all files that don’t begin with “th” and copy them to /var/www/media_test2/media001/.