Skip to content

Instantly share code, notes, and snippets.

@photonxp
Last active October 3, 2018 07:21
Show Gist options
  • Save photonxp/a8bed85e4d0b4405b80dda49393408a8 to your computer and use it in GitHub Desktop.
Save photonxp/a8bed85e4d0b4405b80dda49393408a8 to your computer and use it in GitHub Desktop.
move files to destination directory in command
#!/bin/bash
# Usage:
# move files to dir_destination
# ./mv_files2dir.bash /path/to/file dir_destination
# ./mv_files2dir.bash dir_a ./{b,c} dir_destination
# test_mv_files2dir.bash:
# #!/bin/bash
#
# # Test the usage of mv_files2dir.bash
#
# mkdir -p test/{dir_a,dir_destination}
# touch {b,c}
#
# ./mv_files2dir.bash test/dir_a ./{b,c} dir_destination
arr_arglist=($@)
idx_dir=$((${#arr_arglist[@]} - 1))
dir_path=${arr_arglist[$idx_dir]}
for (( i=0;$i<$idx_dir;i++ ))
do
echo $i
fpath="${arr_arglist[$i]}"
echo "mv $fpath $dir_path"
mv $fpath $dir_path
done
#!/bin/bash
# Test the usage of mv_files2dir.bash
mkdir -p test/{dir_a,dir_destination}
touch {b,c}
./mv_files2dir.bash test/dir_a ./{b,c} dir_destination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment