Moving files with specific dates

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Moving files with specific dates
# 1  
Old 06-20-2017
Moving files with specific dates

Hi,

These are the list of files in one directory in the server :

Code:
[root@L28tstream1 ~]# ls -lrt
total 10120
-rw-r--r-- 1 root root    4484 Jul  8  2011 install.log.syslog
-rw-r--r-- 1 root root   51890 Jul  8  2011 install.log
-rw------- 1 root root    3140 Jul  8  2011 anaconda-ks.cfg
drwxr-xr-x 2 root root    4096 Jun 26  2012 ESA_Inst_pkg
drwxr-xr-x 2 root root    4096 Jun 29  2012 Desktop
-rw-r--r-- 1 root root   89153 Jul  9  2012 POST.zip
drwx------ 2 root root    4096 Nov 25  2014 Mail
drwxr-xr-x 2 root root    4096 Jul  8  2015 test
drwxr-xr-x 2 root root    4096 Aug 17  2015 scripts
-rw-r--r-- 1 root root   19133 Mar 18  2016 snmpd.conf.18032016b4changes
drwxr-xr-x 3 root root    4096 Mar 21  2016 hp-agent
-rw-r--r-- 1 root root   19093 Mar 30  2016 snmpd.conf
-rw-r--r-- 1 root root 1282865 Apr 22  2016 hp-snmp-agents-9.50-2564.34.rhel5.x8                                                                                        6_64.rpm
-rw-r--r-- 1 root root  737366 Apr 22  2016 hp-health-9.50-1631.33.rhel5.x86_64.                                                                                        rpm
-rw-r--r-- 1 root root 1064960 Apr 22  2016 hpacucli-9.40-12.0.x86_64.rpm
-rw-r--r-- 1 root root 3644843 Apr 22  2016 hp-smh-templates-10.4.0-1455.24.noar                                                                                        ch.rpm
-rw-r--r-- 1 root root 3334099 May 17  2016 hpadu-9.40-12.0.x86_64.rpm
-rwxr--r-- 1 root root      39 Apr 19 14:04 script.sh
drwxr-xr-x 2 root root    4096 Apr 19 14:23 2017
-rwxr--r-- 1 root root     202 Apr 19 14:34 script1.sh
drwxr-xr-x 2 root root    4096 Apr 19 14:50 Apr2017_Blast_BC15
-rwxr--r-- 1 root root     164 Apr 19 14:52 script2.sh
-rwxr--r-- 1 root root     147 Apr 19 17:43 script3.sh
[root@L28tstream1 ~]# pwd

I want to move only specific files from this folder to another folder. Let's say I choose only files dated 'Apr 19 14:04' to 'Apr 19 17:43'. This is the command I run to execute this task :

Code:
[root@L28tstream1 ~]# find . -type f -newer "2017-04-19" ! -newer "2017-04-20" -exec cp {} /home/emoaigin/ \;
find: 2017-04-19: No such file or directory
[root@L28tstream1 ~]#

However as you can see, I get the error above. 'No such file or directory'. How do I choose files with specific dates to move to another directory?

This is important as I need to create a script that moves files from a set date in a month. So far I need to move files dated every 2nd, 8th and 16th onwards, (but the end date is not fixed, which is why I need a script that selects files from the dates mentioned onwards) and move it to another directory. If this were not the case, I know I can use 'mtime' to move the files.



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 06-20-2017 at 04:34 AM.. Reason: Added CODE tags.
# 2  
Old 06-20-2017
The -newer test needs a reference file. Some find versions (e.g. find (GNU findutils) 4.7.0-git) offer the -newerXY (where "-t reference is interpreted directly as a time" c.f. man find) test.
# 3  
Old 06-20-2017
You can use touch -mt YYYYMoDDHHMi.SS /tmp/filename to create files of the desired timestamp, like so:-
Code:
$ touch -mt 201704050607.23 /tmp/robin
$ ls -l /tmp/robin
-rw-rw-r-- 1 rbatte1 root_armed 0 Apr  5 06:07 /tmp/robin

The reference file you use does not have to be int he same directory of filesystem as the files you want to run the find against.


Does that help?
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

2. Shell Programming and Scripting

Moving files into dirs corresponding to dates

I am trying to find a way to move files into corresponding date files. i=0 while read line do array="$line" (( i++ )) done < <(ls) cd $(echo ${array}) echo ${array}} pwd #cd "$(array}" ] || mkdir 2015 cd "2015" ] || mkdir 02-February ] || mkdir 03-March ] || mkdir... (10 Replies)
Discussion started by: newbie2010
10 Replies

3. UNIX for Dummies Questions & Answers

Moving files with specific names

Hi, I have a list of names (in a text file) like this: SRR1234 SRR5678 SRR4321 SRR8876 I'd like to have a unix code to find all the files which have any of above strings in their name and move them to a specific directory. I have my files distributed in many subdirectories so it has to... (3 Replies)
Discussion started by: a_bahreini
3 Replies

4. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

5. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

6. Shell Programming and Scripting

Parsing log files, displaying logs between specific dates

Sorry, couldn't really think of a simple subject/title. So, I have a log file, and the dates are displayed like so: 2009-03-05 02:49:44 So the first and second field are the date/time. I can change them into a unix timestamp easily with: date -d "2009-03-05 02:49:44" +%s However,... (17 Replies)
Discussion started by: Rhije
17 Replies

7. UNIX for Dummies Questions & Answers

To find files with specific dates and cp another folder.

Hi all, We have an existing script: find /u03/oraprod/perpcomn/admin/out -type f -ctime +7 \ -exec cp {} "/u08/oraprod/backup/cout" \; Which is to find all files more than 7 days and copy to another folder. However I would like to only list files with Sep 29, and cp to another folder. ... (2 Replies)
Discussion started by: *Jess*
2 Replies

8. Shell Programming and Scripting

How to calculate specific hours between 2 dates

Hi there, I am trying to find out a way to calculate how many hours are between 2 dates but from a specific time range, actually working hours (Monday to Friday 09:00 - 18:00). What I mean is for example date1 = Monday 21 July 2008 22:00:00 so in python 2008-07-21 22:00:00 date2 = Wednesday... (5 Replies)
Discussion started by: sickboy
5 Replies

9. Shell Programming and Scripting

Moving specific files

Hello, I am trying to move specific files to a specific folder. I have a virus script that runs and quarantines the files by changing the ownership to -r--------. This has worked fine but I am wanting to actually move the infected files to a folder called quarantine. I have came up with a basic... (4 Replies)
Discussion started by: Stud33
4 Replies

10. Shell Programming and Scripting

reading files for specific dates

assume files are in a directory /data $ ls -ltr Just displaying Data and file name: 01/01/2004 file_3434_typea.dat 01/01/2004 file_3423_typea.dat 01/01/2004 file_3436_typea.dat 01/01/2004 file_3434_typeb.dat 01/01/2004 file_3423_typeb.dat 01/01/2004 file_3436_typeb.dat ... (3 Replies)
Discussion started by: siva_jm
3 Replies
Login or Register to Ask a Question