Find last 2 days files.

Need to cpy those files which are created or modified in last 2 days.

 
bash$ ll -lrt
total 184
drwxr-xr-x   2 ons   dce             256 Oct 12 06:58 files
-rw-r--r--   1 ons   dce            4313 Oct 14 06:06 cab.ksh
-rw-r--r--   1 ons   dce               6 Oct 14 07:03 Code.txt
-rw-r--r--   1 ons   dce               8 Oct 14 07:23 Code1.txt
-rw-r--r--   1 ons   dce              28 Oct 14 07:28 diff.txt
-rw-r--r--   1 ons   dce             341 Oct 25 02:20 DS.1287677000.820.log
-rw-r--r--   1 ons   dce             348 Oct 25 02:21 DS.1287153156.329.log
-rw-r--r--   1 ons   dce            3106 Oct 25 02:23 DS.1287578250.7.log
-rw-r--r--   1 ons   dce            5925 Oct 25 02:24 DS.1287504078.200.log
-rw-r--r--   1 ons   dce             700 Oct 25 02:24 DS.1287423026.261.log
-rw-r--r--   1 ons   dce             367 Oct 25 02:25 DS.1287163063.587.log
-rw-r--r--   1 ons   dce             349 Oct 25 02:25 DS.1287083779.160.log
-rw-r--r--   1 ons   dce              95 Oct 26 08:49 files.TXT
-rw-r--r--   1 ons   dce              79 Oct 27 05:15 files1.TXT
-rw-r--r--   1 ons   dce              99 Oct 27 08:30 one.TXT
-rw-r--r--   1 ons   dce             156 Oct 27 08:38 two.TXT
-rw-r--r--   1 ons   dce            4981 Oct 29 03:35 t
-rw-r--r--   1 ons   dce            5394 Nov 02 02:15 new
drwxrwxrwx   2 ons   dce            4096 Nov 06 03:00 backup
 
 
bash$ find . -type f -atime +2 
 
find /ons/sam/ -atime -2 | find /ons/sam/ -name 'DS*' | whereis DS* | cp DS* /ons/sam/new

I want only last 2 days file, started with DS* but when i ran above command its gving all files name.

Plz advice here. Thanks

atime == last time file was read, usually you want mtime which is what ls -l shows.

find /ons/sam/ -name 'DS*' -mtime -2

Note: this gives you files less than 48 hours old. If you meant calendar days:
Assume today is Nov 20 2010, two days ago == Nov 18 midnight

touch -t 201011172359 dummy
find /ons/sam/ -name 'DS*' -newer dummy
1 Like

its done thanks.