You should use stat command to get the file date. I don't know if you want to get the creation date (birth) or the modification date of the file. I will provide an example using both dates.
Using birth date
#!/bin/sh for f in *.png do cdate=$(stat -c '%w' "$f" | cut -d ' ' -f1) echo mv -n "$f" "${cdate}_$f" done Using modification date
#!/bin/sh for f in *.png do mdate=$(stat -c '%y' "$f" | cut -d ' ' -f1) echo mv -n "$f" "${mdate}_$f" done With stat -c '%w' somefile you get the creation/birth date and with stat -c '%y' somefile you get the modification date.
The code above will return the date in YYYYMMDD format, if you want to get only in YYMMDD format you can apply parameter expansion (I'm not sure if this one is supported by POSIX or sh). Here you are another example (using bash):
Using birth date
#!/bin/bash for f in *.png do cdate=$(stat --printf='%.10w\n' "$f") echo mv -n "$f" "${cdate#??}_$f" done Using modification date
#!/bin/bash for f in *.png do mdate=$(stat --printf='%.10y\n' "$f") echo mv -n "$f" "${mdate#??}_$f" done With stat --printf='%.10w\n' or stat --printf='%.10y\n' I'm getting the first ten characters of the string that will represent the date in YYYYMMDD format. With ${cdate#??} or ${mdate#??} I'm removing the first two digits of the date so I will get this one in YYMMDD format.