Reputation: 1
I have multiple files like this
2015-01-20 18.09.16 (deleted 0c279a06bf811a0c2c42bfe0d0b8af55).jpg
2015-01-20 18.09.25 (deleted c1e0789f84cf958b170c3a44d9f99bcc).jpg
2015-01-20 18.09.30 (deleted 2927f32e0378ce3e5c1625a3efe65035).jpg
2015-02-11 16.03.14 (deleted 05d37b666219f537a92e10657ebf0205).jpg
How do I remove everything afer the dates? I want my files to look like this:
2015-02-14 16.26.15.jpg
Upvotes: 0
Views: 50
Reputation: 1933
Here is one way to do it
ls *.jpg | while read OLD
do
NEW=$(echo $OLD | sed 's/.*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]\).*\(\.jpg\)/\1\2/')
echo "NEW: $NEW"
done
If the names look ok, you can replace echo statement with "mv $OLD $NEW"
Upvotes: 0
Reputation: 1458
Here's one option:
for F in 2015*\(deleted*\).jpg ; do mv "$F" "${F/ (deleted*)/}" ; done
I would test beforehand using echo
:
for F in 2015*\(deleted*\).jpg ; do echo mv "$F" "${F/ (deleted*)/}" ; done
I'd test first in case you want the pattern to match more files (e.g., 2014 too) or fewer files (e.g., require a full date match). I used a simple pattern above (2015*\(deleted*\).jpg
) to hopefully make the base concept clear.
Upvotes: 1