Bash
Jump to navigation
Jump to search
bash script snippets
file renaming
Rename all *.jpg files in a folder to 0001.jpg, 0002.jpg, etc.
#!/bin/bash
a=1
for i in *.jpg; do
new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
mv -i -- "$i" "$new"
let a=a+1
done
file viewing
List all files and show their contents with the filename as the header ==
$ for f in *; do \
if [ -f "$f" ]; then \
echo ":::::::::::::: $f ::::::::::::::"; \
cat "$f"; \
echo ""; \
fi;
done