#!/bin/bash
# Check if the correct number of arguments is provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <file_list> <destination_directory>"
exit 1
fi
file_list="$1"
destination_directory="$2"
# Check if the file list exists
if [ ! -f "$file_list" ]; then
echo "File list not found: $file_list"
exit 1
fi
# Check if the destination directory exists
if [ ! -d "$destination_directory" ]; then
echo "Destination directory not found: $destination_directory"
exit 1
fi
# Read each filename from the file list and move it to the destination directory
while IFS= read -r filename; do
if [ -f "$filename" ]; then
echo "Moving $filename to $destination_directory"
mv "$filename" "$destination_directory"
else
echo "File not found: $filename"
fi
done < "$file_list"
echo "File move completed."
Save the script in a file, for example, move_files.sh. Make the script executable using the command chmod +x move_files.sh. Then you can run the script by providing the file list and the destination directory as arguments:
./move_files.sh <file_list> <destination_directory>
Replace <file_list> with the path to your file containing the list of filenames, and <destination_directory> with the path to the directory where you want to move the files.
Note: The script assumes that the filenames listed in the file are either absolute paths or relative paths to the current directory. If the file names are relative to a different directory, you may need to modify the script accordingly.