Skip to content

Instantly share code, notes, and snippets.

@130db
Last active December 16, 2015 16:59
Show Gist options
  • Save 130db/5467084 to your computer and use it in GitHub Desktop.
Save 130db/5467084 to your computer and use it in GitHub Desktop.
Move multiple files and/or directories at once to provided or predefined location. Mainly I use this script to clean up home or any other directory. This is why destination folder by default is .clean
#!/bin/sh
#
# mmv - move multiple files and/or directories at once
#
# Usage:
# mmv [-h] [-d DESTINATION] file1 [file2 file3 ...]
#
# Written by Aigars Sukurs <aigars@130db.lv>
#
# Default destination
destination=.clean
usage() {
echo
echo " Move multiple files and directories at once"
echo
echo " Usage:"
echo " $0 [-h] [-d DESTINATION] file1 [file2 file3 ...]"
echo
echo " -h - this message"
echo " -d - destination directory"
echo " Default: .clean"
echo
exit 1;
}
while getopts d:h option
do
case "${option}"
in
d)
destination=${OPTARG}
shift 2;;
h)
usage
shift;;
esac
done
[ $# -lt 1 ] && usage
if [ ! -d "$destination" ]; then
mkdir "$destination" || exit 1
fi
for F in "$@"
do
if [ -f "$F" -o -d "$F" ]; then
if [ "$F" != "$destination" ]; then
mv "$F" "$destination/."
else
echo "Cannot move '$F' to a subdirectory of itself"
exit 1
fi
fi
done
exit 0
@laacz
Copy link

laacz commented Apr 26, 2013

Not to spoil or anythin..

$ mv /path/to/file1 /path/to/file2 /another/path/to/file3 /path/to/destination/

@130db
Copy link
Author

130db commented Apr 26, 2013

Bicycle, bicycle :D

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