My goal is to find the newest image in a directory and make a copy of it with a new name.
I've tried using the find command but copying doesn't seem to work
Here is what will return me the most recent image taken
lastimage=$(find *.jpg -type f | xargs ls -ltr | tail -n 1)
echo $lastimage
Then I've tried this to make a copy of it and call it lastimage.jpg
lastimage=`find *.jpg -type f | xargs ls -ltr | tail -n 1` && cp $lastimage /path/to/location/lastimage.jpg
I expect to see lastimage.jpg
in the same directory i called it from.
My actual result is
cp: invalid option -- 'w'