-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmv_random_files_subset.sh
36 lines (25 loc) · 1.04 KB
/
mv_random_files_subset.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
### Disclaimer: this does not work with folders that contain more than ~4000 files.
### Use ./mv_from_large_folder.sh instead.
# Source and destination directories
source_dir="source_img_dir"
destination_dir="dest_img_dir"
# Number of images to move
num_images_to_move=1000
# Ensure the destination directory exists
mkdir -p "$destination_dir"
# Create an array of all image files in the source directory
image_files=("$source_dir"/*.jpg "$source_dir"/*.png)
# Check if there are enough images to move
if [ ${#image_files[@]} -lt $num_images_to_move ]; then
echo "Error: Not enough images in the source directory."
exit 1
fi
echo "Number of images in source directory: ${#image_files[@]}"
# Shuffle the array randomly
image_files_shuffled=( $(shuf -e "${image_files[@]}"))
# Move the selected images to the destination directory
for ((i = 0; i < $num_images_to_move; i++)); do
mv "${image_files_shuffled[$i]}" "$destination_dir"
done
echo "Random subset of $num_images_to_move images moved from $source_dir to $destination_dir"