Here is a bash script that I hacked together from snippets I found on the net. This rename and move the files from one location to another. The new name will be a combination of the create time and the original file name.
#!/bin/bash ## Variables ## orig_location="/home/user/Desktop" orig_name="*.png" new_location="/media/nas01/private/documents/records/screen_grabs" ## Script ## # file all files in original location with original name and loop thru following... find ${orig_location} -iname "${orig_name}" | while read FILE; do # Use 'stat' to extract the modification time mtime=($(stat -c "%y" "${FILE}")) # get the name (without path) and convert to lower NFILE=($(echo $(basename ${FILE}) | tr '[:upper:]' '[:lower:]')) # move the file to new location and prepend create time to filename mv -f "${FILE}" "${new_location}/${mtime[0]//-/}_${NFILE}" done
No comments:
Post a Comment