Skip to content

Instantly share code, notes, and snippets.

@madhurjain
Last active December 11, 2015 15:18
Show Gist options
  • Save madhurjain/4620000 to your computer and use it in GitHub Desktop.
Save madhurjain/4620000 to your computer and use it in GitHub Desktop.
Shell script to rename/move a file after it is downloaded
#!/bin/bash
echo "1. Rename file1.zip -> file2.zip"
echo "2. Move file1.tar.gz -> file2.tar.gz"
echo "3. Exit"
echo "Please enter your choice: "
read option
#The base folder path
basePath="/home/mad"
case $option in
1)
originalFile="$basePath/downloads/file1.zip"
renameFile="$basePath/downloads/file2.zip"
;;
2)
originalFile="$basePath/downloads/file1.tar.gz"
renameFile="$basePath/archives/file2.tar.gz"
;;
3)
exit 0
;;
esac
if ! [ -f "$originalFile" ]
then
echo "$originalFile does not exist"
exit 1
else
echo "$originalFile found.."
fi
while :
do
if ! [[ `lsof $originalFile` ]]
then
echo "$originalFile -> $renameFile"
mv $originalFile $renameFile
break
else
echo "file in use. waiting.."
fi
sleep 5
done
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment