To read a file name from a file in bash, check all files in the current directory, and return a prompt if none exists: check_file.sh

#! /bin/bash # get the current path CRTDIR=$(PWD) I =0 # get the file name from the TXT file with the file name saved For line in $(cat filelist.txt) do file_list[$I]=${line%%[[: cnTRL :]]} ((I ++)  FILE in "${file_list[@]}" do file_count=$(find $CRTDIR -name $FILE | wc -l) if [[ $file_count -eq 0 ]] then echo "Warning: $FILE not found in $CRTDIR!" fi done

Use:

  • Place the check_file.sh and filelist.txt files in the directory you want to check
  • On Windows, you can use Git Bash. Go to this directory first
  • Type./check_file.sh to run the script

Example:

# file.txt
1.pdf
2.cad
3.txt
4.exe
// ├─ sigma, sigma, sigma, sigma, sigma, sigma, sigma
$ ./check_file.sh
Warning: 1.pdf not found in /g/BashTest!
Warning: 2.cad not found in /g/BashTest!
Warning: 4.exe not found in /g/BashTest!

People can often qing jing, heaven and earth know all return