Skip to content

Instantly share code, notes, and snippets.

@cold-logic
Created November 7, 2022 23:29
Show Gist options
  • Save cold-logic/c8fc8baec2f7c0826e14d68ee81dbfef to your computer and use it in GitHub Desktop.
Save cold-logic/c8fc8baec2f7c0826e14d68ee81dbfef to your computer and use it in GitHub Desktop.
Move a predefined list of files from one directory into another
#!/bin/bash
# Move files from one directory to another
# Usage: move.sh <filelist.txt> <source_dir> <destination_dir>
# Generate a filelist.txt using `ls > filelist.txt`
# First argument is the path to the filelist.txt that contains a newline separated (\n) list of filenames to move
txtListOfFilenames=$1
# Second argument is the path to the source directory where the files are currently located
srcDir=$2
# Third argument is the path to the destination directory where you want the files to be moved to
destDir=$3
# Read each filename from the text file
while read line; do
# Move that file to destination directory
mv "$srcDir/$line" "$destDir/"
done < $txtListOfFilenames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment