-3

I am new to shell scripting and I have requirement.

When I run the shell script it should move last 7 days files from current folder to new folder. My files look like tools_20150727.log,tools_20150726.log,.... like this

Please help me out in this regard.

Kishore
  • 1
  • 1
  • 2
  • 2
    What have you tried so far? This website is for helping if you have problems not for writing code for you. – bish Jul 29 '15 at 05:20

1 Answers1

1

Below will work

find . -type f -mtime -7 -exec mv {} newfolder \;

if you want only .log files to move then use below

find . -type f -name *.log -mtime -7 -exec mv {} newfolder \;

-type f == meaning the pick all files only
-name *.log == having name like .log
-mtime -7== modified within 7 days
-exec == execute also on output from find meaning files found in find command
mv {} newfolder == move all the file found to newfolder
Shravan Yadav
  • 1,297
  • 1
  • 14
  • 26