This script is useful if you’d like to iterate through find results or say files in a directory and pick specific files and do operations on them. Specific to my case – I had to search for files with current timestamp in the filename and use those files for some operations. Here’s what I did in a bash script
TIMESTAMP=`date +%F` echo $TIMESTAMP cd /home/varun.verma/scripts/shell/getFiles #find . -name "*.tar.gz" -type f -exec basename {} \; #Used this command to test the results. It finds files with a format and displays only the name of files, not the path (since I know where I am searching) for i in `find . -name "*$TIMESTAMP*.tar.gz" -type f -exec basename {} \;` do file=`echo -n $i` echo $file #Or do some operation here done
Advertisements