You don't need to worry about setting the newermt option for find as all find is providing is a single execution per file found and the script makes all the decisions. #We then take the first column, split by a white space with awkĭate=`stat "$1" -format %y | awk ' \ #-format %y returns the modification date in the format: #Get the month and year of modification time #destDir should be set to where ever you want the files to go #We want to exit if there is no argument submitted I believe it's more efficient because it was perform the moves in one pass of find so multiple find commands and passes over the directory are unneeded. It can easily be expanded to a 2 digit day by uncommenting a couple lines and commenting out their counterparts. My shell script moves a file to the destination directory, with a 4 digit year and a 2 digit month. I tried doing one screen per year and running multiple finds but this resulted in a lot of errors from each find and files would go missing when one of the finds moved it. This produces a lot of needless passed over each file. The find command is very powerful and I started with the methods that are listed but I had so many years of data throughout that directory that I had to pass over all the files repeatedly. Additionally some *nix systems will barf a too many arguments error with running ls. I wrote this shell script to go through a directory with so many files in it the filesystem was gagging on the metadata trying to perform an ls. The answers are reasonable but there were some limitations with a purely find command. This answer is for answering the question "need to move files to different folder based on the creation date " Please note that the question marked as duplicate, and therefore is restricted from answering it directly, is why I'm posting into here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |