Skip to content

Instantly share code, notes, and snippets.

@verginer
Last active October 31, 2017 17:09
Show Gist options
  • Save verginer/3b50f26e75a1031f72ae7c96d2054045 to your computer and use it in GitHub Desktop.
Save verginer/3b50f26e75a1031f72ae7c96d2054045 to your computer and use it in GitHub Desktop.
Move n files from dir1 to dir2
#!/usr/bin/env bash
# move `n` files from source dir to destination
#
# Example
#
#$./move_n_files.sh 30 './*.csv' ./dest
n_files=$1 # first argument
source_dir=$2 # second argument can be a glob i.e. ls *.csv
dest_dir=$3 # third argument
ls "${source_dir}" | head -n "${n_files}" | xargs -i mv "{}" "${dest_dir}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment