Skip to content

Instantly share code, notes, and snippets.

@sathishvj
Created May 19, 2015 14:36
Show Gist options
  • Save sathishvj/7586b3d51d39ab5b7201 to your computer and use it in GitHub Desktop.
Save sathishvj/7586b3d51d39ab5b7201 to your computer and use it in GitHub Desktop.
Rename file or dir by appending current timestamp
# move a file/folder to its name suffixed by the current timestamp
function mvdate() {
if [ ! -f "$1" -a ! -d "$1" ]
then
echo "Error! Given file/folder $1 does not exist! Exiting"
return 1
fi
mv "$1" "$1_$(date +%Y%m%d%H%M%S)"
OUT=$?
if [ $OUT -ne 0 ]; then
echo "Error! renaming file."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment