Rename multiple files

Remove "-2" from names of multiple files

$ ls
R0012455-2.jpg  R0012462-2.jpg  R0012466-2.jpg
$ for i in *.jpg; do mv -i "$i" "${i/\-2/}"; done
$ ls
R0012455.jpg    R0012462.jpg    R0012466.jpg

References

echo

Enable backslash-escaped characters

$ echo "line1\nline2"
line1\nline2
$ echo -e "line1 \n line2"
line1 
line2

read

pause until user press a key

read -p "Press any key to continue ..."

Interate over a list of values

bash$ for i in {6,8,9,11}; do wget "http://www.weilishi.org/img/0401/$i.jpg"; done

Remarks:

  • Notice that {6, 8, 9, 11} which contains white spaces does not work.
blog comments powered by Disqus