I am new to UNIX, and I am trying to write a shell script that would move all folders that are older than a day in log archive directory into another folder.

Below is the command I am using for doing so.

find /location/logarchive -mtime +1 -type d -exec mv "{}" /Destination/Archives \;

This command is moving the parent directory, i.e. logarchive into the destination instead of sub folders.

Could you please help me modify this command?


You need to also add -mindepth 1 to your command so as not to include the actual directory you specified initially.

find /location/logarchive -mindepth 1 -mtime +1 -type d -exec mv "{}" /Destination/Archives \;

You might want to also add -maxdepth 1 if you don't want to recurse into subfolders, which would make sense here, since they're already contained in any upper level folders.

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.