How to Copy or Move Files Based on Date Modified on Linux

Q. How to copy or Move the files and folder based on date modified on linux ?

A. Follow this steps :

1. Check the files modified date :

# ls -lrt

Output :

drwxr-xr-x  2       507 root           4096 Mar  3 21:00 ioncube
-rw-r--r--  1 root      root        5641209 Mar  3 21:04 ioncube_loaders_lin_x86-64.tar.gz
-rw-r--r--  1 root      root         635678 Mar  8 11:28 facilemanager-complete-1.3.1.tar.gz
-rw-r--r--  1 root      root              0 May 12 00:08 file1
-rw-r--r--  1 root      root              0 May 12 00:08 file2
-rw-r--r--  1 root      root              0 May 12 00:08 file3
-rw-r--r--  1 root      root              0 May 12 00:08 file4
-rw-r--r--  1 root      root              0 May 12 00:08 file5

2. Create May directory under tmp, where the destination of the listed files :

# mkdir -p /tmp/May

3. Run the following command to display the files for date “May 12” and Move it to /tmp/May folder :

# for i in `ls -lrt | grep "May 12" | awk '{print $9}' `; do mv $i* /tmp/May; done

or

READ  How to Adjust the Zimbra Maximum Message and Upload Size via CLI

4. Run the following command to display the files for date “May 12” and copy it to /tmp/May folder :

# for i in `ls -lrt | grep "May 12" | awk '{print $9}' `; do cp -p $i* /tmp/May; done

One Reply to “How to Copy or Move Files Based on Date Modified on Linux”

  1. How i copy based on month and year to destination folder, i have 1 folder in which .tar files present in much more quantity(like:- 1000000 files), i want to copy the files like :- 2014 and 2015 year modified files, please help

Leave a Reply

Your email address will not be published. Required fields are marked *