Last active
April 10, 2018 06:33
-
-
Save xtetsuji/822d194052d0ccffe86b6c46cc3d9984 to your computer and use it in GitHub Desktop.
move-to DIR FILE...: yet another mv command which gets destination and sources as its reverse order.
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/bash | |
# xtetsuji 2018/04/10 | |
# Usage: | |
# move-to DIR FILE1 FILE2 ... | |
# | |
# mv FILE1 FILE2 ... DIR ; 移動元ファイル群と移動先の指定が逆なもの | |
# | |
# これは xargs で役立つ | |
# e.g.: | |
# 4並列、一度の移動プロセスで最大100ファイルを目的のディレクトリへ移動させる場合 | |
# find . -mtime +365 -type f | xargs -P 4 -n 100 move-to backup_dir/ | |
set -eu | |
declare opt dir | |
readonly MV_COMMAND="mv -v" | |
#readonly MV_COMMAND="echo mv" | |
# ハイフンから始まる引数があれば、全部オプションとして引き上げる | |
# TODO: 引き上げたものを使っていない | |
while [ "x${1:0:1}" = "x-" ] ; do | |
opt="$opt $1" | |
shift | |
done | |
dir="$1" | |
shift | |
if [ ! -d "$dir" ] ; then | |
echo "target dir \"$dir\" is not found" | |
exit 1 | |
fi | |
$MV_COMMAND "$@" $dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment