Skip to content

Instantly share code, notes, and snippets.

@wwwins
Last active October 6, 2020 16:16
Show Gist options
  • Save wwwins/80221578d06c6d2082d49067c2e16332 to your computer and use it in GitHub Desktop.
Save wwwins/80221578d06c6d2082d49067c2e16332 to your computer and use it in GitHub Desktop.
Bash shell script tips
# copy a-*.ejs to d-*.ejs
$ for f in a-*.ejs; do cp $f d${f: 1}; done;
cp a-1.ejs d-1.ejs
cp a-2.ejs d-2.ejs
cp a-3.ejs d-3.ejs
cp a-4.ejs d-4.ejs
# copy loop_*.mp3 to loop_*.wav
$ for f in loop_*.mp3; do echo $f ${f:0:-4}.wav; done;
loop_1.mp3 loop_1.wav
loop_2.mp3 loop_2.wav
loop_3.mp3 loop_3.wav
loop_4.mp3 loop_4.wav
loop_5.mp3 loop_5.wav
# rename *.jpeg to *.jpg
$ for f in *.jpeg; do echo ${f%.jpeg}.jpg; done;
img-1.jpg
img-2.jpg
img-3.jpg
img-4.jpg
img-5.jpg
# rename img-*.jpeg to image-*.jpeg
$ for f in *.jpeg; do echo image${f#img}; done;
image-1.jpeg
image-2.jpeg
image-3.jpeg
image-4.jpeg
image-5.jpeg
# rename image-front-*.jpeg to image-Front-*.jpeg
$ for f in *.jpeg; do echo ${f/-f/-F}; done;
image-Front-1.jpeg
image-Front-2.jpeg
image-Front-3.jpeg
image-Front-4.jpeg
image-Front-5.jpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment