I know how to find last modified files, but how do I use it with my already written script. In folder I have hundreds of files xyz_<yyyymm>, now I use $ find /home/directory/TEST/ -type f -mmin -60, but it crashes halfway.

  • 2
    What are you trying to do with your "already written script" and find? I don't see any reference to a script in your find command – Eric Renouf Nov 18 '16 at 15:58
  • my script is just some sed and mv lines, i put $ find on top of it, how to make connection with "already written script" :D thx for answer – Much to learn Nov 18 '16 at 16:01
  • you want to do something with each file? find ... | xargs script – stevieb Nov 18 '16 at 16:06
  • Does your script expect to operate on a file, and you want find to invoke your script for each appropriate file? – Eric Renouf Nov 18 '16 at 16:06
  • I have 10 files xyz1 modified today and 20 xyz2 modified 2 days ago. I've already written some lines that take xyz* file rename it and then .zip. it. All I need now is to take last modified files (10files from today) and execute my "already written script" – Much to learn Nov 18 '16 at 16:09

If you want to execute a script for each result of a find command, you could use xargs, but often I prefer to use -exec with find. So you could do it like:

find /home/directory/TEST/ -type f -mmin -60 -exec /path/to/your/script {} \;

and the name of the file that find matches will be put in the {} spot for each match


If what you're trying to do is use find to iterate over numerous files and then pass each file name to a script, you can use xargs, especially if the file list is very large and you find things crashing part way through.

Here, I iterate over the current working directory looking for all files, then pass each file name to a perl script which simply prints out the name:

find . -type f | xargs -0 ./script.pl

You can adjust your find command string to suit your needs.

  • I got this:sed -e 's/TIMESTAMP*\([0-9]*\)/\1/g' TIMESTAMP_old_*.csv> new.txt sed -i -e 1d new.txt find /home/TEST/ -type f -name "CERTIFICATE_*.csv" -exec mv {} CERTIFICATE_"$(cat new.txt)".csv \; how to make it work on last modified files, files called CERTIFICATE are hundreds, how to take the newer one. i got trouble with understanding xargs – Much to learn Nov 18 '16 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.