-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# mmv - move multiple files and/or directories at once | |
# | |
# Usage: | |
# mmv [-h] [-d DESTINATION] file1 [file2 file3 ...] | |
# | |
# Written by Aigars Sukurs <[email protected]> | |
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not to spoil or anythin..