Skip to content

Instantly share code, notes, and snippets.

@ShawnMcCool
Last active July 19, 2017 13:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShawnMcCool/2eb4c3c786579f168849cf54cf30e01c to your computer and use it in GitHub Desktop.
Save ShawnMcCool/2eb4c3c786579f168849cf54cf30e01c to your computer and use it in GitHub Desktop.
Moves the most recently modified file from the source directory to the destination directory.
alias mvltr="~/scripts/mvltr.sh"
alias ltr="ls -ltr"
#!/usr/bin/zsh
if [ -z "$1" ]
then
echo "You must provide a directory from which to grab the newest file."
echo "\tmvltr ~/source ./destination"
exit 1
fi
if [ -z "$2" ]
then
echo "You must provide a target to move the file"
echo "\tmvltr ~/source ./destination"
exit 1
fi
lastFile=`ls -d -t $1/** | head -n1`
mv "$lastFile" "$2"
@ShawnMcCool
Copy link
Author

example usage:

$ ltr ~/Downloads
$ mvltr ~/Downloads ~/Documents/Tax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment