bash - How do I correct this UNIX command for copying files into a directory? -
i have following command not work
while read line; ls $line | head -10 | cp xargs dest_folder; done < my_file.txt
the objective have file named my_file.txt contains name of folder on every line. want copy 10 files each of directories mentioned on every line of file dest_folder.
how can correct above command?
you cand achive following bash script:
#!/bin/bash # first argument filename contains ton each line name of folder # teh second argument destination folder while ifs='' read -r line || [[ -n "$line" ]]; filestocopy=($(ls $line |head -n 10)) in "${filestocopy[@]}" : cp $line/$i $2 done done < "$1"
usage:
chmod +x your_bash_script ./your_bash_script my_file.txt dest_folder
note:
the folder names inside file should absolute paths.
Comments
Post a Comment