Linux reads the file name line by line from the file and copies the matching file to the specified directory tutorial

To read file names line by line in Linux and copy matching files to a specified directory, you can follow the tutorial below:

  1. Create a text file, for example  filelist.txt, write the filenames that need to be matched and copied line by line into the file. Make sure each filename is on its own line.
  2. Create a target directory for storing the copied files:

    mkdir /path/to/destination

    will  /path/to/destinationbe replaced with the actual target directory path.

  3. Use a loop structure to read  filelist.txtthe file line by line and perform the copy operation:

    while IFS= read -r filename; do
        cp "$filename" /path/to/destination
    done < filelist.txt

    will  /path/to/destinationbe replaced with the actual target directory path.

  4. After executing the above command, the system will read  filelist.txtthe file names in the file line by line, and copy the matching files to the specified directory.

filelist.txtMake sure to double check that the filenames in the file are correct before performing a copy operation  , and back up important files to prevent accidental data loss.

Hope the above tutorial is helpful for you to read the file name line by line and copy the file to the specified directory in the Linux system. If you have other questions, please provide more details or refer to the relevant documentation for further support.

Guess you like

Origin blog.csdn.net/tiansyun/article/details/132287762