This question already has an answer here:

I have set of files created from Monday to Friday..

a -- > 08/20
a1---> 08/21
a2---> 08/21
a3---> 08/21
a4---> 08/22
a5 --> 08/23

I need to move only 08/21 file to diffrenet folder.

How is this possible ?

marked as duplicate by Gilles, slm, jasonwryan, Mat, Anthon Aug 29 '13 at 4:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Let's assume that modification times of the files are kept (files are not modified after they were created). Then, you can play with find command and -mtime option which searches for files whose data was last modified X days ago. So to find all files created e.g. 48 hours ago in the current working directory use

find ./ -type f -mtime 2

to move them to other directory

find ./ -type f -mtime 2 -exec mv {} DEST_DIR \;

Additionally, you can try to estimate the number of days from the current date and the date from which you requested the files (in this example 22)

DAY_CUR="`date +%d`"

find ./ -type f -mtime $DAY_DIF -exec mv {} DEST_DIR \;

The code is not perfect as it doesn't handle situations where the two days are from two different months but it illustrates how you can proceed.


So you want to move files based on their attributes. This means you have to identify or "find" the files and then move the result to a different folder.

The find utility will do an excellent job :-)

find called without any arguments will just list the complete folder content. You can then specifiy various filter criteria. For a complete list see man find (http://unixhelp.ed.ac.uk/CGI/man-cgi?find).

Here are some examples:

   -mmin n
      File's data was last modified n minutes ago.

   -mtime n
      File's  data was last modified n*24 hours ago.  See the comments
      for -atime to understand how rounding affects the interpretation
      of file modification times.

   -newer file
      File was modified more recently than file.  If file  is  a  sym-
      bolic  link and the -H option or the -L option is in effect, the
      modification time of the file it points to is always used.

You can then use -exec to call mv and use {} as a placeholder for the current file.

Example: find /some/path/ -mtime +4 -exec mv {} /some/other/path/

Pro-Tip: Call find without -exec to see if you get the right files :-)


You can use the find command to determine the files created on a day and use a filename pattern to further constrict the search. Use the -exec in find to mv the files.

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