Reputation: 891
Thanks to messing up my first attempts to do this, I now have a directory full of files that are now named like this:
valery-special-music-poetry.txt.mtxt.md.md.txt.mtxt.md.md.md
which I need to be named:
valery-special-music-poetry.md
how can I do this from the command line?
I am running: GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
Upvotes: 1
Views: 2832
Reputation: 911
By Shell itself:
for i in *; do mv "$i" "${i%%.*}.${i##*.}"; done
Unless your dir are single level, I suggest using find, if you have in Apple.
Upvotes: 3
Reputation: 2163
This may help you
#!/bin/bash
for filename in *
do
x=`echo $filename | sed 's/\..*\./\./g'`
mv $filename $x
done
Save this to a file called rename.sh
chmod +x rename.sh
./rename.sh
Upvotes: 2
Reputation: 67211
ls -1 *.txt.mtxt.md.md.txt.mtxt.md.md.md | nawk -F"." '{cmd="mv "$0" "$1".md";system(cmd)}'
Upvotes: 0