I have large image files in one folder (e.g 10000 pics ) and I want to check the last week image files (.jpg) so that I can easily move those last week images to the external hard disk instead of transferring all image files (.jpg) to hard disk. Please can anyone help me in this matter. Thank you
1 Answer
There's a command called find
which can help to identify the files, and even move them to another location.
To find .jpg files that are older than 7 days, and list the names of the files:
find /path/to/images -name "*.jpg" -mtime +6
The -mtime
part of the command looks for files based on the number afterwards in days, +6 means older than 7 days due to the way -mtime
rounds non full days down. More info on that is listed in this answer.
If you'd like more information on the files use find's -ls option like so:
find /path/to/images -name "*.jpg" -mtime +6 -ls
Once you're happy that these are the files you'd like to move, the following command will take care of that, just remember to change '/path/to/images' and '/path/to/external_drive' for the correct values. Using absolute paths is recommended.
find /path/to/images -name "*.jpg" -mtime +6 -execdir mv "{}" /path/to/external_drive "{}" \;
If there are sub-directories in your image directory that you don't want to search, you can restrict directory recursion with --max-depth 1
put this option after '*.jpg' separated by a space.
-
is that +6 or -6 for the last 6 days record means if i need last 6 days record ( last week ) than should i use " +" or "-" Aug 7, 2015 at 18:20
-
find . -type f -name "*.jpg" -mtime -7 -exec mv "{ }" newfolder \; what this command means? and thanks for your answer but little bit confusing Aug 7, 2015 at 18:21